pub struct Model<F: Field> {
pub cohsums: Vec<NormSqr<F>>,
pub amplitudes: Arc<RwLock<Vec<Amplitude<F>>>>,
pub parameters: Vec<Parameter<F>>,
pub contains_python_amplitudes: bool,
}
Expand description
A model contains an API to interact with a group of coherent sums by managing their amplitudes
and parameters. Models are typically passed to Manager
-like
struct.
Fields§
§cohsums: Vec<NormSqr<F>>
The set of coherent sums included in the Model
.
amplitudes: Arc<RwLock<Vec<Amplitude<F>>>>
The unique amplitudes located within all coherent sums.
parameters: Vec<Parameter<F>>
The unique parameters located within all coherent sums.
contains_python_amplitudes: bool
Flag which is True
iff at least one Amplitude
is written in Python and has a Node
for which Node::is_python_node
returns True
.
Implementations§
Source§impl<F: Field> Model<F>
impl<F: Field> Model<F>
Sourcepub fn new(amps: &[Box<dyn AmpLike<F>>]) -> Self
pub fn new(amps: &[Box<dyn AmpLike<F>>]) -> Self
Creates a new Model
from a list of Box<AmpLike>
s.
Sourcepub fn deep_clone(&self) -> Self
pub fn deep_clone(&self) -> Self
Creates a true clone (deep copy) of the Model
where the amplitudes
field is
duplicated rather than having its reference count increased.
Sourcepub fn compute(
&self,
amplitudes: &[Amplitude<F>],
parameters: &[F],
event: &Event<F>,
) -> Result<F, RustitudeError>
pub fn compute( &self, amplitudes: &[Amplitude<F>], parameters: &[F], event: &Event<F>, ) -> Result<F, RustitudeError>
Computes the result of evaluating the terms in the model with the given Parameter
s for
the given Event
by summing the result of NormSqr::compute
for each NormSqr
contained in the Model
(see the cohsum
field of Model
).
§Errors
This method yields a RustitudeError
if any of the Amplitude::calculate
steps fail.
Sourcepub fn load(&mut self, dataset: &Dataset<F>) -> Result<(), RustitudeError>
pub fn load(&mut self, dataset: &Dataset<F>) -> Result<(), RustitudeError>
Registers the Model
with the Dataset
by Amplitude::register
ing each
Amplitude
and setting the proper cache position and parameter starting index.
§Errors
This method will yield a RustitudeError
if any Amplitude::precalculate
steps fail.
Sourcepub fn get_amplitude(
&self,
amplitude_name: &str,
) -> Result<Amplitude<F>, RustitudeError>
pub fn get_amplitude( &self, amplitude_name: &str, ) -> Result<Amplitude<F>, RustitudeError>
Retrieves a copy of an Amplitude
in the Model
by name.
§Errors
This will throw a RustitudeError
if the amplitude name is not located within the model.
Sourcepub fn get_parameter(
&self,
amplitude_name: &str,
parameter_name: &str,
) -> Result<Parameter<F>, RustitudeError>
pub fn get_parameter( &self, amplitude_name: &str, parameter_name: &str, ) -> Result<Parameter<F>, RustitudeError>
Retrieves a copy of a Parameter
in the Model
by name.
§Errors
This will throw a RustitudeError
if the parameter name is not located within the model
or if the amplitude name is not located within the model (this is checked first).
Sourcepub fn print_parameters(&self)
pub fn print_parameters(&self)
Pretty-prints all parameters in the model
Sourcepub fn free_parameters(&self) -> Vec<Parameter<F>>
pub fn free_parameters(&self) -> Vec<Parameter<F>>
Returns a Vec<Parameter<F>>
containing the free parameters in the Model
.
Sourcepub fn fixed_parameters(&self) -> Vec<Parameter<F>>
pub fn fixed_parameters(&self) -> Vec<Parameter<F>>
Returns a Vec<Parameter<F>>
containing the fixed parameters in the Model
.
Sourcepub fn constrain(
&mut self,
amplitude_1: &str,
parameter_1: &str,
amplitude_2: &str,
parameter_2: &str,
) -> Result<(), RustitudeError>
pub fn constrain( &mut self, amplitude_1: &str, parameter_1: &str, amplitude_2: &str, parameter_2: &str, ) -> Result<(), RustitudeError>
Constrains two Parameter
s in the Model
to be equal to each other when evaluated.
§Errors
This method will yield a RustitudeError
if either of the parameters is not found by
name.
Sourcepub fn fix(
&mut self,
amplitude: &str,
parameter: &str,
value: F,
) -> Result<(), RustitudeError>
pub fn fix( &mut self, amplitude: &str, parameter: &str, value: F, ) -> Result<(), RustitudeError>
Fixes a Parameter
in the Model
to a given value.
This method technically sets the Parameter
to be fixed and gives it an initial value of
the given value. This method also handles groups of constrained parameters.
§Errors
This method yields a RustitudeError
if the parameter is not found by name.
Sourcepub fn free(
&mut self,
amplitude: &str,
parameter: &str,
) -> Result<(), RustitudeError>
pub fn free( &mut self, amplitude: &str, parameter: &str, ) -> Result<(), RustitudeError>
Frees a Parameter
in the Model
.
This method does not modify the initial value of the parameter. This method also handles groups of constrained parameters.
§Errors
This method yields a RustitudeError
if the parameter is not found by name.
Sourcepub fn set_bounds(
&mut self,
amplitude: &str,
parameter: &str,
bounds: (F, F),
) -> Result<(), RustitudeError>
pub fn set_bounds( &mut self, amplitude: &str, parameter: &str, bounds: (F, F), ) -> Result<(), RustitudeError>
Sets the bounds on a Parameter
in the Model
.
§Errors
This method yields a RustitudeError
if the parameter is not found by name.
Sourcepub fn set_initial(
&mut self,
amplitude: &str,
parameter: &str,
initial: F,
) -> Result<(), RustitudeError>
pub fn set_initial( &mut self, amplitude: &str, parameter: &str, initial: F, ) -> Result<(), RustitudeError>
Sets the initial value of a Parameter
in the Model
.
§Errors
This method yields a RustitudeError
if the parameter is not found by name.
Sourcepub fn get_bounds(&self) -> Vec<(F, F)>
pub fn get_bounds(&self) -> Vec<(F, F)>
Sourcepub fn get_initial(&self) -> Vec<F>
pub fn get_initial(&self) -> Vec<F>
Sourcepub fn get_n_free(&self) -> usize
pub fn get_n_free(&self) -> usize
Sourcepub fn activate(&mut self, amplitude: &str) -> Result<(), RustitudeError>
pub fn activate(&mut self, amplitude: &str) -> Result<(), RustitudeError>
Activates an Amplitude
in the Model
by name.
§Errors
This function will return a RustitudeError::AmplitudeNotFoundError
if the given
amplitude is not present in the Model
.
Sourcepub fn activate_all(&mut self)
pub fn activate_all(&mut self)
Sourcepub fn isolate(&mut self, amplitudes: Vec<&str>) -> Result<(), RustitudeError>
pub fn isolate(&mut self, amplitudes: Vec<&str>) -> Result<(), RustitudeError>
Activate only the specified Amplitude
s while deactivating the rest.
§Errors
This function will return a RustitudeError::AmplitudeNotFoundError
if a given
amplitude is not present in the Model
.
Sourcepub fn deactivate(&mut self, amplitude: &str) -> Result<(), RustitudeError>
pub fn deactivate(&mut self, amplitude: &str) -> Result<(), RustitudeError>
Deactivates an Amplitude
in the Model
by name.
§Errors
This function will return a RustitudeError::AmplitudeNotFoundError
if the given
amplitude is not present in the Model
.
Sourcepub fn deactivate_all(&mut self)
pub fn deactivate_all(&mut self)
Trait Implementations§
Source§impl<F: Field> AsTree for Model<F>
impl<F: Field> AsTree for Model<F>
Source§fn _get_tree(&self, bits: &mut Vec<bool>) -> String
fn _get_tree(&self, bits: &mut Vec<bool>) -> String
AsTree
-implementor starting with a particular indentation structure
defined by bits
. A true
bit will print a vertical line, while a false
bit
will not.Source§fn get_tree(&self) -> String
fn get_tree(&self) -> String
Source§fn _get_indent(&self, bits: Vec<bool>) -> String
fn _get_indent(&self, bits: Vec<bool>) -> String
AsTree::get_tree
. A true
bit will yield a vertical line, while a
false
bit will not.Source§fn _get_intermediate(&self) -> String
fn _get_intermediate(&self) -> String
AsTree::get_tree
.Source§fn _get_end(&self) -> String
fn _get_end(&self) -> String
AsTree::get_tree
.Auto Trait Implementations§
impl<F> Freeze for Model<F>
impl<F> !RefUnwindSafe for Model<F>
impl<F> Send for Model<F>
impl<F> Sync for Model<F>
impl<F> Unpin for Model<F>where
F: Unpin,
impl<F> !UnwindSafe for Model<F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.