Skip to main contentIBM Quantum Documentation

ParameterExpression

qiskit.circuit.ParameterExpression(symbol_map, expr)GitHub(opens in a new tab)

Bases: object(opens in a new tab)

ParameterExpression class to enable creating expressions of Parameters.

Create a new ParameterExpression.

Not intended to be called directly, but to be instantiated via operations on other Parameter or ParameterExpression objects.

Parameters


Attributes

parameters

Returns a set of the unbound Parameters in the expression.


Methods

abs

abs()

Absolute of a ParameterExpression

arccos

arccos()

Arccos of a ParameterExpression

arcsin

arcsin()

Arcsin of a ParameterExpression

arctan

arctan()

Arctan of a ParameterExpression

assign

assign(parameter, value)

Assign one parameter to a value, which can either be numeric or another parameter expression.

Parameters

Returns

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

Return type

ParameterExpression

bind

bind(parameter_values, allow_unknown_parameters=False)

Binds the provided set of parameters to their corresponding values.

Parameters

  • parameter_values (dict(opens in a new tab)) – Mapping of Parameter instances to the numeric value to which they will be bound.
  • allow_unknown_parameters (bool(opens in a new tab)) – 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

Returns

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

Return type

ParameterExpression

conjugate

conjugate()

Return the conjugate.

Return type

ParameterExpression

cos

cos()

Cosine of a ParameterExpression

exp

exp()

Exponential of a ParameterExpression

gradient

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

Returns

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

Return type

ParameterExpression | complex(opens in a new tab)

is_real

is_real()

Return whether the expression is real

log

log()

Logarithm of a ParameterExpression

numeric

numeric()

Return a Python number representing this object, using the most restrictive of int(opens in a new tab), float(opens in a new tab) and complex(opens in a new tab) that is valid for this object.

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

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

Return type

int(opens in a new tab) | float(opens in a new tab) | complex(opens in a new tab)

sign

sign()

Sign of a ParameterExpression

sin

sin()

Sine of a ParameterExpression

subs

subs(parameter_map, allow_unknown_parameters=False)

Returns a new Expression with replacement Parameters.

Parameters

  • parameter_map (dict(opens in a new tab)) – Mapping from Parameters in self to the ParameterExpression instances with which they should be replaced.
  • allow_unknown_parameters (bool(opens in a new tab)) – 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

  • 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

sympify

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.

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

Tangent of a ParameterExpression

Was this page helpful?