Skip to main contentIBM Quantum Documentation
This page is from the dev version of Qiskit SDK. Go to the stable version

Parameter

class qiskit.circuit.Parameter(name, *, uuid=None)

GitHub

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 Parameters 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')
../_images/qiskit-circuit-Parameter-1_00.png../_images/qiskit-circuit-Parameter-1_01.png

Parameters

  • name (str) – 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

Returns the name of the Parameter.

parameters

Returns a set of the unbound Parameters in the expression.

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()

GitHub

Absolute of a ParameterExpression

arccos

arccos()

GitHub

Arccos of a ParameterExpression

arcsin

arcsin()

GitHub

Arcsin of a ParameterExpression

arctan

arctan()

GitHub

Arctan of a ParameterExpression

assign

assign(parameter, value)

GitHub

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 – 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)

GitHub

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.
  • allow_unknown_parameters (bool) – 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

    • 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.

Returns

A new expression parameterized by any parameters which were not bound by parameter_values.

Return type

ParameterExpression

conjugate

conjugate()

GitHub

Return the conjugate.

Return type

ParameterExpression

cos

cos()

GitHub

Cosine of a ParameterExpression

exp

exp()

GitHub

Exponential of a ParameterExpression

gradient

gradient(param)

GitHub

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

Returns

ParameterExpression representing the gradient of param_expr w.r.t. param or complex or float number

Return type

ParameterExpression | complex

is_real

is_real()

GitHub

Return whether the expression is real

log

log()

GitHub

Logarithm of a ParameterExpression

numeric

numeric()

GitHub

Return a Python number representing this object, using the most restrictive of int, float and complex that is valid for this object.

In general, an int 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 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 could represent every intermediate value exactly), you can use float.is_integer() to check if the return float represents an integer and cast it using int if so. This would be an unusual pattern; typically one requires this by only ever using explicitly Rational objects while working with symbolic expressions.

This is more reliable and performant than using is_real() followed by calling float or complex, as in some cases 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 – if there are unbound parameters.

Return type

int | float | complex

sign

sign()

GitHub

Sign of a ParameterExpression

sin

sin()

GitHub

Sine of a ParameterExpression

subs

subs(parameter_map, allow_unknown_parameters=False)

GitHub

Substitute self with the corresponding parameter in parameter_map.

sympify

sympify()

GitHub

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.

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.

tan

tan()

GitHub

Tangent of a ParameterExpression

Was this page helpful?
Report a bug or request content on GitHub.