qiskit.circuit.QuantumCircuit.assign_parameters¶
- QuantumCircuit.assign_parameters(parameters: Union[Mapping[Parameter, Union[ParameterExpression, float]], Sequence[Union[ParameterExpression, float]]], inplace: Literal[False] = False) QuantumCircuit [ソース]¶
- QuantumCircuit.assign_parameters(parameters: Union[Mapping[Parameter, Union[ParameterExpression, float]], Sequence[Union[ParameterExpression, float]]], inplace: Literal[True] = False) None
Assign parameters to new parameters or values.
If
parameters
is passed as a dictionary, the keys must beParameter
instances in the current circuit. The values of the dictionary can either be numeric values or new parameter objects.If
parameters
is passed as a list or array, the elements are assigned to the current parameters in the order ofparameters
which is sorted alphabetically (while respecting the ordering inParameterVector
objects).The values can be assigned to the current circuit object or to a copy of it.
- パラメータ
parameters – Either a dictionary or iterable specifying the new parameter values.
inplace – If False, a copy of the circuit with the bound parameters is returned. If True the circuit instance itself is modified.
- 例外
CircuitError – If parameters is a dict and contains parameters not present in the circuit.
ValueError – If parameters is a list/array and the length mismatches the number of free parameters in the circuit.
- 戻り値
A copy of the circuit with bound parameters, if
inplace
is False, otherwise None.
サンプル
Create a parameterized circuit and assign the parameters in-place.
from qiskit.circuit import QuantumCircuit, Parameter circuit = QuantumCircuit(2) params = [Parameter('A'), Parameter('B'), Parameter('C')] circuit.ry(params[0], 0) circuit.crx(params[1], 0, 1) circuit.draw('mpl') circuit.assign_parameters({params[0]: params[2]}, inplace=True) circuit.draw('mpl')
Bind the values out-of-place by list and get a copy of the original circuit.
from qiskit.circuit import QuantumCircuit, ParameterVector circuit = QuantumCircuit(2) params = ParameterVector('P', 2) circuit.ry(params[0], 0) circuit.crx(params[1], 0, 1) bound_circuit = circuit.assign_parameters([1, 2]) bound_circuit.draw('mpl') circuit.draw('mpl')