s_matrix¶
- photonforge.monte_carlo.s_matrix(component, frequencies, *variables, show_progress=True, random_samples=0, corner_samples=0, corner_coverage=0.95, random_seed=None, chain_technology_updates=True, chain_component_updates=True, component_args=(), component_kwargs={}, model_kwargs={}, callback_fn=None)¶
Compute variations of a component’s S matrix.
Technologies are updated before components and sub-components are updated before parents. Models are updated after components.
- Parameters:
component – Main component or function that returns a component.
frequencies – Frequencies to use of the S matrix computation.
*variables – Random variables to include in the computation. More info below. If no variables are defined, all random variables present in the main component, its active model, and technology are used.
show_progress – If
True
, show overall computation progress.random_samples – Number of random samples to evaluate.
corner_samples – Number of corner cases to evaluate (randomly sampled). If negative or larger than the total number of corner cases, all cases are tested once.
corner_coverage – For variables with normal distribution, the lower and upper bounds are defined such that this value is the probability that a random sample is within those bounds. For example, a 0.95 probability sets the bounds at approximately 2 standard deviations from the mean.
random_seed – If set, value used as the random generator seed.
chain_technology_updates – If set, a technology update will trigger an update for all components using that technology.
chain_component_updates – If set, a component update will trigger an update for all components referencing it.
component_args – Tuple of positional arguments for the component function or parametric component update.
component_kwargs – Dictionary of keyword arguments for the component function or parametric component update.
model_kwargs – Dictionary of keyword arguments used in the call to
Component.s_matrix()
.callback_fn – Function called before the S matrix computation for each variation, after the component has been updated. The function must receive 2 arguments: component (the current variation) and a tuple with all random variables in their current state.
- Returns:
Tuple with list of variables (in update order) and list of results.
Arguments
variables
can be:RandomVariable
instance.(parameter_name, object)
: Look for the random variable namedparameter_name
withinobject
, which can be aphotonforge.Component
,photonforge.Model
, orphotonforge.Technology
instance, or one of"component"
,"model"
, or"technology"
. The strings are used to indicate the main component, its model, and its technology, respectively, which can be useful when the argumentcomponent
is a function.(parameter_name, object, random_variable_kwargs)
: Create a new random variable namedparameter_name
for the specifiedobject
usingrandom_variable_kwargs
.(ref_spec, updates)
: Addphotonforge.Reference.update()
keyword arguments for the specified reference. Dictionaryupdates
can contain the following keys:{ "technology_updates": [tech_var1, tech_var2, ...], "component_updates": [comp_var1, comp_var2, ...], "model_updates": [model_var1, model_var2, ...], }
and each value is a list of random variables for the specified reference’s component, its technology, or its active model. The reference specification
ref_spec
follows the same format as the keys inphotonforge.CircuitModel.start()
, which is used for evaluation of the updates.
Important
Variables for references will only be used if the specified reference is computed by a
photonforge.CircuitModel
, that is, all components in the tree leading to that reference have an active Circuit model for their S parameter computation.Examples
>>> var1 = monte_carlo.RandomVariable( ... "var1", sub_component, values=[1, 2, 3] ... ) >>> var4 = monte_carlo.RandomVariable("length", value=1, stdev=0.1) >>> monte_carlo.s_matrix( ... component, ... frequencies, ... var1, ... ("var2", "component"), ... ("var3", "model", {"value": 0.5, "stdev": 0.01}), ... ((None, "DELAY"), {"model_updates": [var4]}), ... random_samples=12, ... )
In this case, we use
var1
as defined, look for a random variable named “var2” in the main component, create a new random variable named “var3” with normal distribution applied to the main component’s active model, and usevar4
in the model of any component named “DELAY” among the dependencies ofcomponent
.Note
After the computations, all parametric components and models are updated with their original keyword values.
See also