Korean
언어
English
Bengali
French
German
Japanese
Korean
Portuguese
Spanish
Tamil

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 be Parameter 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 of parameters which is sorted alphabetically (while respecting the ordering in ParameterVector 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')

(Source code)

../_images/qiskit-circuit-QuantumCircuit-assign_parameters-1_00.png
../_images/qiskit-circuit-QuantumCircuit-assign_parameters-1_01.png

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

(Source code)

../_images/qiskit-circuit-QuantumCircuit-assign_parameters-2_00.png
../_images/qiskit-circuit-QuantumCircuit-assign_parameters-2_01.png