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

perf(lox-orbits): parallelise visibility #195

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
130 changes: 58 additions & 72 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/lox-orbits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
75 changes: 73 additions & 2 deletions crates/lox-orbits/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -28,7 +31,7 @@
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;
Expand Down Expand Up @@ -468,6 +471,7 @@
}

#[pyclass(name = "Event", module = "lox_space", frozen)]
#[derive(Clone, Debug)]
pub struct PyEvent(pub Event<DynTimeScale>);

#[pymethods]
Expand All @@ -493,6 +497,7 @@
}

#[pyclass(name = "Window", module = "lox_space", frozen)]
#[derive(Clone, Debug)]
pub struct PyWindow(pub Window<DynTimeScale>);

#[pymethods]
Expand All @@ -519,6 +524,7 @@
}

#[pyclass(name = "Vallado", module = "lox_space", frozen)]
#[derive(Clone, Debug)]
pub struct PyVallado(pub DynVallado);

impl From<ValladoError> for PyErr {
Expand Down Expand Up @@ -559,7 +565,7 @@
}

#[pyclass(name = "GroundLocation", module = "lox_space", frozen)]
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct PyGroundLocation(pub DynGroundLocation);

#[pymethods]
Expand Down Expand Up @@ -760,6 +766,71 @@
)
}

#[pyclass(name = "Ensemble", module = "lox_space", frozen)]

Check warning on line 769 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L769

Added line #L769 was not covered by tests
pub struct PyEnsemble(pub HashMap<String, DynTrajectory>);

#[pymethods]

Check warning on line 772 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L772

Added line #L772 was not covered by tests
impl PyEnsemble {
#[new]
pub fn new(ensemble: HashMap<String, PyTrajectory>) -> Self {
Self(
ensemble
.into_iter()
.map(|(name, trajectory)| (name, trajectory.0))
.collect(),
)
}

Check warning on line 782 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L775-L782

Added lines #L775 - L782 were not covered by tests
}

#[pyfunction]

Check warning on line 785 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L785

Added line #L785 was not covered by tests
#[pyo3(signature = (times, ground_stations, spacecraft, provider=None))]
pub fn visibility_all(
py: Python<'_>,
times: &Bound<'_, PyList>,
ground_stations: HashMap<String, (PyGroundLocation, PyElevationMask)>,
spacecraft: &Bound<'_, PyEnsemble>,
provider: Option<&Bound<'_, PyUt1Provider>>,
) -> PyResult<HashMap<String, HashMap<String, Vec<PyWindow>>>> {
let times: Vec<DynTime> = times
.extract::<Vec<PyTime>>()?
.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(&times, &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
},
)
}))
}

Check warning on line 832 in crates/lox-orbits/src/python.rs

View check run for this annotation

Codecov / codecov/patch

crates/lox-orbits/src/python.rs#L787-L832

Added lines #L787 - L832 were not covered by tests

impl From<ElevationMaskError> for PyErr {
fn from(err: ElevationMaskError) -> Self {
PyValueError::new_err(err.to_string())
Expand Down
Loading
Loading