qiskit-documentation/docs/api/qiskit/1.2/qiskit.circuit.ParameterExp...

237 lines
13 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: ParameterExpression (v1.2)
description: API reference for qiskit.circuit.ParameterExpression in qiskit v1.2
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.circuit.ParameterExpression
---
# ParameterExpression
<Class id="qiskit.circuit.ParameterExpression" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L33-L554" signature="qiskit.circuit.ParameterExpression(symbol_map, expr)" modifiers="class">
Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)")
ParameterExpression class to enable creating expressions of Parameters.
Create a new [`ParameterExpression`](#qiskit.circuit.ParameterExpression "qiskit.circuit.ParameterExpression").
Not intended to be called directly, but to be instantiated via operations on other [`Parameter`](qiskit.circuit.Parameter "qiskit.circuit.Parameter") or [`ParameterExpression`](#qiskit.circuit.ParameterExpression "qiskit.circuit.ParameterExpression") objects.
**Parameters**
* **symbol\_map** (*Dict\[*[*Parameter*](qiskit.circuit.Parameter "qiskit.circuit.Parameter")*, \[*[*ParameterExpression*](#qiskit.circuit.ParameterExpression "qiskit.circuit.ParameterExpression")*,* [*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")*, or* [*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")*]]*) Mapping of [`Parameter`](qiskit.circuit.Parameter "qiskit.circuit.Parameter") instances to the `sympy.Symbol` serving as their placeholder in expr.
* **expr** (*sympy.Expr*) Expression of `sympy.Symbol` s.
## Attributes
### parameters
<Attribute id="qiskit.circuit.ParameterExpression.parameters">
Returns a set of the unbound Parameters in the expression.
</Attribute>
## Methods
### abs
<Function id="qiskit.circuit.ParameterExpression.abs" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L460-L462" signature="abs()">
Absolute of a ParameterExpression
</Function>
### arccos
<Function id="qiskit.circuit.ParameterExpression.arccos" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L372-L374" signature="arccos()">
Arccos of a ParameterExpression
</Function>
### arcsin
<Function id="qiskit.circuit.ParameterExpression.arcsin" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L368-L370" signature="arcsin()">
Arcsin of a ParameterExpression
</Function>
### arctan
<Function id="qiskit.circuit.ParameterExpression.arctan" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L376-L378" signature="arctan()">
Arctan of a ParameterExpression
</Function>
### assign
<Function id="qiskit.circuit.ParameterExpression.assign" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L77-L91" signature="assign(parameter, value)">
Assign one parameter to a value, which can either be numeric or another parameter expression.
**Parameters**
* **parameter** ([*Parameter*](qiskit.circuit.Parameter "qiskit.circuit.Parameter")) A parameter in this expression whose value will be updated.
* **value** ([*ParameterExpression*](#qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression") *|*[*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")) The new value to bind to.
**Returns**
A new expression parameterized by any parameters which were not bound by assignment.
**Return type**
[*ParameterExpression*](#qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")
</Function>
### bind
<Function id="qiskit.circuit.ParameterExpression.bind" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L93-L146" signature="bind(parameter_values, allow_unknown_parameters=False)">
Binds the provided set of parameters to their corresponding values.
**Parameters**
* **parameter\_values** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")) Mapping of Parameter instances to the numeric value to which they will be bound.
* **allow\_unknown\_parameters** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) If `False`, raises an error if `parameter_values` contains Parameters in the keys outside those present in the expression. If `True`, any such parameters are simply ignored.
**Raises**
* [**CircuitError**](circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError")
* If parameter\_values contains Parameters outside those in self. - If a non-numeric value is passed in parameter\_values.
* [**ZeroDivisionError**](https://docs.python.org/3/library/exceptions.html#ZeroDivisionError "(in Python v3.13)")
* If binding the provided values requires division by zero.
**Returns**
A new expression parameterized by any parameters which were not bound by parameter\_values.
**Return type**
[*ParameterExpression*](#qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")
</Function>
### conjugate
<Function id="qiskit.circuit.ParameterExpression.conjugate" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L70-L75" signature="conjugate()">
Return the conjugate.
**Return type**
[*ParameterExpression*](#qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")
</Function>
### cos
<Function id="qiskit.circuit.ParameterExpression.cos" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L360-L362" signature="cos()">
Cosine of a ParameterExpression
</Function>
### exp
<Function id="qiskit.circuit.ParameterExpression.exp" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L380-L382" signature="exp()">
Exponential of a ParameterExpression
</Function>
### gradient
<Function id="qiskit.circuit.ParameterExpression.gradient" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L279-L313" signature="gradient(param)">
Get the derivative of a parameter expression w\.r.t. a specified parameter expression.
**Parameters**
**param** ([*Parameter*](qiskit.circuit.Parameter "qiskit.circuit.Parameter")) Parameter w\.r.t. which we want to take the derivative
**Returns**
ParameterExpression representing the gradient of param\_expr w\.r.t. param or complex or float number
**Return type**
[*ParameterExpression*](#qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression") | [complex](https://docs.python.org/3/library/functions.html#complex "(in Python v3.13)")
</Function>
### is\_real
<Function id="qiskit.circuit.ParameterExpression.is_real" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L483-L494" signature="is_real()">
Return whether the expression is real
</Function>
### log
<Function id="qiskit.circuit.ParameterExpression.log" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L384-L386" signature="log()">
Logarithm of a ParameterExpression
</Function>
### numeric
<Function id="qiskit.circuit.ParameterExpression.numeric" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L496-L540" signature="numeric()">
Return a Python number representing this object, using the most restrictive of [`int`](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)"), [`float`](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") and [`complex`](https://docs.python.org/3/library/functions.html#complex "(in Python v3.13)") that is valid for this object.
In general, an [`int`](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") is only returned if the expression only involved symbolic integers. If floating-point values were used during the evaluation, the return value will be a [`float`](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") regardless of whether the represented value is an integer. This is because floating-point values “infect” symbolic computations by their inexact nature, and symbolic libraries will use inexact floating-point semantics not exact real-number semantics when they are involved. If you want to assert that all floating-point calculations *were* carried out at infinite precision (i.e. [`float`](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") could represent every intermediate value exactly), you can use [`float.is_integer()`](https://docs.python.org/3/library/stdtypes.html#float.is_integer "(in Python v3.13)") to check if the return float represents an integer and cast it using [`int`](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") if so. This would be an unusual pattern; typically one requires this by only ever using explicitly [`Rational`](https://docs.python.org/3/library/numbers.html#numbers.Rational "(in Python v3.13)") objects while working with symbolic expressions.
This is more reliable and performant than using [`is_real()`](#qiskit.circuit.ParameterExpression.is_real "qiskit.circuit.ParameterExpression.is_real") followed by calling [`float`](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") or [`complex`](https://docs.python.org/3/library/functions.html#complex "(in Python v3.13)"), as in some cases [`is_real()`](#qiskit.circuit.ParameterExpression.is_real "qiskit.circuit.ParameterExpression.is_real") needs to force a floating-point evaluation to determine an accurate result to work around bugs in the upstream symbolic libraries.
**Returns**
A Python number representing the object.
**Raises**
[**TypeError**](https://docs.python.org/3/library/exceptions.html#TypeError "(in Python v3.13)") if there are unbound parameters.
**Return type**
[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") | [float](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)") | [complex](https://docs.python.org/3/library/functions.html#complex "(in Python v3.13)")
</Function>
### sign
<Function id="qiskit.circuit.ParameterExpression.sign" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L388-L390" signature="sign()">
Sign of a ParameterExpression
</Function>
### sin
<Function id="qiskit.circuit.ParameterExpression.sin" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L356-L358" signature="sin()">
Sine of a ParameterExpression
</Function>
### subs
<Function id="qiskit.circuit.ParameterExpression.subs" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L148-L196" signature="subs(parameter_map, allow_unknown_parameters=False)">
Returns a new Expression with replacement Parameters.
**Parameters**
* **parameter\_map** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict "(in Python v3.13)")) Mapping from Parameters in self to the ParameterExpression instances with which they should be replaced.
* **allow\_unknown\_parameters** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) If `False`, raises an error if `parameter_map` contains Parameters in the keys outside those present in the expression. If `True`, any such parameters are simply ignored.
**Raises**
[**CircuitError**](circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError")
* If parameter\_map contains Parameters outside those in self. - If the replacement Parameters in parameter\_map would result in a name conflict in the generated expression.
**Returns**
A new expression with the specified parameters replaced.
**Return type**
[*ParameterExpression*](#qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")
</Function>
### sympify
<Function id="qiskit.circuit.ParameterExpression.sympify" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L542-L554" signature="sympify()">
Return symbolic expression as a raw Sympy or Symengine object.
Symengine is used preferentially; if both are available, the result will always be a `symengine` object. Symengine is a separate library but has integration with Sympy.
<Admonition title="Note" type="note">
This is for interoperability only. Qiskit will not accept or work with raw Sympy or Symegine expressions in its parameters, because they do not contain the tracking information used in circuit-parameter binding and assignment.
</Admonition>
</Function>
### tan
<Function id="qiskit.circuit.ParameterExpression.tan" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/parameterexpression.py#L364-L366" signature="tan()">
Tangent of a ParameterExpression
</Function>
</Class>