qpandalite.circuit_builder.parameter module#
Symbolic parameters for parametric quantum circuits.
This module provides: - Parameter: Named symbolic parameter for parametric gates - Parameters: Array of named parameters with indexing support
These classes enable symbolic expressions for gate parameters that can be bound to concrete values at execution time.
- Example usage:
theta = Parameter("theta") phi = Parameter("phi")
# Arithmetic operations create symbolic expressions expr = theta + phi / 2
# Bind values and evaluate theta.bind(1.0) phi.bind(2.0) result = expr.evalf() # 2.0
- class qpandalite.circuit_builder.parameter.Parameter(name)[源代码]
基类:
objectNamed symbolic parameter for parametric quantum circuits.
Parameter supports arithmetic operations that create symbolic expressions using sympy. The parameter can be bound to a concrete value or evaluated with a provided values dictionary.
- 参数:
name (str)
- name
Parameter name
- symbol
Underlying sympy Symbol
示例
>>> theta = Parameter("theta") >>> phi = Parameter("phi") >>> expr = theta * 2 + phi >>> # Evaluate with concrete values >>> float(expr.subs({theta.symbol: 1.0, phi.symbol: 0.5})) 2.5
- bind(value)[源代码]
Bind a concrete value to this parameter.
- 参数:
value (float) -- The numeric value to bind
- 返回类型:
None
- evaluate(values=None)[源代码]
Evaluate the parameter.
If the parameter is bound, returns the bound value. Otherwise, looks up the value in the provided dictionary.
- 参数:
values (dict[str, float] | None) -- Optional dictionary mapping parameter names to values
- 返回:
The evaluated numeric value
- 抛出:
ValueError -- If parameter is not bound and not in values dict
- 返回类型:
float
- property is_bound: bool
Check if the parameter has a bound value.
- property name: str
- property symbol: Symbol
- class qpandalite.circuit_builder.parameter.Parameters(name, size)[源代码]
基类:
objectArray of named parameters with indexing support.
Creates multiple Parameter objects with names "{name}_{index}".
- 参数:
name (str)
size (int)
- name
Base name for the parameter array
示例
>>> alphas = Parameters("alpha", size=4) >>> alphas[0] Parameter('alpha_0') >>> alphas.names ['alpha_0', 'alpha_1', 'alpha_2', 'alpha_3'] >>> alphas.bind([0.1, 0.2, 0.3, 0.4]) >>> alphas[0].evaluate() 0.1
- bind(values)[源代码]
Bind values to all parameters.
- 参数:
values (list[float]) -- List of values (must match array size)
- 抛出:
ValueError -- If values length doesn't match array size
- 返回类型:
None
- evaluate(values=None)[源代码]
Evaluate all parameters.
- 参数:
values (list[float] | None) -- Optional list of values to use (must match array size)
- 返回:
List of evaluated values
- 返回类型:
list[float]
- property name: str
- property names: list[str]
Return list of all parameter names.
- property symbols: list[Symbol]
Return list of all sympy symbols.