ParameterExpressionTable
class samplomatic.samplex.ParameterExpressionTable
Bases: object
Evaluates a list of parameter expressions given a list of parameter values.
An instance of this class owns an ordered list of ParameterExpressions that together implicitly specify an ordered list of distinct 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 and . However, in the common special case that all parameter expressions are just, in fact, unique parameters.
The evaluate() method accepts parameter values, and returns numeric values for each of the 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
Column 1 | Column 2 |
|---|---|
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. |
Methods Summary
Column 1 | Column 2 |
|---|---|
append(expression) | Add a parameter expression to the table. |
evaluate(parameter_values[, indices]) | Return numeric values for the table's expressions. |
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 ParameterVector elements are arranged numerically, but otherwise alphabetically by name.
Methods Documentation
append
append(expression: ParameterExpression) → int
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
evaluate(parameter_values: Sequence[float] | dict[Parameter, float], indices: Sequence[int] | None = None) → ndarray
Return numeric values for the table’s expressions.
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). - indices – An optional sequence of expression indices to evaluate. When
None, all expressions are evaluated in order. When provided, only the expressions at the given indices are evaluated, in the given order, solen(returned_array) == len(indices).
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.