ParameterExpressionTable¶
- class samplomatic.samplex.ParameterExpressionTable[source]¶
Bases:
objectEvaluates a list of parameter expressions given a list of parameter values.
An instance of this class owns an ordered list of \(M\)
ParameterExpressions that together implicitly specify an ordered list of distinct \(N\)Parameters. Because parameter expressions can involve multiple parameters, because distinct parameter expressions can reference the same parameters, and because parameter expressions that are completely bound contain no parameters, there is in general no relationship between \(N\) and \(M\). However, \(N=M\) in the common special case that all parameter expressions are just, in fact, unique parameters.The
evaluate()method accepts \(N\) parameter values, and returns numeric values for each of the \(M\) parameter expressions.This class can be used as a shim for tools that want to accept parameter values but use expressions of them without the tedious responsibilities usually attached.
Attributes Summary
The number of parameter expressions to evaluate; the return size of
evaluate().The number of unique input parameters across all expressions.
The unique parameters across all expressions in sorted order.
Methods Summary
append(expression)Add a parameter expression to the table.
evaluate(parameter_values)Return one numeric value for each expression.
Attributes Documentation
- num_expressions¶
The number of parameter expressions to evaluate; the return size of
evaluate().
- num_parameters¶
The number of unique input parameters across all expressions.
- parameters¶
The unique parameters across all expressions in sorted order.
The same sorting order as qiskit is used, where
ParameterVectorelements are arranged numerically, but otherwise alphabetically by name.
Methods Documentation
- append(expression: ParameterExpression) int[source]¶
Add a parameter expression to the table.
- Parameters:
expression – The parameter expression to append.
- Returns:
The index of the appended expression.
- Raises:
ParameterError – If the expression contains a parameter that is not already in this table but whose name conflicts with an existing parameter. Keep in mind that
Parameters use instance equality.
- evaluate(parameter_values: Sequence[float] | dict[Parameter, float]) ndarray[source]¶
Return one numeric value for each expression.
- Parameters:
parameter_values – The parameter values, either as a map from parameters to their values, or just the values in parameter-sorted order (see
parameters).- Returns:
An array of evaluated expressions.
- Raises:
ParameterError – If the correct number of parameters is not supplied, or if some expression requires a value for a parameter that was not provided.