XOR.assign_parameters¶
- XOR.assign_parameters(param_dict, inplace=False)¶
Assign parameters to new parameters or values.
The keys of the parameter dictionary must be Parameter instances in the current circuit. The values of the dictionary can either be numeric values or new parameter objects. The values can be assigned to the current circuit object or to a copy of it.
- Parameters
param_dict (dict) – A dictionary specifying the mapping from
current_parameter
tonew_parameter
, wherenew_parameter
can be a new parameter object or a numeric value.inplace (bool) – If False, a copy of the circuit with the bound parameters is returned. If True the circuit instance itself is modified.
- Raises
CircuitError – If param_dict contains parameters not present in the circuit
- Returns
- A copy of the circuit with bound parameters, if
inplace
is True, otherwise None.
- Return type
optional(QuantumCircuit)
Examples
>>> 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() ┌───────┐ q_0: |0>┤ Ry(A) ├────■──── └───────┘┌───┴───┐ q_1: |0>─────────┤ Rx(B) ├ └───────┘ >>> circuit.assign_parameters({params[0]: params[2]}, inplace=True) >>> circuit.draw() ┌───────┐ q_0: |0>┤ Ry(C) ├────■──── └───────┘┌───┴───┐ q_1: |0>─────────┤ Rx(B) ├ └───────┘ >>> bound_circuit = circuit.assign_parameters({params[1]: 1, params[2]: 2}) >>> bound_circuit.draw() ┌───────┐ q_0: |0>┤ Ry(2) ├────■──── └───────┘┌───┴───┐ q_1: |0>─────────┤ Rx(1) ├ └───────┘ >>> bound_circuit.parameters # this one has no free parameters anymore set() >>> circuit.parameters # the original one is still parameterized {Parameter(A), Parameter(C)}