graphix.parameter module¶
Parameter class.
Parameter object acts as a placeholder of measurement angles and allows the manipulation of the measurement pattern without specific value assignment.
- class Expression[source]¶
Bases:
ABCExpression with parameters.
- abstractmethod with_parameter(variable: Parameter, substitute: Expression | SupportsFloat) Expression | complex[source]¶
Substitute a parameter with a value or expression.
- abstractmethod with_parameters(assignment: Mapping[Parameter, ExpressionOrSupportsFloat]) ExpressionOrComplex[source]¶
Perform parallel substitution of multiple parameters.
- subs(variable: Parameter, substitute: Expression | SupportsFloat) Expression | complex[source]¶
Alias for
with_parameter(), following thesympyconvention.
- xreplace(assignment: Mapping[Parameter, ExpressionOrSupportsFloat]) ExpressionOrComplex[source]¶
Alias for
with_parameters(), following thesympyconvention.
- class ExpressionWithTrigonometry[source]¶
Bases:
Expression,ABCExpression that supports trigonometric functions.
- abstractmethod cos() ExpressionWithTrigonometry[source]¶
Return the cosine of the expression.
- abstractmethod sin() ExpressionWithTrigonometry[source]¶
Return the cosine of the expression.
- abstractmethod exp() ExpressionWithTrigonometry[source]¶
Return the exponential of the expression.
- class Parameter[source]¶
Bases:
ExpressionAbstract class for substituable parameter.
- exception PlaceholderOperationError[source]¶
Bases:
ValueErrorError raised when an operation is not supported by the placeholder.
- class AffineExpression(a: float, x: Parameter, b: float)[source]¶
Bases:
ExpressionAffine expression.
An affine expression is of the form a*x+b where a and b are numbers and x is a parameter.
- offset(d: float) AffineExpression[source]¶
Add d to the expression.
- scale_non_null(k: float) AffineExpression[source]¶
Return
selfscaled bykassumingkis non-zero.- Parameters:
k (float) – Scaling factor.
- Returns:
A new expression scaled by
k.- Return type:
- scale(k: float) Expression | float[source]¶
Multiply the expression by
k.
- evaluate(value: Expression | SupportsFloat) Expression | float[source]¶
Evaluate the expression at
value.
- with_parameter(variable: Parameter, substitute: Expression | SupportsFloat) AffineExpression | Expression | complex[source]¶
Look to the documentation in the parent class.
- class Placeholder(name: str)[source]¶
Bases:
AffineExpression,ParameterPlaceholder for measurement angles.
These placeholder may appear in affine expressions. Placeholders and affine expressions may be used as angles in rotation gates of
Circuitclass or for the measurement angle of the measurement commands. Pattern optimizations such that standardization, signal shifting and Pauli preprocessing can be applied to patterns with placeholders.These placeholders and affine expressions do not support arbitrary computation and are not suitable for simulation. You may use
Circuit.subs()orPattern.subs()with an actual value before the computation.
- check_expression_or_complex(value: object) Expression | complex[source]¶
Check that the given object is of type ExpressionOrComplex and return it.
- check_expression_or_float(value: object) Expression | float[source]¶
Check that the given object is of type ExpressionOrFloat and return it.
- with_parameter(value: Expression | float, variable: Parameter, substitute: Expression | SupportsFloat) Expression | float[source]¶
- with_parameter(value: _T, variable: Parameter, substitute: Expression | SupportsFloat) _T | complex
Substitute in
value.If
valueis an instance ofExpression, then returnvalue.with_parameter(variable, substitute)(coerced into a complex or a float if the result is a number).If
valuedoes not implementwith_parameter,valueis returned unchanged.This function is used to apply substitution to collections where some elements are
Expressionand other elements are just plain numbers.
- with_parameters(value: Expression | float, assignment: Mapping[Parameter, ExpressionOrSupportsFloat]) Expression | float[source]¶
- with_parameters(value: _T, assignment: Mapping[Parameter, ExpressionOrSupportsFloat]) _T | Expression | complex
Substitute in parallel in
value.If
valueis an instance ofExpression, then returnvalue.with_parameters(assignment)(coerced into a complex if the result is a number).If
value`does not implementwith_parameters,valueis returned unchanged.This function is used to apply parallel substitutions to collections where some elements are Expression and other elements are just plain numbers.
- cos_sin(angle: Expression | float) tuple[Expression | float, Expression | float][source]¶
Cosine and sine of a float or an expression.
- exp(z: Expression | complex) Expression | complex[source]¶
Exponential of a number or an expression.
- class Parameterizable[source]¶
Bases:
ABCAbstract base class for objects that hold parameters.
This class defines the abstract methods
with_parameter()for single-parameter substitution andwith_parameters()for parallel substitution of multiple parameters.It also exposes
subs()andxreplace()as aliases forwith_parameter()andwith_parameters(), respectively, following thesympyconvention.- abstractmethod with_parameter(variable: Parameter, substitute: ExpressionOrSupportsFloat) Self[source]¶
Substitute a parameter with a value or expression.
- abstractmethod with_parameters(assignment: Mapping[Parameter, ExpressionOrSupportsFloat]) Self[source]¶
Perform parallel substitution of multiple parameters.
- subs(variable: Parameter, substitute: ExpressionOrSupportsFloat) Self[source]¶
Alias for
with_parameter(), following thesympyconvention.
- xreplace(assignment: Mapping[Parameter, ExpressionOrSupportsFloat]) Self[source]¶
Alias for
with_parameters(), following thesympyconvention.
- class InplaceParameterizable[source]¶
Bases:
Parameterizable,ABCAbstract base class for objects that hold parameters and can be modified in place.
This class defines the abstract methods
replace_parameter()for single-parameter substitution andreplace_parameters()for parallel substitution of multiple parameters. By default, these methods modify the object in place, with an optionalcopyparameter. Ifcopy=True, a modified copy is returned instead.The methods
with_parameter()andwith_parameters()are equivalent to callingreplace_parameter()andreplace_parameters(), respectively, withcopy=True.- abstractmethod replace_parameter(variable: Parameter, substitute: ExpressionOrSupportsFloat, *, copy: bool = False) Self[source]¶
Substitute all occurrences of the given variable in measurement angles by the given value.
- Parameters:
variable (Parameter) – The symbolic expression to be replaced within the measurement angles.
substitute (ExpressionOrSupportsFloat) – The value or symbolic expression to substitute in place of
variable.copy (bool, optional) – If
True, the current object remains unchanged and a new object is returned. The default isFalse, meaning that changes are performed in place.
- Returns:
The object with the updated measurement parameters. Equal to
selfifcopyisFalse.- Return type:
Self
- abstractmethod replace_parameters(assignment: Mapping[Parameter, ExpressionOrSupportsFloat], *, copy: bool = False) Self[source]¶
Substitute all occurrences of the given keys in measurement angles by the given values in parallel.
- Parameters:
assignment (Mapping[Parameter, ExpressionOrSupportsFloat]) – A dictionary-like mapping where keys are the
Parameterobjects to be replaced and values are the new expressions or numerical values.copy (bool, optional) – If
True, the current object remains unchanged and a new object is returned. The default isFalse, meaning that changes are performed in place.
- Returns:
The object with the updated measurement parameters. Equal to
selfifcopyisFalse.- Return type:
Self