mm.math.parameter_set.ParameterSet

class mrmustard.math.parameter_set.ParameterSet[source]

Bases: object

A set of parameters.

ParameterSet can store both constant and variable parameters. It provides fast access to both classes of parameters, as well as to their names.

const1 = Constant(1.2345, "const1")
const2 = Constant(2.3456, "const2")
var1 = Variable(3.4567, "var1")

ps = ParameterSet()
ps.add_parameter(const1)
ps.add_parameter(const2)
ps.add_parameter(var1)

ps.names  # returns `["const1", "const2", "var1"]`
ps.constants  # returns `{"const1": const1, "const2": const2}`
ps.variable  # returns `{"var1": var1}`

all_parameters

constants

The constant parameters in this parameter set.

names

The names of all the parameters in this parameter set, in the order in which they were added.

variables

The variable parameters in this parameter set.

all_parameters
constants

The constant parameters in this parameter set.

names

The names of all the parameters in this parameter set, in the order in which they were added.

variables

The variable parameters in this parameter set.

add_parameter(parameter)

Adds a parameter to this parameter set.

tagged_variables(tag)

Returns a dictionary whose keys are tagged names of the variables in this parameter set, and whose values are the variables in this parameter set.

to_string(decimals)

Returns a string representation of the parameter values, separated by commas and rounded to the specified number of decimals.

add_parameter(parameter)[source]

Adds a parameter to this parameter set.

Parameters:

parameter (Union[Constant, Variable]) – A constant or variable parameter.

Raises:

ValueError – If this parameter set already contains a parameter with the same name as that of the given parameter.

Return type:

None

tagged_variables(tag)[source]

Returns a dictionary whose keys are tagged names of the variables in this parameter set, and whose values are the variables in this parameter set. Tagging is done by prepending the string f"{tag}"/ to variables’ original names.

Return type:

dict[str, Variable]

to_string(decimals)[source]

Returns a string representation of the parameter values, separated by commas and rounded to the specified number of decimals.

Parameters:

decimals (int) – number of decimals to round to

Returns:

string representation of the parameter values

Return type:

str