Parameter
class Parameter(name)
Bases: 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.
from qiskit.circuit import QuantumCircuit, Parameter
# create the parameter
phi = Parameter('phi')
qc = QuantumCircuit(1)
# parameterize the rotation
qc.rx(phi, 0)
qc.draw()
# bind the parameters after circuit to create a bound circuit
bc = qc.bind_parameters({phi: 3.14})
bc.measure_all()
bc.draw()
┌──────────┐ ░ ┌─┐
q: ┤ Rx(3.14) ├─░─┤M├
└──────────┘ ░ └╥┘
meas: 1/════════════════╩═
0
Create a new named Parameter
.
Parameters
name (str
) – name of the Parameter
, used for visual representation. This can be any unicode string, e.g. “ϕ”.
Methods
arccos
Parameter.arccos()
Arccos of a ParameterExpression
arcsin
Parameter.arcsin()
Arcsin of a ParameterExpression
arctan
Parameter.arctan()
Arctan of a ParameterExpression
assign
Parameter.assign(parameter, value)
Assign one parameter to a value, which can either be numeric or another parameter expression.
Parameters
- parameter (Parameter) – A parameter in this expression whose value will be updated.
- value (
Union
[ParameterExpression
,float
]) – The new value to bind to.
Return type
Returns
A new expression parameterized by any parameters which were not bound by assignment.
bind
Parameter.bind(parameter_values)
Binds the provided set of parameters to their corresponding values.
Parameters
parameter_values (Dict
) – Mapping of Parameter instances to the numeric value to which they will be bound.
Raises
-
CircuitError –
- If parameter_values contains Parameters outside those in self. - If a non-numeric value is passed in parameter_values.
-
ZeroDivisionError –
- If binding the provided values requires division by zero.
Return type
Returns
A new expression parameterized by any parameters which were not bound by parameter_values.
conjugate
cos
Parameter.cos()
Cosine of a ParameterExpression
exp
Parameter.exp()
Exponential of a ParameterExpression
gradient
Parameter.gradient(param)
Get the derivative of a parameter expression w.r.t. a specified parameter expression.
Parameters
param (Parameter) – Parameter w.r.t. which we want to take the derivative
Return type
Union
[ParameterExpression
, complex
]
Returns
ParameterExpression representing the gradient of param_expr w.r.t. param or complex or float number
is_real
Parameter.is_real()
Return whether the expression is real
log
Parameter.log()
Logarithm of a ParameterExpression
sin
Parameter.sin()
Sine of a ParameterExpression
subs
Parameter.subs(parameter_map)
Substitute self with the corresponding parameter in parameter_map
.
sympify
Parameter.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.
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.
tan
Parameter.tan()
Tangent of a ParameterExpression
Attributes
name
Returns the name of the Parameter
.
parameters
Returns a set of the unbound Parameters in the expression.
Return type
Set