223 lines
7.6 KiB
Plaintext
223 lines
7.6 KiB
Plaintext
---
|
||
title: Parameter
|
||
description: API reference for qiskit.circuit.Parameter
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.circuit.Parameter
|
||
---
|
||
|
||
# Parameter
|
||
|
||
<Class id="qiskit.circuit.Parameter" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/circuit/parameter.py" signature="qiskit.circuit.Parameter(name, *, uuid=None)" modifiers="class">
|
||
Bases: [`ParameterExpression`](qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")
|
||
|
||
Parameter Class for variable parameters.
|
||
|
||
A parameter is a variable value that is not required to be fixed at circuit definition.
|
||
|
||
**Examples**
|
||
|
||
Construct a variable-rotation X gate using circuit parameters.
|
||
|
||
```python
|
||
from qiskit.circuit import QuantumCircuit, Parameter
|
||
|
||
# create the parameter
|
||
phi = Parameter('phi')
|
||
qc = QuantumCircuit(1)
|
||
|
||
# parameterize the rotation
|
||
qc.rx(phi, 0)
|
||
qc.draw('mpl')
|
||
|
||
# bind the parameters after circuit to create a bound circuit
|
||
bc = qc.assign_parameters({phi: 3.14})
|
||
bc.measure_all()
|
||
bc.draw('mpl')
|
||
```
|
||
|
||

|
||
|
||

|
||
|
||
Create a new named [`Parameter`](#qiskit.circuit.Parameter "qiskit.circuit.Parameter").
|
||
|
||
**Parameters**
|
||
|
||
* **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.12)")) – name of the `Parameter`, used for visual representation. This can be any unicode string, e.g. “ϕ”.
|
||
* **uuid** (*UUID | None*) – For advanced usage only. Override the UUID of this parameter, in order to make it compare equal to some other parameter object. By default, two parameters with the same name do not compare equal to help catch shadowing bugs when two circuits containing the same named parameters are spurious combined. Setting the `uuid` field when creating two parameters to the same thing (along with the same name) allows them to be equal. This is useful during serialization and deserialization.
|
||
|
||
## Attributes
|
||
|
||
### name
|
||
|
||
<Attribute id="qiskit.circuit.Parameter.name">
|
||
Returns the name of the [`Parameter`](#qiskit.circuit.Parameter "qiskit.circuit.Parameter").
|
||
</Attribute>
|
||
|
||
### parameters
|
||
|
||
<Attribute id="qiskit.circuit.Parameter.parameters">
|
||
Returns a set of the unbound Parameters in the expression.
|
||
</Attribute>
|
||
|
||
## Methods
|
||
|
||
### abs
|
||
|
||
<Function id="qiskit.circuit.Parameter.abs" signature="abs()">
|
||
Absolute of a ParameterExpression
|
||
</Function>
|
||
|
||
### arccos
|
||
|
||
<Function id="qiskit.circuit.Parameter.arccos" signature="arccos()">
|
||
Arccos of a ParameterExpression
|
||
</Function>
|
||
|
||
### arcsin
|
||
|
||
<Function id="qiskit.circuit.Parameter.arcsin" signature="arcsin()">
|
||
Arcsin of a ParameterExpression
|
||
</Function>
|
||
|
||
### arctan
|
||
|
||
<Function id="qiskit.circuit.Parameter.arctan" signature="arctan()">
|
||
Arctan of a ParameterExpression
|
||
</Function>
|
||
|
||
### assign
|
||
|
||
<Function id="qiskit.circuit.Parameter.assign" 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** – The new value to bind to.
|
||
|
||
**Returns**
|
||
|
||
A new expression parameterized by any parameters which were not bound by assignment.
|
||
</Function>
|
||
|
||
### bind
|
||
|
||
<Function id="qiskit.circuit.Parameter.bind" 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.12)")) – 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.12)")) – 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.12)") –
|
||
|
||
* 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.Parameter.conjugate" signature="conjugate()">
|
||
Return the conjugate.
|
||
|
||
**Return type**
|
||
|
||
[*ParameterExpression*](qiskit.circuit.ParameterExpression "qiskit.circuit.parameterexpression.ParameterExpression")
|
||
</Function>
|
||
|
||
### cos
|
||
|
||
<Function id="qiskit.circuit.Parameter.cos" signature="cos()">
|
||
Cosine of a ParameterExpression
|
||
</Function>
|
||
|
||
### exp
|
||
|
||
<Function id="qiskit.circuit.Parameter.exp" signature="exp()">
|
||
Exponential of a ParameterExpression
|
||
</Function>
|
||
|
||
### gradient
|
||
|
||
<Function id="qiskit.circuit.Parameter.gradient" 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.12)")
|
||
</Function>
|
||
|
||
### is\_real
|
||
|
||
<Function id="qiskit.circuit.Parameter.is_real" signature="is_real()">
|
||
Return whether the expression is real
|
||
</Function>
|
||
|
||
### log
|
||
|
||
<Function id="qiskit.circuit.Parameter.log" signature="log()">
|
||
Logarithm of a ParameterExpression
|
||
</Function>
|
||
|
||
### sign
|
||
|
||
<Function id="qiskit.circuit.Parameter.sign" signature="sign()">
|
||
Sign of a ParameterExpression
|
||
</Function>
|
||
|
||
### sin
|
||
|
||
<Function id="qiskit.circuit.Parameter.sin" signature="sin()">
|
||
Sine of a ParameterExpression
|
||
</Function>
|
||
|
||
### subs
|
||
|
||
<Function id="qiskit.circuit.Parameter.subs" signature="subs(parameter_map, allow_unknown_parameters=False)">
|
||
Substitute self with the corresponding parameter in `parameter_map`.
|
||
</Function>
|
||
|
||
### sympify
|
||
|
||
<Function id="qiskit.circuit.Parameter.sympify" 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.Parameter.tan" signature="tan()">
|
||
Tangent of a ParameterExpression
|
||
</Function>
|
||
</Class>
|
||
|