Parameter
class qiskit.circuit.Parameter
Bases: ParameterExpression
A compile-time symbolic parameter.
The value of a Parameter
must be entirely determined before a circuit begins execution. Typically this will mean that you should supply values for all Parameter
s in a circuit using QuantumCircuit.assign_parameters()
, though certain hardware vendors may allow you to give them a circuit in terms of these parameters, provided you also pass the values separately.
This is the atom of ParameterExpression
, and is itself an expression. The numeric value of a parameter need not be fixed while the circuit is being defined.
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("mpl")
# bind the parameters after circuit to create a bound circuit
bc = qc.assign_parameters({phi: 3.14})
bc.measure_all()
bc.draw("mpl")


Attributes
name
Returns the name of the Parameter
.
parameters
Get the parameters present in the expression.
Qiskit guarantees equality (via ==
) of parameters retrieved from an expression with the original Parameter
objects used to create this expression, but does not guarantee is
comparisons to succeed.
uuid
Returns the UUID
of the Parameter
.
In advanced use cases, this property can be passed to the Parameter
constructor to produce an instance that compares equal to another instance.
Methods
abs
abs()
Take the absolute value of the expression.
arccos
arccos()
Arccosine of the expression.
arcsin
arcsin()
Arcsine of the expression.
arctan
arctan()
Arctangent of the expression.
assign
assign(parameter, value)
Assign one parameter to a value, which can either be numeric or another parameter expression.
Parameters
- 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.
bind
bind(parameter_values, allow_unknown_parameters=False)
Binds the provided set of parameters to their corresponding values.
Parameters
- parameter_values – Mapping of
Parameter
instances to the numeric value to which they will be bound. - allow_unknown_parameters – If
False
, raises an error ifparameter_values
containsParameter
s in the keys outside those present in the expression. IfTrue
, any such parameters are simply ignored.
Raises
-
- If parameter_values contains parameters outside those in self. - If a non-numeric value is passed in
parameter_values
.
- If parameter_values contains parameters outside those in self. - If a non-numeric value is passed in
-
- If binding the provided values requires division by zero.
Returns
A new expression parameterized by any parameters which were not bound by parameter_values
.
bind_all
bind_all(values)
Bind all of the parameters in self
to numeric values in the dictionary, returning a numeric value.
This is a special case of bind()
which can reach higher performance. It is no problem for the values
dictionary to contain parameters that are not used in this expression; the expectation is that the same bindings dictionary will be fed to other expressions as well.
It is an error to call this method with a values
dictionary that does not bind all of the values, or to call this method with non-numeric values, but this is not explicitly checked, since this method is intended for performance-sensitive use. Passing an incorrect dictionary may result in unexpected behavior.
Unlike bind()
, this method will not raise an exception if non-finite floating-point values are encountered.
Parameters
values – mapping of parameters to numeric values.
conjugate
conjugate()
Return the complex conjugate of the expression.
cos
cos()
Cosine of the expression.
exp
exp()
Exponentiate the expression.
gradient
gradient(param)
Return derivative of this expression with respect to the input parameter.
Parameters
param – The parameter with respect to which the derivative is calculated.
Returns
The derivative as either a constant numeric value or a symbolic ParameterExpression
.
is_real
is_real()
Check whether the expression represents a real number.
Note that this will return None
if there are unbound parameters, in which case it cannot be determined whether the expression is real.
is_symbol
is_symbol()
Check if the expression corresponds to a plain symbol.
Returns
True
is this expression corresponds to a symbol, False
otherwise.
log
log()
Take the natural logarithm of the expression.
numeric
numeric(strict=True)
Cast this expression to a numeric value.
Parameters
strict – If True
(default) this function raises an error if there are any unbound symbols in the expression. If False
, this allows casting if the expression represents a numeric value, regardless of unbound symbols. For example (0 * Parameter("x"))
is 0 but has the symbol x
present.
sign
sign()
Return the sign of the expression.
sin
sin()
Sine of the expression.
subs
subs(parameter_map, allow_unknown_parameters=False)
Returns a new expression with replacement parameters.
Parameters
- parameter_map – Mapping from
Parameter
s inself
to theParameterExpression
instances with which they should be replaced. - allow_unknown_parameters – If
False
, raises an error ifparameter_map
containsParameter
s in the keys outside those present in the expression. IfTrue
, any such parameters are simply ignored.
Raises
- 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.
sympify
sympify()
Return a SymPy equivalent of this expression.
Returns
A SymPy equivalent of this expression.
tan
tan()
Tangent of the expression.