diff --git a/.github/workflow/build.yml b/.github/workflow/build.yml new file mode 100644 index 0000000..41e921b --- /dev/null +++ b/.github/workflow/build.yml @@ -0,0 +1,28 @@ +on: push +env: + PYTHON_VERSION: 3.7 + RUST_TOOLCHAIN: nightly + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + name: Build Rust Extension for ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - name: Setup Python + uses: actions/setup-python@v4.0.0 + with: + python-version: ${{env.PYTHON_VERSION}} + cache: pip + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1.0.6 + with: + toolchain: ${{env.RUST_TOOLCHAIN}} + profile: minimal + default: true + - name: Build Python Extension + run: | + python -m build . diff --git a/.gitignore b/.gitignore index d26e49d..b50d296 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ rust/target rust/.history/ rust/Cargo.lock +rust/ed_lrr_test.log **/*.rs.bk *.tmp *.idx @@ -27,4 +28,4 @@ ed_lrr_gui/web/ed_lrr_web_ui.db __version__.py .nox/ dist_vis.py -img/** \ No newline at end of file +img/** diff --git a/rust/.vscode/settings.json b/rust/.vscode/settings.json index bf0fd37..ff0c268 100644 --- a/rust/.vscode/settings.json +++ b/rust/.vscode/settings.json @@ -16,5 +16,11 @@ "*.vpy": "python", "stat.h": "c" }, - "rust-analyzer.diagnostics.disabled": ["unresolved-import"] + "rust-analyzer.diagnostics.disabled": [ + "unresolved-import" + ], + "yaml.schemas": { + "https://raw.githubusercontent.com/kaitai-io/ksy_schema/master/ksy_schema.json": "*.ksy", + "https://json.schemastore.org/github-workflow.json": "file:///d%3A/devel/rust/ed_lrr_gui/.github/workflow/build.yml" + } } \ No newline at end of file diff --git a/rust/Cargo.toml b/rust/Cargo.toml index fbcaba0..ad841d5 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -23,7 +23,6 @@ csv = "1.1.6" humantime = "2.1.0" permutohedron = "0.2.4" serde_json = "1.0.81" -fnv = "1.0.7" bincode = "1.3.3" sha3 = "0.10.1" byteorder = "1.4.3" @@ -43,14 +42,6 @@ eval = "0.4.3" pythonize = "0.16.0" itertools = "0.10.3" rustc-hash = "1.1.0" -stats_alloc = "0.1.10" - -tracing = { version = "0.1.34", optional = true } -tracing-subscriber = { version = "0.3.11", optional = true } -tracing-tracy = { version = "0.10.0", optional = true } -# tracing-unwrap = { version = "0.9.2", optional = true } -tracy-client = { version = "0.14.0", optional = true } -tracing-chrome = "0.6.0" rand = "0.8.5" eyre = "0.6.8" memmap = "0.7.0" @@ -59,9 +50,17 @@ nohash-hasher = "0.2.0" dashmap = "5.3.4" rayon = "1.5.3" +stats_alloc = {version="0.1.10", optional=true} +tracing = { version = "0.1.34", optional = true } +tracing-subscriber = { version = "0.3.11", optional = true } +tracing-tracy = { version = "0.10.0", optional = true } +# tracing-unwrap = { version = "0.9.2", optional = true } +tracy-client = { version = "0.14.0", optional = true } +tracing-chrome = "0.6.0" + [features] -profiling = ["tracing","tracing-subscriber","tracing-tracy","tracy-client"] +profiling = ["tracing","tracing-subscriber","tracing-tracy","tracy-client","stats_alloc"] [dev-dependencies] criterion = { version = "0.3.5", features = ["real_blackbox"] } diff --git a/rust/route_log.txt b/rust/route_log.txt deleted file mode 100644 index e69de29..0000000 diff --git a/rust/run_test.py b/rust/run_test.py index 27504ba..58ffd2c 100644 --- a/rust/run_test.py +++ b/rust/run_test.py @@ -76,8 +76,8 @@ r.load("../stars.csv", immediate=False) # start, end = "Sol", "Colonia" # systems = r.resolve(start, end) # sys_ids = {k: v["id"] for k, v in systems.items()} - -r.bfs_test(JUMP_RANGE) +r.floyd_warshall_test(JUMP_RANGE) +# r.bfs_test(JUMP_RANGE) # cfg = {} # cfg["mode"] = "incremental_broadening" diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 0143205..efc9936 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -13,13 +13,15 @@ pub mod search_algos; pub mod ship; // ========================= +#[cfg(feature="mem_profiling")] use stats_alloc::{Region, StatsAlloc, INSTRUMENTED_SYSTEM}; +#[cfg(feature="mem_profiling")] use std::alloc::System as SystemAlloc; use std::collections::BTreeMap; use std::io::{BufWriter, Write}; use std::path::Path; use std::time::Instant; -#[cfg(not(feature = "profiling"))] +#[cfg(feature = "mem_profiling")] #[global_allocator] static GLOBAL: &StatsAlloc = &INSTRUMENTED_SYSTEM; // ========================= @@ -295,13 +297,13 @@ impl PyRouter { if is_default && !is_ship { warn!("no mode specified, defaulting to {}", mode); } - #[cfg(not(feature = "profiling"))] + #[cfg(feature = "mem_profiling")] let reg = Region::new(GLOBAL); let res = match self.router.compute_route(&ids, range, mode, num_workers) { Ok(route) => Ok(route), Err(err_msg) => Err(PyErr::new::(err_msg)), }; - #[cfg(not(feature = "profiling"))] + #[cfg(feature = "mem_profiling")] println!("{:?}", reg.change()); return res; } diff --git a/rust/src/route.rs b/rust/src/route.rs index 92c7554..b73e2f7 100644 --- a/rust/src/route.rs +++ b/rust/src/route.rs @@ -1623,16 +1623,17 @@ impl Router { info!("nb..."); let total = self.tree.size(); for (n, node) in self.tree.iter().enumerate() { - if (n % 100_000) == 0 { - println!("{}/{}", n, total); - } - let key = (node.id as u64) << 32; - for nb in self.neighbours(node, range) { - let key = key | nb.id as u64; - dist.entry(key).or_insert(1); - } - let key = ((node.id as u64) << 32) | node.id as u64; - dist.insert(key, 0); + println!("{}: {}",node.id,self.neighbours(node, range).count()); + // if (n % 100_000) == 0 { + // println!("{}/{}", n, total); + // } + // let key = (node.id as u64) << 32; + // for nb in self.neighbours(node, range) { + // let key = key | nb.id as u64; + // dist.entry(key).or_insert(1); + // } + // let key = ((node.id as u64) << 32) | node.id as u64; + // dist.insert(key, 0); } todo!() } diff --git a/rust/src/search_algos/mod.rs b/rust/src/search_algos/mod.rs index 7f2ae32..cc63b20 100644 --- a/rust/src/search_algos/mod.rs +++ b/rust/src/search_algos/mod.rs @@ -1,6 +1,7 @@ +use rustc_hash::FxHashMap; + use crate::common::TreeNode; use crate::route::{Router, SearchState}; -use fnv::FnvHashMap; trait SearchAlgoImpl { fn get_weight(&mut self, systems: &TreeNode, router: &Router) -> Option; @@ -23,7 +24,7 @@ trait SearchAlgoImpl { struct SearchAlgo<'a> { algo: Box, - prev: FnvHashMap, + prev: FxHashMap, state: Option, router: &'a Router, } @@ -40,7 +41,7 @@ impl<'a> SearchAlgo<'a> { fn new(router: &'a Router, algo: Box) -> Self { Self { algo, - prev: FnvHashMap::default(), + prev: FxHashMap::default(), state: None, router, }