Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voxel bidir #316

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions experiments/voxel/args-voxel.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
{
"cmd": "rofi-voxel {init} {goal} --init-format {init_fmt} --goal-format {goal_fmt} --alg {alg} --repr {repr} -v",
"args": [
{ "alg": "bfs", "repr": ["matrix", "map"] },
{ "alg": "astar-zero", "repr": "map" },
{ "alg": "astar-naive", "repr": ["matrix", "map", "sortvec"] }
]
"args": {
"alg": [
"bfs",
"astar-zero",
"astar-naive",
"astar-naive-opt",
"astar-assg-posvoxel",
"astar-assg-posvoxel-opt",
"astar-assg-pos",
"astar-assg-pos-opt",
"astar-assg-voxel",
"astar-assg-voxel-opt"
],
"repr": ["matrix", "map", "sortvec"]
}
}
32 changes: 16 additions & 16 deletions experiments/voxel/full_traversal.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM ghcr.io/paradise-fi/rofi.debian:latest

SHELL ["/bin/bash", "-c"]

RUN apt-get install -y --no-install-recommends time jq moreutils

RUN cd /; \
git clone https://github.com/paradise-fi/RoFI.git --depth 1 --branch master; \
cd RoFI; \
Expand All @@ -15,29 +17,27 @@ RUN echo $'#!/usr/bin/env bash\n\
$@\n' > /bin/rofiInvoke; \
chmod +x /bin/rofiInvoke

RUN export RUSTFLAGS="-C debug-assertions -C overflow-checks"

WORKDIR /RoFI

ENTRYPOINT ["rofiInvoke"]

# Name: RoFI Voxel - full traversal bfs
# Memory limit: 2048 MB
# Name: Voxel - full traversal bfs
# Memory limit: 32768 MB
# Tasks:
# [
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m1_snake.json --log-counters /artefact/results.json -vv",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m2_snake.json --log-counters /artefact/results.json -vv",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m3_snake.json --log-counters /artefact/results.json -vv",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m4_snake.json --log-counters /artefact/results.json -vv --max 8",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m5_snake.json --log-counters /artefact/results.json -vv --max 7",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m6_snake.json --log-counters /artefact/results.json -vv --max 6",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m7_snake.json --log-counters /artefact/results.json -vv --max 6",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m8_snake.json --log-counters /artefact/results.json -vv --max 5",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m9_snake.json --log-counters /artefact/results.json -vv --max 5",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m10_snake.json --log-counters /artefact/results.json -vv --max 5",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m11_snake.json --log-counters /artefact/results.json -vv --max 4",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m12_snake.json --log-counters /artefact/results.json -vv --max 4",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m13_snake.json --log-counters /artefact/results.json -vv --max 4",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m14_snake.json --log-counters /artefact/results.json -vv --max 4",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m15_snake.json --log-counters /artefact/results.json -vv --max 4"
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m4_snake.json --log-counters /artefact/results.json -vv --max 10",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m5_snake.json --log-counters /artefact/results.json -vv --max 8",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m6_snake.json --log-counters /artefact/results.json -vv --max 7",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m7_snake.json --log-counters /artefact/results.json -vv --max 7",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m8_snake.json --log-counters /artefact/results.json -vv --max 6",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m9_snake.json --log-counters /artefact/results.json -vv --max 6",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m10_snake.json --log-counters /artefact/results.json -vv --max 6",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m11_snake.json --log-counters /artefact/results.json -vv --max 6",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m12_snake.json --log-counters /artefact/results.json -vv --max 5",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m13_snake.json --log-counters /artefact/results.json -vv --max 5",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m14_snake.json --log-counters /artefact/results.json -vv --max 5",
# "rofi-voxel_full_traversal_bfs data/configurations/voxel/snake/m15_snake.json --log-counters /artefact/results.json -vv --max 5"
# ]
33 changes: 24 additions & 9 deletions experiments/voxel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ def parse_generic_json(cls: type[T], json_value: Any) -> T:
assert isinstance(json_value, cls), f"Type {cls} is dict with no type args"
return json_value
key_cls, value_cls = cls_args
return {
parse_json(key_cls, key): parse_json(value_cls, value)
for key, value in json_value.items()
} # type: ignore
try:
return {
parse_json(key_cls, key): parse_json(value_cls, value)
for key, value in json_value.items()
} # type: ignore
except ValueError as e:
raise ValueError(f"Error parsing {cls}: {e}") from e

if cls_origin is list:
if not isinstance(json_value, list):
Expand All @@ -64,7 +67,10 @@ def parse_generic_json(cls: type[T], json_value: Any) -> T:
assert isinstance(json_value, cls), f"Type {cls} is list with no type args"
return json_value
(arg_cls,) = cls_args
return [parse_json(arg_cls, value) for value in json_value] # type: ignore
try:
return [parse_json(arg_cls, value) for value in json_value] # type: ignore
except ValueError as e:
raise ValueError(f"Error parsing {cls}: {e}") from e

if cls_origin is types.UnionType or cls_origin is Union:
for arg_cls in cls_args:
Expand Down Expand Up @@ -99,10 +105,19 @@ def parse_json_dataclass(cls: type[T], json_value: Any) -> T:
raise ValueError(f"Cannot parse dataclass key from type {type(key)}")

field_types = {field.name: field.type for field in dataclasses.fields(cls)}
field_values = {
key: parse_json(field_types[key], value) if key in field_types else value
for key, value in json_value.items()
}

def parse_field(json_key: str, json_value: Any):
try:
if json_key in field_types:
return parse_json(field_types[json_key], json_value)
else:
return json_value
except ValueError as e:
raise ValueError(
f"Error parsing field {json_key!r} from {cls.__name__}: {e}"
) from e

field_values = {key: parse_field(key, value) for key, value in json_value.items()}

result = cls(**field_values)
assert isinstance(result, cls)
Expand Down
6 changes: 6 additions & 0 deletions softwareComponents/voxelReconfig/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ educe = "0.4"
enum-iterator = "1.2"
iter_fixed = "0.3"
itertools = "0.11"
lapjv = "0.2"
litemap = "0.7"
log = "0.4"
modular-bitfield = "0.11"
ndarray = "0.13" # In sync with crate lapjv
num = "0.4"
ordered-float = "4.1"
rs-graph = "0.21"
rustc-hash = "1.1"
serde = { version = "1.0", features = ["derive"] }
smallvec = "1.10"
static_assertions = "1.1"

[dev-dependencies]
multicode = { path = "multicode" }
2 changes: 2 additions & 0 deletions softwareComponents/voxelReconfig/multicode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
12 changes: 12 additions & 0 deletions softwareComponents/voxelReconfig/multicode/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "multicode"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1.0"
syn = { version = "2.0", features = ["full"] }
quote = "1.0"
8 changes: 8 additions & 0 deletions softwareComponents/voxelReconfig/multicode/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod multicode_impl;

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn multicode(attr: TokenStream, item: TokenStream) -> TokenStream {
multicode_impl::multicode_impl(attr, item)
}
124 changes: 124 additions & 0 deletions softwareComponents/voxelReconfig/multicode/src/multicode_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
use std::str::FromStr;

use proc_macro2::{ TokenStream, TokenTree, Group, Delimiter };
use quote::{ ToTokens, TokenStreamExt };
use syn::{ bracketed, parse_macro_input, Ident, Token };
use syn::punctuated::Punctuated;
use syn::parse::{ Parse, ParseStream };
use syn::token;

macro_rules! outer_sep {
() => { Token![;] };
}

struct Replacement {
mod_name: Ident,
_sep: Token![:],
replacement: TokenStream,
}
impl std::fmt::Debug for Replacement {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { mod_name, _sep, replacement } = self;
f.debug_struct("Replacement")
.field("mod_name", mod_name)
.field("replacement", replacement)
.finish()
}
}
impl Parse for Replacement {
fn parse(input: ParseStream) -> syn::Result<Self> {
Ok(Replacement {
mod_name: input.parse()?,
_sep: input.parse()?,
replacement: {
let mut repl = TokenStream::new();
while !input.is_empty() && !input.peek(outer_sep!()) {
repl.append(input.parse::<TokenTree>()?);
}
repl
},
})
}
}
impl Replacement {
fn add_mod_with_repl(
&self,
out_stream: &mut TokenStream,
repl_ident: &Ident,
inner_stream: TokenStream
) {
Ident::new("mod", self.mod_name.span()).to_tokens(out_stream);
self.mod_name.to_tokens(out_stream);

let pub_use_all = TokenStream::from_str("pub use super::*;").unwrap();
let repl_stream = replace_ident(inner_stream, repl_ident, &self.replacement);
Group::new(
Delimiter::Brace,
TokenStream::from_iter(pub_use_all.into_iter().chain(repl_stream))
).to_tokens(out_stream);
}
}

fn replace_ident(input: TokenStream, repl_ident: &Ident, replacement: &TokenStream) -> TokenStream {
input
.into_iter()
.map(|token| {
match token {
TokenTree::Ident(ident) => {
if ident.to_string() == repl_ident.to_string() {
replacement.clone()
} else {
TokenTree::Ident(ident).into_token_stream()
}
}
TokenTree::Group(group) => {
let new_stream = replace_ident(group.stream(), repl_ident, replacement);
let mut new_group = Group::new(group.delimiter(), new_stream);
new_group.set_span(group.span());
TokenTree::Group(new_group).into_token_stream()
}
token => token.into_token_stream(),
}
})
.collect()
}
struct MulticodeArgs {
ident: Ident,
_sep: Token![,],
_repl_bracket: token::Bracket,
replacements: Punctuated<Replacement, outer_sep!()>,
}
impl std::fmt::Debug for MulticodeArgs {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { ident, _sep, _repl_bracket, replacements } = self;
f.debug_struct("MulticodeArgs")
.field("ident", ident)
.field("replacements", &replacements.iter().collect::<Vec<_>>())
.finish()
}
}
impl Parse for MulticodeArgs {
fn parse(input: ParseStream) -> syn::Result<Self> {
let repl_content;
Ok(MulticodeArgs {
ident: input.parse()?,
_sep: input.parse()?,
_repl_bracket: bracketed!(repl_content in input),
replacements: Punctuated::parse_terminated(&repl_content)?,
})
}
}

pub fn multicode_impl(
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream
) -> proc_macro::TokenStream {
let args = parse_macro_input!(attr as MulticodeArgs);
let item = TokenStream::from(item);

let mut result = TokenStream::new();
for repl in &args.replacements {
repl.add_mod_with_repl(&mut result, &args.ident, item.clone());
}
result.into()
}
Loading
Loading