Skip to content

Commit

Permalink
Merge pull request #349 from nyx-space/dep/nalgebra-0.33
Browse files Browse the repository at this point in the history
Update to nalgebra 0.33 + switch to anise git
  • Loading branch information
ChristopherRabotin authored Aug 7, 2024
2 parents d1db1d7 + 1aa0d03 commit a8db2ce
Show file tree
Hide file tree
Showing 33 changed files with 344 additions and 418 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ maintenance = { status = "actively-developed" }
gitlab = { repository = "nyx-space/nyx", branch = "master" }

[dependencies]
nalgebra = "=0.32"
nalgebra = "0.33"
log = "0.4"
hifitime = "4.0.0-alpha"
anise = "0.4.0"
# anise = "0.4.0"
anise = { git = "https://github.com/nyx-space/anise.git", branch = "master" }
flate2 = { version = "1.0", features = [
"rust_backend",
], default-features = false }
serde = "1.0"
serde_derive = "1.0"
csv = "1"
hyperdual = "=1.2.0"
hyperdual = "1.3.0"
bytes = "1.0"
rand = "0.8"
rand_distr = "0.4"
Expand Down
7 changes: 3 additions & 4 deletions src/cosmic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ pub trait TimeTagged {
pub trait State: Default + Copy + PartialEq + fmt::Display + fmt::LowerExp + Send + Sync
where
Self: Sized,
DefaultAllocator: Allocator<f64, Self::Size>
+ Allocator<f64, Self::Size, Self::Size>
+ Allocator<f64, Self::VecLength>,
DefaultAllocator:
Allocator<Self::Size> + Allocator<Self::Size, Self::Size> + Allocator<Self::VecLength>,
{
/// Size of the state and its STM
type Size: DimName;
Expand Down Expand Up @@ -85,7 +84,7 @@ where
vector: &OVector<f64, Self::VecLength>,
) -> Self
where
DefaultAllocator: Allocator<f64, Self::VecLength>,
DefaultAllocator: Allocator<Self::VecLength>,
{
self.set(self.epoch() + delta_t_s, vector);
self
Expand Down
17 changes: 8 additions & 9 deletions src/dynamics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::State;
use anise::almanac::planetary::PlanetaryDataError;
use anise::almanac::Almanac;
use anise::errors::AlmanacError;
use hyperdual::{OHyperdual, Owned};
use hyperdual::Owned;
use snafu::Snafu;

use std::fmt;
Expand Down Expand Up @@ -75,9 +75,9 @@ pub use self::sph_harmonics::*;
#[allow(clippy::type_complexity)]
pub trait Dynamics: Clone + Sync + Send
where
DefaultAllocator: Allocator<f64, <Self::StateType as State>::Size>
+ Allocator<f64, <Self::StateType as State>::VecLength>
+ Allocator<f64, <Self::StateType as State>::Size, <Self::StateType as State>::Size>,
DefaultAllocator: Allocator<<Self::StateType as State>::Size>
+ Allocator<<Self::StateType as State>::VecLength>
+ Allocator<<Self::StateType as State>::Size, <Self::StateType as State>::Size>,
{
/// The state of the associated hyperdual state, almost always StateType + U1
type HyperdualSize: DimName;
Expand All @@ -96,7 +96,7 @@ where
almanac: Arc<Almanac>,
) -> Result<OVector<f64, <Self::StateType as State>::VecLength>, DynamicsError>
where
DefaultAllocator: Allocator<f64, <Self::StateType as State>::VecLength>;
DefaultAllocator: Allocator<<Self::StateType as State>::VecLength>;

/// Defines the equations of motion for Dual numbers for these dynamics.
/// _All_ dynamics need to allow for automatic differentiation. However, if differentiation is not supported,
Expand All @@ -114,10 +114,9 @@ where
DynamicsError,
>
where
DefaultAllocator: Allocator<f64, Self::HyperdualSize>
+ Allocator<f64, <Self::StateType as State>::Size>
+ Allocator<f64, <Self::StateType as State>::Size, <Self::StateType as State>::Size>
+ Allocator<OHyperdual<f64, Self::HyperdualSize>, <Self::StateType as State>::Size>,
DefaultAllocator: Allocator<Self::HyperdualSize>
+ Allocator<<Self::StateType as State>::Size>
+ Allocator<<Self::StateType as State>::Size, <Self::StateType as State>::Size>,
Owned<f64, Self::HyperdualSize>: Copy,
{
Err(DynamicsError::StateTransitionMatrixUnset)
Expand Down
2 changes: 1 addition & 1 deletion src/io/tracking_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl DynamicTrackingArc {
pub fn to_tracking_arc<Msr>(&self) -> Result<TrackingArc<Msr>, InputOutputError>
where
Msr: Measurement,
DefaultAllocator: Allocator<f64, Msr::MeasurementSize>,
DefaultAllocator: Allocator<Msr::MeasurementSize>,
{
// Read the file since we closed it earlier
let file = File::open(&self.path).context(StdIOSnafu {
Expand Down
5 changes: 2 additions & 3 deletions src/io/trajectory_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ impl TrajectoryLoader {
pub fn to_traj<S>(&self) -> Result<Traj<S>, InputOutputError>
where
S: Interpolatable,
DefaultAllocator: Allocator<f64, S::VecLength>
+ Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>,
DefaultAllocator:
Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
// Check the schema
let mut has_epoch = false; // Required
Expand Down
5 changes: 1 addition & 4 deletions src/mc/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ impl Dispersion<Normal<f64>> {
#[derive(Clone)]
pub struct DispersedState<S: State>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<usize, S::Size, S::Size>
+ Allocator<f64, S::VecLength>,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
{
/// The dispersed state
pub state: S,
Expand Down
57 changes: 20 additions & 37 deletions src/mc/montecarlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use rand::SeedableRng;
use rand_distr::Distribution;
use rayon::prelude::ParallelIterator;
use rayon::prelude::*;
use std::f64;
use std::fmt;
use std::sync::mpsc::channel;
use std::sync::Arc;
Expand All @@ -47,10 +46,7 @@ use std::time::Instant as StdInstant;
/// One caveat of the design is that the trajectory is used for post processing, not each individual state. This may prevent some event switching from being shown in GNC simulations.
pub struct MonteCarlo<S: Interpolatable, Distr: Distribution<DispersedState<S>>>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<f64, S::VecLength>
+ Allocator<usize, S::Size, S::Size>,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
{
/// Seed of the [64bit PCG random number generator](https://www.pcg-random.org/index.html)
pub seed: Option<u128>,
Expand All @@ -63,10 +59,7 @@ where

impl<S: Interpolatable, Distr: Distribution<DispersedState<S>>> MonteCarlo<S, Distr>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<f64, S::VecLength>
+ Allocator<usize, S::Size, S::Size>,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
{
pub fn new(
nominal_state: S,
Expand Down Expand Up @@ -109,11 +102,10 @@ where
D: Dynamics<StateType = S>,
E: ErrorCtrl,
F: EventEvaluator<S>,
DefaultAllocator: Allocator<f64, <D::StateType as State>::Size>
+ Allocator<f64, <D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<usize, <D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<f64, <D::StateType as State>::VecLength>,
<DefaultAllocator as Allocator<f64, <D::StateType as State>::VecLength>>::Buffer: Send,
DefaultAllocator: Allocator<<D::StateType as State>::Size>
+ Allocator<<D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<<D::StateType as State>::VecLength>,
<DefaultAllocator as Allocator<<D::StateType as State>::VecLength>>::Buffer<f64>: Send,
{
self.resume_run_until_nth_event(prop, almanac, 0, max_duration, event, trigger, num_runs)
}
Expand All @@ -135,11 +127,10 @@ where
D: Dynamics<StateType = S>,
E: ErrorCtrl,
F: EventEvaluator<S>,
DefaultAllocator: Allocator<f64, <D::StateType as State>::Size>
+ Allocator<f64, <D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<usize, <D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<f64, <D::StateType as State>::VecLength>,
<DefaultAllocator as Allocator<f64, <D::StateType as State>::VecLength>>::Buffer: Send,
DefaultAllocator: Allocator<<D::StateType as State>::Size>
+ Allocator<<D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<<D::StateType as State>::VecLength>,
<DefaultAllocator as Allocator<<D::StateType as State>::VecLength>>::Buffer<f64>: Send,
{
// Generate the initial states
let init_states = self.generate_states(skip, num_runs, self.seed);
Expand Down Expand Up @@ -207,11 +198,10 @@ where
where
D: Dynamics<StateType = S>,
E: ErrorCtrl,
DefaultAllocator: Allocator<f64, <D::StateType as State>::Size>
+ Allocator<f64, <D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<usize, <D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<f64, <D::StateType as State>::VecLength>,
<DefaultAllocator as Allocator<f64, <D::StateType as State>::VecLength>>::Buffer: Send,
DefaultAllocator: Allocator<<D::StateType as State>::Size>
+ Allocator<<D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<<D::StateType as State>::VecLength>,
<DefaultAllocator as Allocator<<D::StateType as State>::VecLength>>::Buffer<f64>: Send,
{
self.resume_run_until_epoch(prop, almanac, 0, end_epoch, num_runs)
}
Expand All @@ -230,11 +220,10 @@ where
where
D: Dynamics<StateType = S>,
E: ErrorCtrl,
DefaultAllocator: Allocator<f64, <D::StateType as State>::Size>
+ Allocator<f64, <D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<usize, <D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<f64, <D::StateType as State>::VecLength>,
<DefaultAllocator as Allocator<f64, <D::StateType as State>::VecLength>>::Buffer: Send,
DefaultAllocator: Allocator<<D::StateType as State>::Size>
+ Allocator<<D::StateType as State>::Size, <D::StateType as State>::Size>
+ Allocator<<D::StateType as State>::VecLength>,
<DefaultAllocator as Allocator<<D::StateType as State>::VecLength>>::Buffer<f64>: Send,
{
// Generate the initial states
let init_states = self.generate_states(skip, num_runs, self.seed);
Expand Down Expand Up @@ -315,10 +304,7 @@ where
impl<S: Interpolatable, Distr: Distribution<DispersedState<S>>> fmt::Display
for MonteCarlo<S, Distr>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<f64, S::VecLength>
+ Allocator<usize, S::Size, S::Size>,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
Expand All @@ -332,10 +318,7 @@ where
impl<S: Interpolatable, Distr: Distribution<DispersedState<S>>> fmt::LowerHex
for MonteCarlo<S, Distr>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<f64, S::VecLength>
+ Allocator<usize, S::Size, S::Size>,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
{
/// Returns a filename friendly name
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
28 changes: 8 additions & 20 deletions src/mc/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ use super::DispersedState;
/// A structure storing the result of a single Monte Carlo run
pub struct Run<S: Interpolatable, R>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<usize, S::Size, S::Size>
+ Allocator<f64, S::VecLength>,
<DefaultAllocator as Allocator<f64, S::VecLength>>::Buffer: Send,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
<DefaultAllocator as Allocator<S::VecLength>>::Buffer<f64>: Send,
{
/// The index of this run
pub index: usize,
Expand All @@ -64,11 +61,8 @@ where
/// A structure of Monte Carlo results
pub struct Results<S: Interpolatable, R>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<usize, S::Size, S::Size>
+ Allocator<f64, S::VecLength>,
<DefaultAllocator as Allocator<f64, S::VecLength>>::Buffer: Send,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
<DefaultAllocator as Allocator<S::VecLength>>::Buffer<f64>: Send,
{
/// Raw data from each run, sorted by run index for O(1) access to each run
pub runs: Vec<Run<S, R>>,
Expand All @@ -79,23 +73,17 @@ where
/// A structure that stores the result of a propagation segment of a Monte Carlo.
pub struct PropResult<S: Interpolatable>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<usize, S::Size, S::Size>
+ Allocator<f64, S::VecLength>,
<DefaultAllocator as Allocator<f64, S::VecLength>>::Buffer: Send,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
<DefaultAllocator as Allocator<S::VecLength>>::Buffer<f64>: Send,
{
pub state: S,
pub traj: Traj<S>,
}

impl<S: Interpolatable> Results<S, PropResult<S>>
where
DefaultAllocator: Allocator<f64, S::Size>
+ Allocator<f64, S::Size, S::Size>
+ Allocator<usize, S::Size, S::Size>
+ Allocator<f64, S::VecLength>,
<DefaultAllocator as Allocator<f64, S::VecLength>>::Buffer: Send,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
<DefaultAllocator as Allocator<S::VecLength>>::Buffer<f64>: Send,
{
/// Returns the value of the requested state parameter for all trajectories from `start` to `end` every `step` and
/// using the value of `value_if_run_failed` if set and skipping that run if the run failed
Expand Down
15 changes: 5 additions & 10 deletions src/md/events/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ pub enum EventEdge {
#[derive(Clone, Debug, PartialEq)]
pub struct EventDetails<S: Interpolatable>
where
DefaultAllocator:
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
DefaultAllocator: Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
/// The state of the trajectory at the found event.
pub state: S,
Expand All @@ -70,8 +69,7 @@ where

impl<S: Interpolatable> EventDetails<S>
where
DefaultAllocator:
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
DefaultAllocator: Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
/// Generates detailed information about an event at a specific epoch in a trajectory.
///
Expand Down Expand Up @@ -148,8 +146,7 @@ where

impl<S: Interpolatable> fmt::Display for EventDetails<S>
where
DefaultAllocator:
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
DefaultAllocator: Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let prev_fmt = match self.prev_value {
Expand All @@ -173,17 +170,15 @@ where
#[derive(Clone, Debug, PartialEq)]
pub struct EventArc<S: Interpolatable>
where
DefaultAllocator:
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
DefaultAllocator: Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
pub rise: EventDetails<S>,
pub fall: EventDetails<S>,
}

impl<S: Interpolatable> fmt::Display for EventArc<S>
where
DefaultAllocator:
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
DefaultAllocator: Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
Expand Down
3 changes: 1 addition & 2 deletions src/md/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ use std::sync::Arc;
/// A trait to specify how a specific event must be evaluated.
pub trait EventEvaluator<S: State>: fmt::Display + Send + Sync
where
DefaultAllocator:
Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size> + Allocator<f64, S::VecLength>,
DefaultAllocator: Allocator<S::Size> + Allocator<S::Size, S::Size> + Allocator<S::VecLength>,
{
// Evaluation of event crossing, must return whether the condition happened between between both states.
fn eval_crossing(
Expand Down
3 changes: 1 addition & 2 deletions src/md/events/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ use std::sync::Arc;

impl<S: Interpolatable> Traj<S>
where
DefaultAllocator:
Allocator<f64, S::VecLength> + Allocator<f64, S::Size> + Allocator<f64, S::Size, S::Size>,
DefaultAllocator: Allocator<S::VecLength> + Allocator<S::Size> + Allocator<S::Size, S::Size>,
{
/// Find the exact state where the request event happens. The event function is expected to be monotone in the provided interval because we find the event using a Brent solver.
#[allow(clippy::identity_op)]
Expand Down
5 changes: 2 additions & 3 deletions src/md/trajectory/interpolatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ use enum_iterator::all;
pub trait Interpolatable: State
where
Self: Sized,
DefaultAllocator: Allocator<f64, Self::Size>
+ Allocator<f64, Self::Size, Self::Size>
+ Allocator<f64, Self::VecLength>,
DefaultAllocator:
Allocator<Self::Size> + Allocator<Self::Size, Self::Size> + Allocator<Self::VecLength>,
{
/// Interpolates a new state at the provided epochs given a slice of states.
fn interpolate(self, epoch: Epoch, states: &[Self]) -> Result<Self, InterpolationError>;
Expand Down
Loading

0 comments on commit a8db2ce

Please sign in to comment.