From 988aa2c6d6c8fa8d9594ad880d6ef9f05f661aa5 Mon Sep 17 00:00:00 2001 From: Helge Eichhorn Date: Sun, 26 Jan 2025 16:07:36 +0100 Subject: [PATCH] perf(lox-orbits): parallelise visibility --- Cargo.lock | 130 ++++++++++------------ Cargo.toml | 5 +- crates/lox-orbits/Cargo.toml | 2 + crates/lox-orbits/src/python.rs | 75 ++++++++++++- crates/lox-orbits/src/trajectories.rs | 29 ++--- crates/lox-space/Cargo.toml | 15 --- crates/lox-space/benches/iau_frames.rs | 60 ---------- crates/lox-space/benches/observables.rs | 51 --------- crates/lox-space/benches/time_delta.rs | 19 ---- crates/lox-space/lox_space.pyi | 6 + crates/lox-space/src/lib.rs | 8 +- crates/lox-space/tests/conftest.py | 4 +- crates/lox-space/tests/test_benchmarks.py | 34 ++---- justfile | 4 +- tools/lox-gen/Cargo.lock | 4 +- 15 files changed, 174 insertions(+), 272 deletions(-) delete mode 100644 crates/lox-space/benches/iau_frames.rs delete mode 100644 crates/lox-space/benches/observables.rs delete mode 100644 crates/lox-space/benches/time_delta.rs diff --git a/Cargo.lock b/Cargo.lock index c36e72c4..50b776b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -26,12 +32,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anstyle" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" - [[package]] name = "autocfg" version = "1.4.0" @@ -100,42 +100,35 @@ dependencies = [ ] [[package]] -name = "clap" -version = "4.5.20" +name = "core-foundation-sys" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" -dependencies = [ - "clap_builder", -] +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] -name = "clap_builder" -version = "4.5.20" +name = "crossbeam-deque" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ - "anstyle", - "clap_lex", - "terminal_size", + "crossbeam-epoch", + "crossbeam-utils", ] [[package]] -name = "clap_lex" -version = "0.7.2" +name = "crossbeam-epoch" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] [[package]] -name = "condtype" -version = "1.3.0" +name = "crossbeam-utils" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "csv" @@ -158,31 +151,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "divan" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e05d17bd4ff1c1e7998ed4623d2efd91f72f1e24141ac33aac9377974270e1f" -dependencies = [ - "cfg-if", - "clap", - "condtype", - "divan-macros", - "libc", - "regex-lite", -] - -[[package]] -name = "divan-macros" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b4464d46ce68bfc7cb76389248c7c254def7baca8bece0693b02b83842c4c88" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "dyn-clone" version = "1.0.17" @@ -238,6 +206,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" + [[package]] name = "futures" version = "0.3.31" @@ -361,6 +335,12 @@ name = "hashbrown" version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", + "rayon", +] [[package]] name = "heck" @@ -547,6 +527,7 @@ dependencies = [ "csv", "float_eq", "glam", + "hashbrown", "itertools", "libm", "lox-bodies", @@ -556,6 +537,7 @@ dependencies = [ "lox-time", "numpy", "pyo3", + "rayon", "rstest", "sgp4", "thiserror", @@ -565,7 +547,6 @@ dependencies = [ name = "lox-space" version = "0.1.0-alpha.13" dependencies = [ - "divan", "lox-bodies", "lox-ephem", "lox-math", @@ -833,6 +814,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" dependencies = [ "cfg-if", + "hashbrown", "indoc", "libc", "memoffset", @@ -959,6 +941,26 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "regex" version = "1.11.1" @@ -982,12 +984,6 @@ dependencies = [ "regex-syntax", ] -[[package]] -name = "regex-lite" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" - [[package]] name = "regex-syntax" version = "0.8.5" @@ -1181,16 +1177,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "terminal_size" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f599bd7ca042cfdf8f4512b277c02ba102247820f9d9d4a9f521f496751a6ef" -dependencies = [ - "rustix", - "windows-sys 0.59.0", -] - [[package]] name = "thiserror" version = "2.0.3" diff --git a/Cargo.toml b/Cargo.toml index 91d4643f..6370b52e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,11 +22,11 @@ lox-space = { path = "crates/lox-space", version = "0.1.0-alpha.13" } lox-time = { path = "crates/lox-time", version = "0.1.0-alpha.3" } csv = "1.3.0" -divan = "0.1.14" dyn-clone = "1.0.17" fast_polynomial = "0.3.0" float_eq = "1.0.1" glam = "0.29.2" +hashbrown = {version = "0.15", features = ["rayon"]} itertools = "0.13.0" libm = "0.2.8" nom = "7.1.3" @@ -35,8 +35,9 @@ num-derive = "0.4.2" num-traits = "0.2.19" numpy = "0.23.0" proptest = "1.4.0" -pyo3 = "0.23.3" +pyo3 = {version = "0.23.3", features = ["hashbrown"]} quick-xml = { version = "0.31.0", features = ["serde", "serialize"] } +rayon = "1.10.0" regex = "1.10.4" rstest = "0.23.0" serde = { version = "1.0.199", features = ["derive"] } diff --git a/crates/lox-orbits/Cargo.toml b/crates/lox-orbits/Cargo.toml index 8fc82dbc..5d7fb3d4 100644 --- a/crates/lox-orbits/Cargo.toml +++ b/crates/lox-orbits/Cargo.toml @@ -18,10 +18,12 @@ lox-math.workspace = true csv.workspace = true float_eq.workspace = true glam.workspace = true +hashbrown.workspace = true itertools.workspace = true libm.workspace = true numpy = { workspace = true, optional = true } pyo3 = { workspace = true, optional = true } +rayon.workspace = true sgp4.workspace = true thiserror.workspace = true diff --git a/crates/lox-orbits/src/python.rs b/crates/lox-orbits/src/python.rs index 4c0216b7..ddb5a769 100644 --- a/crates/lox-orbits/src/python.rs +++ b/crates/lox-orbits/src/python.rs @@ -6,7 +6,10 @@ * file, you can obtain one at https://mozilla.org/MPL/2.0/. */ +use rayon::prelude::*; + use glam::DVec3; +use hashbrown::HashMap; use lox_ephem::python::PySpk; use lox_time::DynTime; use numpy::{PyArray1, PyArray2, PyArrayMethods}; @@ -28,7 +31,7 @@ use lox_time::python::time::PyTime; use lox_time::python::ut1::PyUt1Provider; use lox_time::time_scales::{DynTimeScale, Tai}; -use crate::analysis::{ElevationMask, ElevationMaskError}; +use crate::analysis::{visibility_dyn, ElevationMask, ElevationMaskError}; use crate::elements::{DynKeplerian, Keplerian}; use crate::events::{Event, FindEventError, Window}; use crate::frames::iau::IauFrameTransformationError; @@ -468,6 +471,7 @@ impl PyTrajectory { } #[pyclass(name = "Event", module = "lox_space", frozen)] +#[derive(Clone, Debug)] pub struct PyEvent(pub Event); #[pymethods] @@ -493,6 +497,7 @@ impl PyEvent { } #[pyclass(name = "Window", module = "lox_space", frozen)] +#[derive(Clone, Debug)] pub struct PyWindow(pub Window); #[pymethods] @@ -519,6 +524,7 @@ impl PyWindow { } #[pyclass(name = "Vallado", module = "lox_space", frozen)] +#[derive(Clone, Debug)] pub struct PyVallado(pub DynVallado); impl From for PyErr { @@ -559,7 +565,7 @@ impl PyVallado { } #[pyclass(name = "GroundLocation", module = "lox_space", frozen)] -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct PyGroundLocation(pub DynGroundLocation); #[pymethods] @@ -760,6 +766,71 @@ pub fn visibility( ) } +#[pyclass(name = "Ensemble", module = "lox_space", frozen)] +pub struct PyEnsemble(pub HashMap); + +#[pymethods] +impl PyEnsemble { + #[new] + pub fn new(ensemble: HashMap) -> Self { + Self( + ensemble + .into_iter() + .map(|(name, trajectory)| (name, trajectory.0)) + .collect(), + ) + } +} + +#[pyfunction] +#[pyo3(signature = (times, ground_stations, spacecraft, provider=None))] +pub fn visibility_all( + py: Python<'_>, + times: &Bound<'_, PyList>, + ground_stations: HashMap, + spacecraft: &Bound<'_, PyEnsemble>, + provider: Option<&Bound<'_, PyUt1Provider>>, +) -> PyResult>>> { + let times: Vec = times + .extract::>()? + .into_iter() + .map(|s| s.0) + .collect(); + let provider = provider.map(|p| &p.get().0); + let spacecraft = &spacecraft.get().0; + Ok(py.allow_threads(|| { + ground_stations.iter().fold( + HashMap::with_capacity(ground_stations.len()), + |mut passes, (gs_name, (gs, mask))| { + passes.insert( + gs_name.clone(), + spacecraft + .par_iter() + .fold(HashMap::new, |mut passes, (sc_name, sc)| { + passes.insert( + sc_name.clone(), + visibility_dyn(×, &gs.0, &mask.0, sc, provider) + .into_iter() + .map(PyWindow) + .collect(), + ); + + passes + }) + .reduce( + || HashMap::with_capacity(spacecraft.len()), + |mut p1, p2| { + p1.extend(p2); + p1 + }, + ), + ); + passes + }, + ) + })) +} + impl From for PyErr { fn from(err: ElevationMaskError) -> Self { PyValueError::new_err(err.to_string()) diff --git a/crates/lox-orbits/src/trajectories.rs b/crates/lox-orbits/src/trajectories.rs index 801d94f7..da9948d8 100644 --- a/crates/lox-orbits/src/trajectories.rs +++ b/crates/lox-orbits/src/trajectories.rs @@ -1,5 +1,4 @@ use std::num::ParseFloatError; -use std::sync::Arc; use csv::Error; use glam::DVec3; @@ -19,16 +18,6 @@ use crate::frames::ReferenceFrame; use crate::frames::{DynFrame, Icrf}; use crate::states::State; -#[derive(Clone, Debug, PartialEq)] -#[repr(transparent)] -struct ArcVecF64(Arc>); - -impl AsRef<[f64]> for ArcVecF64 { - fn as_ref(&self) -> &[f64] { - self.0.as_ref() - } -} - impl From for TrajectoryError { fn from(err: Error) -> Self { TrajectoryError::CsvError(err.to_string()) @@ -48,13 +37,13 @@ pub enum TrajectoryError { #[derive(Clone, Debug)] pub struct Trajectory { states: Vec>, - t: ArcVecF64, - x: Series>, - y: Series>, - z: Series>, - vy: Series>, - vx: Series>, - vz: Series>, + t: Vec, + x: Series, Vec>, + y: Series, Vec>, + z: Series, Vec>, + vy: Series, Vec>, + vx: Series, Vec>, + vz: Series, Vec>, } pub type DynTrajectory = Trajectory; @@ -74,7 +63,7 @@ where .iter() .map(|s| (s.time() - start_time.clone()).to_decimal_seconds()) .collect(); - let t = ArcVecF64(Arc::new(t)); + // let t = ArcVecF64(Arc::new(t)); let x: Vec = states.iter().map(|s| s.position().x).collect(); let y: Vec = states.iter().map(|s| s.position().y).collect(); let z: Vec = states.iter().map(|s| s.position().z).collect(); @@ -138,7 +127,7 @@ where } pub fn to_vec(&self) -> Vec> { - let times = self.t.clone().0; + let times = self.t.clone(); let mut vec = Vec::with_capacity(times.len()); for (i, state) in self.states.iter().enumerate() { vec.push(vec![ diff --git a/crates/lox-space/Cargo.toml b/crates/lox-space/Cargo.toml index 35b36b48..b4c13396 100644 --- a/crates/lox-space/Cargo.toml +++ b/crates/lox-space/Cargo.toml @@ -31,18 +31,3 @@ python = [ "lox-orbits/python", "lox-time/python", ] - -[dev-dependencies] -divan.workspace = true - -[[bench]] -name = "iau_frames" -harness = false - -[[bench]] -name = "time_delta" -harness = false - -[[bench]] -name = "observables" -harness = false diff --git a/crates/lox-space/benches/iau_frames.rs b/crates/lox-space/benches/iau_frames.rs deleted file mode 100644 index ef95d045..00000000 --- a/crates/lox-space/benches/iau_frames.rs +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2023. Helge Eichhorn and the LOX contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - */ - -use lox_bodies::{Jupiter, RotationalElements}; -use lox_orbits::{frames::BodyFixed, rotations::Rotation}; - -fn main() { - // Run registered benchmarks. - divan::main(); -} - -#[divan::bench] -fn right_ascension() { - Jupiter.right_ascension(divan::black_box(0.0)); -} - -#[divan::bench] -fn right_ascension_dot() { - Jupiter.right_ascension_rate(divan::black_box(0.0)); -} - -#[divan::bench] -fn declination() { - Jupiter.declination(divan::black_box(0.0)); -} - -#[divan::bench] -fn declination_dot() { - Jupiter.declination_rate(divan::black_box(0.0)); -} - -#[divan::bench] -fn prime_meridian() { - Jupiter.rotation_angle(divan::black_box(0.0)); -} - -#[divan::bench] -fn prime_meridian_dot() { - Jupiter.rotation_rate(divan::black_box(0.0)); -} - -#[divan::bench] -fn rotational_elements() { - Jupiter.rotational_elements(divan::black_box(0.0)); -} - -#[divan::bench] -fn rotational_element_rates() { - Jupiter.rotational_element_rates(divan::black_box(0.0)); -} - -#[divan::bench] -fn rotation() -> Rotation { - BodyFixed(Jupiter).rotation(divan::black_box(0.0)) -} diff --git a/crates/lox-space/benches/observables.rs b/crates/lox-space/benches/observables.rs deleted file mode 100644 index 22a3623a..00000000 --- a/crates/lox-space/benches/observables.rs +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2024. Helge Eichhorn and the LOX contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - */ - -use lox_bodies::Earth; -use lox_orbits::analysis::elevation; -use lox_orbits::frames::{Icrf, NoOpFrameTransformationProvider, Topocentric}; -use lox_orbits::ground::GroundLocation; -use lox_orbits::trajectories::Trajectory; -use lox_time::prelude::Tai; -use lox_time::{time, Time}; - -fn main() { - // Run registered benchmarks. - divan::main(); -} - -#[divan::bench] -fn elevation_rotation(bencher: divan::Bencher) { - bencher - .with_inputs(|| { - ( - time!(Tai, 2022, 2, 1).unwrap(), - GroundLocation::new(-4f64.to_radians(), 41f64.to_radians(), 0.0, Earth), - spacecraft_trajectory(), - ) - }) - .bench_values(|(t, gs, sc)| elevation(t, &gs, &sc, &NoOpFrameTransformationProvider)); -} - -fn ground_station_trajectory() -> Trajectory, Earth, Icrf> { - Trajectory::from_csv( - include_str!("../../../data/trajectory_cebr.csv"), - Earth, - Icrf, - ) - .unwrap() -} - -fn spacecraft_trajectory() -> Trajectory, Earth, Icrf> { - Trajectory::from_csv( - include_str!("../../../data/trajectory_lunar.csv"), - Earth, - Icrf, - ) - .unwrap() -} diff --git a/crates/lox-space/benches/time_delta.rs b/crates/lox-space/benches/time_delta.rs deleted file mode 100644 index b69c7b55..00000000 --- a/crates/lox-space/benches/time_delta.rs +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2023. Helge Eichhorn and the LOX contributors - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, you can obtain one at https://mozilla.org/MPL/2.0/. - */ - -use lox_time::deltas::TimeDelta; - -fn main() { - // Run registered benchmarks. - divan::main(); -} - -#[divan::bench] -fn from_f64_seconds() { - TimeDelta::try_from_decimal_seconds(divan::black_box(60.3)).unwrap(); -} diff --git a/crates/lox-space/lox_space.pyi b/crates/lox-space/lox_space.pyi index fa8683ad..32fe104e 100644 --- a/crates/lox-space/lox_space.pyi +++ b/crates/lox-space/lox_space.pyi @@ -23,6 +23,12 @@ def visibility( sc: Trajectory, provider: UT1Provider, ): ... +def visibility_all( + times: list[Time], + ground_stations: dict[str,tuple[GroundLocation,ElevationMask]], + sc: dict[str,Trajectory], + provider: UT1Provider | None, +): ... class Origin: def __new__(cls, origin: str | int): ... diff --git a/crates/lox-space/src/lib.rs b/crates/lox-space/src/lib.rs index 657a7252..1ce76472 100644 --- a/crates/lox-space/src/lib.rs +++ b/crates/lox-space/src/lib.rs @@ -9,9 +9,9 @@ use lox_bodies::python::PyOrigin; use lox_ephem::python::PySpk; use lox_orbits::python::{ - find_events, find_windows, visibility, PyElevationMask, PyEvent, PyFrame, PyGroundLocation, - PyGroundPropagator, PyKeplerian, PyObservables, PySgp4, PyState, PyTrajectory, PyVallado, - PyWindow, + find_events, find_windows, visibility, visibility_all, PyElevationMask, PyEnsemble, PyEvent, + PyFrame, PyGroundLocation, PyGroundPropagator, PyKeplerian, PyObservables, PySgp4, PyState, + PyTrajectory, PyVallado, PyWindow, }; use pyo3::prelude::*; @@ -27,7 +27,9 @@ fn lox_space(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(find_events, m)?)?; m.add_function(wrap_pyfunction!(find_windows, m)?)?; m.add_function(wrap_pyfunction!(visibility, m)?)?; + m.add_function(wrap_pyfunction!(visibility_all, m)?)?; m.add_class::()?; + m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?; diff --git a/crates/lox-space/tests/conftest.py b/crates/lox-space/tests/conftest.py index cb6c2e39..49b9cd02 100644 --- a/crates/lox-space/tests/conftest.py +++ b/crates/lox-space/tests/conftest.py @@ -47,8 +47,8 @@ def estrack(): ("New Norcia", -30.9855, 116.2041), ] return { - name: lox.GroundLocation( + name: (lox.GroundLocation( lox.Origin("Earth"), np.radians(lon), np.radians(lat), 0 - ) + ), lox.ElevationMask.fixed(0)) for name, lat, lon in stations } diff --git a/crates/lox-space/tests/test_benchmarks.py b/crates/lox-space/tests/test_benchmarks.py index b5fb093f..91a16a4f 100644 --- a/crates/lox-space/tests/test_benchmarks.py +++ b/crates/lox-space/tests/test_benchmarks.py @@ -4,33 +4,23 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, you can obtain one at https://mozilla.org/MPL/2.0/. -import itertools import pytest import lox_space as lox - -@pytest.mark.benchmark() -def test_visibility_benchmark(provider, oneweb, estrack): - mask = lox.ElevationMask.fixed(0) +@pytest.fixture(scope="session") +def times(oneweb): t0 = next(iter(oneweb.values())).states()[0].time() - times = [t0 + t for t in lox.TimeDelta.range(0, 86400, 3000)] - - passes = {} + return [t0 + t for t in lox.TimeDelta.range(0, 86400, 3000)] - for (gs_name, gs), (sc_name, sc) in filter( - lambda pair: isinstance(pair[0][1], lox.GroundLocation) - and isinstance(pair[1][1], lox.Trajectory), - itertools.combinations(itertools.chain(estrack.items(), oneweb.items()), 2), - ): - assert isinstance(gs, lox.GroundLocation) - assert isinstance(sc, lox.Trajectory) +@pytest.fixture(scope="session") +def ensemble(oneweb): + return lox.Ensemble(oneweb) + - if not sc_name in passes: - passes[sc_name] = {} - - passes[sc_name][gs_name] = lox.visibility(times, gs, mask, sc, provider) - - assert len(passes) == len(oneweb) +@pytest.mark.benchmark() +def test_visibility_benchmark(estrack, ensemble, oneweb, provider, times): + passes = lox.visibility_all(times, estrack, ensemble, provider) + assert len(passes) == len(estrack) for sc_passes in passes.values(): - assert len(sc_passes) == len(estrack) + assert len(sc_passes) == len(oneweb) diff --git a/justfile b/justfile index f82c6e02..cd98339d 100644 --- a/justfile +++ b/justfile @@ -1,8 +1,8 @@ _default: just -l -build-pyo3: - maturin develop -E dev -m crates/lox-space/Cargo.toml +build-pyo3 *FLAGS: + maturin develop -E dev -m crates/lox-space/Cargo.toml {{FLAGS}} pytest *FLAGS: build-pyo3 pytest {{FLAGS}} diff --git a/tools/lox-gen/Cargo.lock b/tools/lox-gen/Cargo.lock index ae3e28b1..c94537b4 100644 --- a/tools/lox-gen/Cargo.lock +++ b/tools/lox-gen/Cargo.lock @@ -162,7 +162,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lox-derive" -version = "0.1.0-alpha.0" +version = "0.1.0-alpha.1" dependencies = [ "proc-macro2", "quote", @@ -182,7 +182,7 @@ dependencies = [ [[package]] name = "lox-io" -version = "0.1.0-alpha.2" +version = "0.1.0-alpha.3" dependencies = [ "csv", "lox-derive",