quri_parts.circuit package#
- class QuantumGate(name, target_indices, control_indices=(), classical_indices=(), params=(), pauli_ids=(), unitary_matrix=())#
Bases:
NamedTuple
Non-parametric quantum gate.
Not intended for direct use. Every gate is created by factory methods. A QuantumGate object contains information of gate name, control qubit, target qubit, classical bits, parameters, and pauli ids.
- Parameters:
name (str) –
target_indices (Sequence[int]) –
control_indices (Sequence[int]) –
classical_indices (Sequence[int]) –
params (Sequence[float]) –
pauli_ids (Sequence[int]) –
unitary_matrix (Sequence[Sequence[complex]]) –
- name: str#
Alias for field number 0
- target_indices: Sequence[int]#
Alias for field number 1
- control_indices: Sequence[int]#
Alias for field number 2
- classical_indices: Sequence[int]#
Alias for field number 3
- params: Sequence[float]#
Alias for field number 4
- pauli_ids: Sequence[int]#
Alias for field number 5
- unitary_matrix: Sequence[Sequence[complex]]#
Alias for field number 6
- class ParametricQuantumGate(name, target_indices, control_indices=(), pauli_ids=())#
Bases:
NamedTuple
Parametric quantum gate.
Not intended for direct use. Every gate is created through factory methods. A ParametricQuantumGate object contains information of gate name, control qubit, target qubit, and pauli ids.
- Parameters:
name (str) –
target_indices (Sequence[int]) –
control_indices (Sequence[int]) –
pauli_ids (Sequence[int]) –
- name: str#
Alias for field number 0
- target_indices: Sequence[int]#
Alias for field number 1
- control_indices: Sequence[int]#
Alias for field number 2
- pauli_ids: Sequence[int]#
Alias for field number 3
- class QuantumCircuitProtocol(*args, **kwargs)#
Bases:
Protocol
Interface protocol for a quantum circuit.
This interface covers all quantum circuit classes, including:
Non-parametric circuit, parametric circuit and linearly mapped parametric circuit
Mutable and immutable circuit classes
- abstract property qubit_count: int#
Number of qubits involved in the circuit.
- abstract property cbit_count: int#
Number of classical bits involved in the circuit.
- abstract property depth: int#
Returns circuit depth.
- class MutableQuantumCircuitProtocol(*args, **kwargs)#
Bases:
QuantumCircuitProtocol
,Protocol
Interface protocol for a mutable quantum circuit.
This interface represents quantum circuits that can be modified by adding
QuantumGate
s (non-parametric gates).Some methods (
add_???_gate
) have implementations using an abstract methodadd_gate()
.- abstract add_gate(gate, gate_index=None)#
Add a (non-parametric) quantum gate to the circuit.
- Parameters:
gate (QuantumGate) –
gate_index (int | None) –
- Return type:
None
- abstract extend(gates)#
Extend the circuit with given gate sequence.
- Parameters:
gates (circuit.circuit.GateSequence) –
- Return type:
None
- add_Identity_gate(qubit_index)#
Add an Identity gate to the circuit.
- Parameters:
qubit_index (int) –
- Return type:
None
- add_X_gate(qubit_index)#
Add an X gate to the circuit.
- Parameters:
qubit_index (int) –
- Return type:
None
- add_Y_gate(qubit_index)#
Add a Y gate to the circuit.
- Parameters:
qubit_index (int) –
- Return type:
None
- add_Z_gate(qubit_index)#
Add a Z gate to the circuit.
- Parameters:
qubit_index (int) –
- Return type:
None
- add_H_gate(qubit_index)#
Add an H gate to the circuit.
- Parameters:
qubit_index (int) –
- Return type:
None
- add_S_gate(index)#
Add a S gate to the circuit.
- Parameters:
index (int) –
- Return type:
None
- add_Sdag_gate(index)#
Add a Sdag gate to the circuit.
- Parameters:
index (int) –
- Return type:
None
- add_SqrtX_gate(index)#
Add a SqrtX gate to the circuit.
- Parameters:
index (int) –
- Return type:
None
- add_SqrtXdag_gate(index)#
Add a SqrtXdag gate to the circuit.
- Parameters:
index (int) –
- Return type:
None
- add_SqrtY_gate(index)#
Add a SqrtY gate to the circuit.
- Parameters:
index (int) –
- Return type:
None
- add_SqrtYdag_gate(index)#
Add a SqrtYdag gate to the circuit.
- Parameters:
index (int) –
- Return type:
None
- add_T_gate(index)#
Add a T gate to the circuit.
- Parameters:
index (int) –
- Return type:
None
- add_Tdag_gate(index)#
Add a Tdag gate to the circuit.
- Parameters:
index (int) –
- Return type:
None
- add_U1_gate(index, lmd)#
Add an U1 gate to the circuit.
- Parameters:
index (int) –
lmd (float) –
- Return type:
None
- add_U2_gate(index, phi, lmd)#
Add an U2 gate to the circuit.
- Parameters:
index (int) –
phi (float) –
lmd (float) –
- Return type:
None
- add_U3_gate(index, theta, phi, lmd)#
Add an U3 gate to the circuit.
- Parameters:
index (int) –
theta (float) –
phi (float) –
lmd (float) –
- Return type:
None
- add_RX_gate(index, angle)#
Add a RX gate to the circuit.
- Parameters:
index (int) –
angle (float) –
- Return type:
None
- add_RY_gate(index, angle)#
Add a RY gate to the circuit.
- Parameters:
index (int) –
angle (float) –
- Return type:
None
- add_RZ_gate(index, angle)#
Add a RZ gate to the circuit.
- Parameters:
index (int) –
angle (float) –
- Return type:
None
- add_CNOT_gate(control_index, target_index)#
Add a CNOT gate to the circuit.
- Parameters:
control_index (int) –
target_index (int) –
- Return type:
None
- add_CZ_gate(control_qubit_index, target_qubit_index)#
Add a Control-Z gate to the circuit.
- Parameters:
control_qubit_index (int) –
target_qubit_index (int) –
- Return type:
None
- add_SWAP_gate(target_index1, target_index2)#
Add a SWAP gate to the circuit.
- Parameters:
target_index1 (int) –
target_index2 (int) –
- Return type:
None
- add_TOFFOLI_gate(control_index1, control_index2, target_index)#
Add a TOFFOLI gate to the circuit.
- Parameters:
control_index1 (int) –
control_index2 (int) –
target_index (int) –
- Return type:
None
- add_UnitaryMatrix_gate(target_indices, unitary_matrix)#
Add a UnitaryMatrix gate to the circuit.
- Parameters:
target_indices (Sequence[int]) –
unitary_matrix (Sequence[Sequence[complex]]) –
- Return type:
None
- add_SingleQubitUnitaryMatrix_gate(target_index, unitary_matrix)#
Add a single qubit UnitaryMatrix gate to the circuit.
- Parameters:
target_index (int) –
unitary_matrix (Sequence[Sequence[complex]]) –
- Return type:
None
- add_TwoQubitUnitaryMatrix_gate(target_index1, target_index2, unitary_matrix)#
Add a two qubit UnitaryMatrix gate to the circuit.
- Parameters:
target_index1 (int) –
target_index2 (int) –
unitary_matrix (Sequence[Sequence[complex]]) –
- Return type:
None
- add_Pauli_gate(target_indices, pauli_ids)#
Add a Pauli gate to the circuit.
- Parameters:
target_indices (Sequence[int]) –
pauli_ids (Sequence[int]) –
- Return type:
None
- add_PauliRotation_gate(target_qubits, pauli_id_list, angle)#
Add a Pauli rotation gate to the circuit.
- Parameters:
target_qubits (Sequence[int]) –
pauli_id_list (Sequence[int]) –
angle (float) –
- Return type:
None
- measure(qubit_indices, classical_indices)#
Adds measurement gate at selected qubits.
- Parameters:
qubit_indices (int | Sequence[int]) –
classical_indices (int | Sequence[int]) –
- Return type:
None
- class NonParametricQuantumCircuit(*args, **kwargs)#
Bases:
QuantumCircuitProtocol
,ABC
A base class for quantum circuits having only non-parametric gates.
This class support
+
operator withGateSequence
.- abstract property gates: Sequence[QuantumGate]#
Returns the gate sequence of the circuit.
- property depth: int#
Returns circuit depth.
- combine(gates)#
Create a new circuit with itself and the given gates combined.
- Parameters:
gates (circuit.circuit.GateSequence) –
- Return type:
- abstract freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- abstract get_mutable_copy()#
Returns a copy of itself that can be modified.
Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.
- Return type:
- class QuantumCircuit(qubit_count, cbit_count=0, gates=[])#
Bases:
NonParametricQuantumCircuit
,MutableQuantumCircuitProtocol
A mutable quantum circuit having only non-parametric gates.
- Parameters:
qubit_count (int) –
cbit_count (int) –
gates (Sequence[QuantumGate]) –
- property qubit_count: int#
Number of qubits involved in the circuit.
- property cbit_count: int#
Number of classical bits involved in the circuit.
- property gates: Sequence[QuantumGate]#
Returns the gate sequence of the circuit.
- freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- get_mutable_copy()#
Returns a copy of itself that can be modified.
Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.
- Return type:
- add_gate(gate, gate_index=None)#
Add a (non-parametric) quantum gate to the circuit.
- Parameters:
gate (QuantumGate) –
gate_index (int | None) –
- Return type:
None
- extend(gates)#
Extend the circuit with given gate sequence.
- Parameters:
gates (circuit.circuit.GateSequence) –
- Return type:
None
- class ImmutableQuantumCircuit(circuit)#
Bases:
NonParametricQuantumCircuit
An immutable quantum circuit having only non-parametric gates.
- Parameters:
circuit (NonParametricQuantumCircuit) –
- property qubit_count: int#
Number of qubits involved in the circuit.
- property cbit_count: int#
Number of classical bits involved in the circuit.
- property gates: Sequence[QuantumGate]#
Returns the gate sequence of the circuit.
- property depth: int#
Returns circuit depth.
- freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- get_mutable_copy()#
Returns a copy of itself that can be modified.
Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.
- Return type:
- class Parameter(name='')#
Bases:
object
A class representing parameters in parametric quantum circuits.
A
Parameter
is a placeholder and does not hold a concrete value in it.Implementation note: equality of Parameters is evaluated as identity of the objects. This means that even if two Parameters have the same name they are not equal if they are different objects. To achieve this behavior, it is avoided to 1) inherit
NamedTuple
and 2) define__eq__
method.- Parameters:
name (str) –
- class ParameterMapping(*args, **kwargs)#
Bases:
Protocol
ParameterMapping represents a mapping of a set of parameters to another set of parameters.
It can be considered as a function mapping \(m\) input parameters to \(n\) output parameters:
\[(\theta^\text{(out)}_0, \ldots, \theta^\text{(out)}_{n-1}) = f(\theta^\text{(in)}_0, \ldots, \theta^\text{(in)}_{m-1})\]- abstract property mapper: circuit.parameter_mapping.Mapper#
Returns a function that maps an input
ParameterValueAssignment
to an outputParameterValueAssignment
(i.e. \(f\)).It is expected that the function captures the state of
ParameterMapping
at the time that this property is accessed and does not reflect subsequent changes in the state of theParameterMapping
instance.
- abstract property seq_mapper: circuit.parameter_mapping.SeqMapper#
Returns a function that maps a sequence of input parameter values to a sequence of output parameter values (i.e. \(f\)).
It is expected that the function captures the state of
ParameterMapping
at the time that this property is accessed and does not reflect subsequent changes in the state of theParameterMapping
instance.
- get_derivatives()#
Returns a sequence of
ParameterMapping
s of derivatives of the originalParameterMapping
with respect to each input parameter.The returned sequence corresponds to
\[\left( \frac{\partial f}{\partial \theta^\text{(in)}_0}, \ldots, \frac{\partial f}{\partial \theta^\text{(in)}_{m-1}} \right),\]where \(f\) is defined as described in
ParameterMapping
docstring.- Return type:
Sequence[ParameterMapping]
- CONST = Parameter(name=)#
A placeholder representing a constant term.
- class UnboundParametricQuantumCircuitProtocol(*args, **kwargs)#
Bases:
QuantumCircuitProtocol
,Protocol
Interface protocol for a quantum circuit containing unbound (i.e. not assigned values) parameters.
For circuit execution, the parameters need to be assigned concrete values by
bind_parameters()
method.- abstract bind_parameters(params)#
Returns a new circuit with the parameters assigned concrete values.
This method does not modify self but returns a newly created circuit.
- Parameters:
params (Sequence[float]) –
- Return type:
- abstract freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- abstract get_mutable_copy()#
Returns a copy of itself that can be modified.
Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.
- Return type:
- abstract primitive_circuit()#
Returns the parametric circuit where each gate has an independent parameter.
Note that some parametric circuit, e.g.
LinearMappedUnboundParametricQuantumCircuit
, can have non-trivial mapping of the parameters. In this “primitive circuit”, however, gate parameters are treated as independent, even if those in the original circuit depend on the same parameters. For example, if the parametric circuit is defined as:\[\begin{align} U_1(f(\theta_1, \theta_2)) U_2(g(\theta_1, \theta_2)) \end{align}\]the primitive circuit should be as the following:
\[\begin{align} U_1(\psi_1) U_2(\psi_2) \end{align}\]where U1, U2 are rotation gates and f, g are parameter mappings.
- Return type:
- abstract property parameter_count: int#
- abstract property gates: Sequence[QuantumGate | ParametricQuantumGate]#
Returns the gate sequence of the circuit.
- abstract property has_trivial_parameter_mapping: bool#
Returns if the input parameters are used for parametric gates without any conversions.
Note that some parametric circuit, e.g.
LinearMappedUnboundParametricQuantumCircuit
, can have non-trivial mapping of the parameters.
- abstract property param_mapping: ParameterMapping#
Returns the parameter mapping of the circuit.
- class MutableUnboundParametricQuantumCircuitProtocol(*args, **kwargs)#
Bases:
UnboundParametricQuantumCircuitProtocol
,MutableQuantumCircuitProtocol
,Protocol
- class UnboundParametricQuantumCircuitBase(*args, **kwargs)#
Bases:
UnboundParametricQuantumCircuitProtocol
,ABC
A base class for quantum circuits having parametric gates with unbound parameters.
This class is for parametric circuits where all parametric gates have independent parameters, i.e., no two parametric gates share the same parameter. If you want to make dependency between parameters, see
LinearMappedUnboundParametricQuantumCircuitBase
.- property depth: int#
Returns circuit depth.
- property gates: Sequence[QuantumGate | ParametricQuantumGate]#
Returns the gate sequence of the circuit.
- property gates_and_params: Sequence[tuple[QuantumGate, None] | tuple[ParametricQuantumGate, Parameter]]#
Returns the sequence of the tuples of gate and it’s parameter.
- property has_trivial_parameter_mapping: bool#
Returns if the input parameters are used for parametric gates without any conversions.
Note that some parametric circuit, e.g.
LinearMappedUnboundParametricQuantumCircuit
, can have non-trivial mapping of the parameters.
- property param_mapping: LinearParameterMapping#
Returns the parameter mapping of the circuit.
- primitive_circuit()#
Returns the parametric circuit where each gate has an independent parameter.
Note that some parametric circuit, e.g.
LinearMappedUnboundParametricQuantumCircuit
, can have non-trivial mapping of the parameters. In this “primitive circuit”, however, gate parameters are treated as independent, even if those in the original circuit depend on the same parameters. For example, if the parametric circuit is defined as:\[\begin{align} U_1(f(\theta_1, \theta_2)) U_2(g(\theta_1, \theta_2)) \end{align}\]the primitive circuit should be as the following:
\[\begin{align} U_1(\psi_1) U_2(\psi_2) \end{align}\]where U1, U2 are rotation gates and f, g are parameter mappings.
- Return type:
- get_mutable_copy()#
Returns a copy of itself that can be modified.
Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.
- Return type:
- combine(gates)#
Create a new parametric circuit with itself and the given gates or an unbound parametric circuit combined.
All parameters in self and the other are treated as different ones. I.e. even if those two share the same instance of a parameter, it is copied into two independent parameters.
- Parameters:
gates (circuit.circuit.GateSequence | UnboundParametricQuantumCircuitBase) –
- Return type:
- abstract freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- bind_parameters(params)#
Returns a new circuit with the parameters assigned concrete values.
This method does not modify self but returns a newly created circuit.
- Parameters:
params (Sequence[float]) –
- Return type:
- property parameter_count: int#
- class UnboundParametricQuantumCircuit(qubit_count, cbit_count=0)#
Bases:
UnboundParametricQuantumCircuitBase
,MutableUnboundParametricQuantumCircuitProtocol
A mutable unbound parametric quantum circuit.
This class is for parametric circuits where all parametric gates have independent parameters, i.e., no two parametric gates share the same parameter. If you want to make dependency between parameters, see
LinearMappedUnboundParametricQuantumCircuit
.- Parameters:
qubit_count (int) –
cbit_count (int) –
- property qubit_count: int#
Number of qubits involved in the circuit.
- property cbit_count: int#
Number of classical bits involved in the circuit.
- add_gate(gate, gate_index=None)#
Add a (non-parametric) quantum gate to the circuit.
- Parameters:
gate (QuantumGate) –
gate_index (int | None) –
- Return type:
None
- add_ParametricRX_gate(qubit_index)#
Add a parametric RX gate to the circuit.
- Parameters:
qubit_index (int) –
- Return type:
- add_ParametricPauliRotation_gate(target_indices, pauli_ids)#
Add a parametric Pauli rotation gate to the circuit.
- Parameters:
target_indices (Sequence[int]) –
pauli_ids (Sequence[int]) –
- Return type:
- extend(gates)#
Extend the parametric circuit with given gates or an unbound parametric circuit.
All parameters in self and the other are treated as different ones. I.e. even if those two share the same instance of a parameter, it is copied into two independent parameters.
- Parameters:
gates (circuit.circuit.GateSequence | UnboundParametricQuantumCircuitBase) –
- Return type:
None
- freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- class ImmutableUnboundParametricQuantumCircuit(circuit)#
Bases:
UnboundParametricQuantumCircuitBase
An immutable unbound parametric quantum circuit.
This class is for parametric circuits where all parametric gates have independent parameters, i.e., no two parametric gates share the same parameter. If you want to make dependency between parameters, see
ImmutableLinearMappedUnboundParametricQuantumCircuit
.- Parameters:
circuit (UnboundParametricQuantumCircuitBase) –
- property qubit_count: int#
Number of qubits involved in the circuit.
- property cbit_count: int#
Number of classical bits involved in the circuit.
- freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- class ImmutableBoundParametricQuantumCircuit(circuit, parameter_map)#
Bases:
ImmutableQuantumCircuit
An immutable “bound” parametric quantum circuit, i.e. a parametric circuit with its parameters assigned concrete values.
- Parameters:
circuit (UnboundParametricQuantumCircuitBase) –
parameter_map (Mapping[Parameter, float]) –
- property gates: Sequence[QuantumGate]#
Returns the gate sequence of the circuit.
- freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- LinearParameterFunction#
A type representing a linear (affine) function of parameters. It is an alias for mapping from
Parameter
to float coefficients. A constant term can be represented as a coefficient forCONST
.
- class LinearParameterMapping(in_params=(), out_params=(), mapping={})#
Bases:
ParameterMappingBase
A
ParameterMapping
representing a linear (affine) transformation of parameters.The mapping is represented as a
Mapping
fromParameter
s toParameterOrLinearFunction
s. For example, if the mapping is defined as:\[\begin{split}\begin{align} \theta^\text{(out)}_0 &= 0.1\theta^\text{(in)}_1 + 0.2, \\ \theta^\text{(out)}_1 &= 0.3\theta^\text{(in)}_0 + 0.4\theta^\text{(in)}_1, \end{align}\end{split}\]the
mapping
argument should be as the following:{ out_param_0: { in_param_1: 0.1, CONST: 0.2 }, out_param_1: { in_param_0: 0.3, in_param_1: 0.4 }, }
where
in_param_0(1)
andout_param_0(1)
are input and outputParameter
instances respectively.- Parameters:
- with_data_updated(*, in_params_addition=(), out_params_addition=(), mapping_update={})#
- Parameters:
- Return type:
- property mapper: circuit.parameter_mapping.Mapper#
- property is_trivial_mapping: bool#
Returns if the mapping is trivial one-to-one mapping (Identity function).
- get_derivatives()#
Returns a sequence of
LinearParameterMapping
s of derivatives of the originalLinearParameterMapping
with respect to each input parameter.Since the original mapping is linear, the returned mappings only contains constant terms. For example, for the linear mapping defined in the docstring of
LinearParameterMapping
, the returned derivatives are as follows:\[\begin{split}\begin{align} \frac{\partial f}{\partial \theta^\text{(in)}_0} &= (0, 0.3)\\ \frac{\partial f}{\partial \theta^\text{(in)}_1} &= (0.1, 0.4) \end{align}\end{split}\]- Return type:
Sequence[LinearParameterMapping]
- combine(other)#
- Parameters:
other (LinearParameterMapping) –
- Return type:
- class LinearMappedUnboundParametricQuantumCircuitBase(*args, **kwargs)#
Bases:
UnboundParametricQuantumCircuitProtocol
,ABC
A base class for parametric quantum circuits where parameters of parametric gates are given by linear functions of circuit parameters.
- property qubit_count: int#
Number of qubits involved in the circuit.
- property cbit_count: int#
Number of classical bits involved in the circuit.
- property parameter_count: int#
- property depth: int#
Returns circuit depth.
- property gates: Sequence[QuantumGate | ParametricQuantumGate]#
Returns the gate sequence of the circuit.
- property has_trivial_parameter_mapping: bool#
Returns if the input parameters are used for parametric gates without any conversions.
Note that some parametric circuit, e.g.
LinearMappedUnboundParametricQuantumCircuit
, can have non-trivial mapping of the parameters.
- property param_mapping: LinearParameterMapping#
Returns the parameter mapping of the circuit.
- primitive_circuit()#
Returns the parametric circuit where each gate has an independent parameter.
Note that some parametric circuit, e.g.
LinearMappedUnboundParametricQuantumCircuit
, can have non-trivial mapping of the parameters. In this “primitive circuit”, however, gate parameters are treated as independent, even if those in the original circuit depend on the same parameters. For example, if the parametric circuit is defined as:\[\begin{align} U_1(f(\theta_1, \theta_2)) U_2(g(\theta_1, \theta_2)) \end{align}\]the primitive circuit should be as the following:
\[\begin{align} U_1(\psi_1) U_2(\psi_2) \end{align}\]where U1, U2 are rotation gates and f, g are parameter mappings.
- Return type:
- get_mutable_copy()#
Returns a copy of itself that can be modified.
Use this method when you want to get a new circuit based on an existing circuit but don’t want to modify it.
- Return type:
- combine(gates)#
- Parameters:
gates (circuit.circuit.GateSequence | UnboundParametricQuantumCircuitProtocol) –
- Return type:
- bind_parameters(params)#
Returns a new circuit with the parameters assigned concrete values.
This method does not modify self but returns a newly created circuit.
- Parameters:
params (Sequence[float]) –
- Return type:
- class LinearMappedUnboundParametricQuantumCircuit(qubit_count, cbit_count=0)#
Bases:
LinearMappedUnboundParametricQuantumCircuitBase
,MutableUnboundParametricQuantumCircuitProtocol
A mutable parametric quantum circuit where parameters of parametric gates are given by linear functions of circuit parameters.
- Parameters:
qubit_count (int) –
cbit_count (int) –
- add_parameters(*names)#
Add new parameters for the circuit.
Newly created parameters are returned as a sequence. Before adding a parametric gate to the circuit, all used parameters should be added by this method or
add_parameter()
.- Parameters:
names (str) –
- Return type:
Sequence[Parameter]
- add_parameter(name)#
Add a new parameter for the circuit.
Before adding a parametric gate to the circuit, all used parameters should be added by this method or
add_parametesr()
.- Parameters:
name (str) –
- Return type:
- add_gate(gate, gate_index=None)#
Add a (non-parametric) quantum gate to the circuit.
- Parameters:
gate (QuantumGate) –
gate_index (int | None) –
- Return type:
None
- add_ParametricRX_gate(qubit_index, angle)#
Add a parametric RX gate to the circuit.
- Parameters:
qubit_index (int) –
angle (circuit.parameter_mapping.ParameterOrLinearFunction) –
- Return type:
None
- add_ParametricRY_gate(qubit_index, angle)#
Add a parametric RY gate to the circuit.
- Parameters:
qubit_index (int) –
angle (circuit.parameter_mapping.ParameterOrLinearFunction) –
- Return type:
None
- add_ParametricRZ_gate(qubit_index, angle)#
Add a parametric RZ gate to the circuit.
- Parameters:
qubit_index (int) –
angle (circuit.parameter_mapping.ParameterOrLinearFunction) –
- Return type:
None
- add_ParametricPauliRotation_gate(qubit_indices, pauli_ids, angle)#
Add a parametric Pauli rotation gate to the circuit.
- Parameters:
qubit_indices (Sequence[int]) –
pauli_ids (Sequence[int]) –
angle (circuit.parameter_mapping.ParameterOrLinearFunction) –
- Return type:
None
- extend(gates)#
Extend the parametric circuit with given gates or a linear mapped unbound parametric circuit.
If the two linear mapped parametric circuit share the same parameters, they are treated as the same parameters, in contrast to the case of
UnboundParametricQuantumCircuit
.- Parameters:
gates (circuit.circuit.GateSequence | UnboundParametricQuantumCircuitProtocol) –
- Return type:
None
- freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- class ImmutableLinearMappedUnboundParametricQuantumCircuit(circuit)#
Bases:
LinearMappedUnboundParametricQuantumCircuitBase
An immutable parametric quantum circuit where parameters of parametric gates are given by linear functions of circuit parameters.
- Parameters:
circuit (LinearMappedUnboundParametricQuantumCircuitBase) –
- freeze()#
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- Return type:
- inverse_gate(gate)#
- Parameters:
gate (QuantumGate) –
- Return type:
- inverse_circuit(circuit)#
- Parameters:
circuit (NonParametricQuantumCircuit) –
- Return type:
- is_clifford(gate, rtol=1e-05, atol=1e-08)#
Returns True if the input gate is Clifford, otherwise False. In the case of a rotation gate, whether it is a Clifford gate or not is determined by whether the rotation angle is in the Clifford angle set \(\{\pi n /2| n\in\mathbb{Z}\}\) or not. This can be applied only to the gates in the set CLIFFORD_GATE_NAMES and currently implemented rotation gates: {RX, RY, RZ, U1, U2, U3, PauliRotation}. Since newly defined gates (e.g. U’(a, b) = RZ(2*a)RY(a+2b)) may return the wrong result, in this case this function currently returns a NotImplementedError.
- Parameters:
gate (QuantumGate) – A gate to be checked whether Clifford or not.
rtol (float) – The relative tolerance parameter determines how close the angle of rotation is to the angle in the Clifford angle set.
atol (float) – The absolute tolerance parameter determines how close the angle of rotation is to the angle in the Clifford angle set.
- Return type:
bool
Subpackages#
- quri_parts.circuit.noise package
AmplitudeDampingNoise
BitFlipNoise
BitPhaseFlipNoise
CircuitNoiseInstruction
ProbabilisticNoise
DepolarizingNoise
DepthIntervalNoise
GateIntervalNoise
GateNoiseInstruction
GeneralDepolarizingNoise
KrausNoise
AbstractKrausNoise
MeasurementNoise
NoiseModel
NoiseInstruction
PauliNoise
PhaseAmplitudeDampingNoise
PhaseAmplitudeDampingNoise.phase_damping_rate
PhaseAmplitudeDampingNoise.amplitude_damping_rate
PhaseAmplitudeDampingNoise.excited_state_population
PhaseAmplitudeDampingNoise.kraus_operators
PhaseAmplitudeDampingNoise.name
PhaseAmplitudeDampingNoise.qubit_count
PhaseAmplitudeDampingNoise.params
PhaseAmplitudeDampingNoise.qubit_indices
PhaseAmplitudeDampingNoise.target_gates
PhaseDampingNoise
PhaseFlipNoise
QubitNoisePair
ResetNoise
ThermalRelaxationNoise
ThermalRelaxationNoise.t1
ThermalRelaxationNoise.t2
ThermalRelaxationNoise.gate_time
ThermalRelaxationNoise.excited_state_population
ThermalRelaxationNoise.kraus_operators
ThermalRelaxationNoise.name
ThermalRelaxationNoise.qubit_count
ThermalRelaxationNoise.params
ThermalRelaxationNoise.qubit_indices
ThermalRelaxationNoise.target_gates
CircuitNoiseResolverProtocol
- Submodules
- quri_parts.circuit.noise.noise_instruction module
NoiseInstruction
CircuitNoiseInstruction
CircuitNoiseResolverProtocol
GateNoiseInstruction
GateIntervalNoise
DepthIntervalNoise
MeasurementNoise
BitFlipNoise
PhaseFlipNoise
BitPhaseFlipNoise
DepolarizingNoise
PauliNoise
GeneralDepolarizingNoise
ProbabilisticNoise
AbstractKrausNoise
KrausNoise
ResetNoise
PhaseDampingNoise
AmplitudeDampingNoise
PhaseAmplitudeDampingNoise
ThermalRelaxationNoise
- quri_parts.circuit.noise.noise_model module
- quri_parts.circuit.noise.noise_instruction module
- quri_parts.circuit.topology package
- quri_parts.circuit.transpile package
CliffordConversionTranspiler
CliffordRZSetTranspiler
CliffordApproximationTranspiler
CircuitTranspilerProtocol
CNOT2CZHTranspiler
CZ2CNOTHTranspiler
CZ2RXRYCNOTTranspiler
CNOTHCNOTFusingTranspiler
FuseRotationTranspiler
GateDecomposer
GateKindDecomposer
GateSetConversionTranspiler
H2RXRYTranspiler
H2RZSqrtXTranspiler
IdentityEliminationTranspiler
IdentityInsertionTranspiler
Identity2RZTranspiler
NormalizeRotationTranspiler
ParallelDecomposer
PauliDecomposeTranspiler
PauliRotationDecomposeTranspiler
QubitRemappingTranspiler
RotationConversionTranspiler
RX2RYRZTranspiler
RX2RZHTranspiler
RY2RXRZTranspiler
RY2RZHTranspiler
RZ2RXRYTranspiler
RZSetTranspiler()
RotationSetTranspiler()
Rotation2NamedTranspiler
RX2RZSqrtXTranspiler
RY2RZSqrtXTranspiler
RX2NamedTranspiler
RY2NamedTranspiler
RZ2NamedTranspiler
SequentialTranspiler
S2RZTranspiler
Sdag2RZTranspiler
SingleQubitUnitaryMatrix2RYRZTranspiler
SqrtX2RXTranspiler
SqrtX2RZHTranspiler
SqrtXdag2RXTranspiler
SqrtXdag2RZSqrtXTranspiler
SqrtY2RYTranspiler
SqrtY2RZSqrtXTranspiler
SqrtYdag2RYTranspiler
SqrtYdag2RZSqrtXTranspiler
SWAP2CNOTTranspiler
STARSetTranspiler()
T2RZTranspiler
Tdag2RZTranspiler
TOFFOLI2HTTdagCNOTTranspiler
TwoQubitUnitaryMatrixKAKTranspiler
U1ToRZTranspiler
U2ToRXRZTranspiler
U2ToRZSqrtXTranspiler
U3ToRXRZTranspiler
U3ToRZSqrtXTranspiler
X2HZTranspiler
X2RXTranspiler
X2SqrtXTranspiler
Y2RYTranspiler
Y2RZXTranspiler
Z2HXTranspiler
Z2RZTranspiler
ZeroRotationEliminationTranspiler
su2_decompose()
su4_decompose()
- Submodules
- quri_parts.circuit.transpile.clifford_approximation module
- quri_parts.circuit.transpile.fuse module
- quri_parts.circuit.transpile.gate_kind_decomposer module
CNOT2CZHTranspiler
CZ2CNOTHTranspiler
CZ2RXRYCNOTTranspiler
H2RZSqrtXTranspiler
H2RXRYTranspiler
Identity2RZTranspiler
RX2RZSqrtXTranspiler
RY2RZSqrtXTranspiler
S2RZTranspiler
Sdag2RZTranspiler
SqrtX2RXTranspiler
SqrtX2RZHTranspiler
SqrtXdag2RXTranspiler
SqrtXdag2RZSqrtXTranspiler
SqrtY2RYTranspiler
SqrtY2RZSqrtXTranspiler
SqrtYdag2RYTranspiler
SqrtYdag2RZSqrtXTranspiler
SWAP2CNOTTranspiler
T2RZTranspiler
Tdag2RZTranspiler
TOFFOLI2HTTdagCNOTTranspiler
U1ToRZTranspiler
U2ToRZSqrtXTranspiler
U2ToRXRZTranspiler
U3ToRZSqrtXTranspiler
U3ToRXRZTranspiler
X2HZTranspiler
X2RXTranspiler
X2SqrtXTranspiler
Y2RZXTranspiler
Y2RYTranspiler
Z2RZTranspiler
Z2HXTranspiler
- quri_parts.circuit.transpile.gateset module
- quri_parts.circuit.transpile.identity_manipulation module
- quri_parts.circuit.transpile.multi_pauli_decomposer module
- quri_parts.circuit.transpile.qubit_remapping module
- quri_parts.circuit.transpile.transpiler module
- quri_parts.circuit.transpile.unitary_matrix_decomposer module
- quri_parts.circuit.utils namespace
Submodules#
- quri_parts.circuit.circuit module
is_gate_sequence()
QuantumCircuitProtocol
MutableQuantumCircuitProtocol
MutableQuantumCircuitProtocol.add_gate()
MutableQuantumCircuitProtocol.extend()
MutableQuantumCircuitProtocol.add_Identity_gate()
MutableQuantumCircuitProtocol.add_X_gate()
MutableQuantumCircuitProtocol.add_Y_gate()
MutableQuantumCircuitProtocol.add_Z_gate()
MutableQuantumCircuitProtocol.add_H_gate()
MutableQuantumCircuitProtocol.add_S_gate()
MutableQuantumCircuitProtocol.add_Sdag_gate()
MutableQuantumCircuitProtocol.add_SqrtX_gate()
MutableQuantumCircuitProtocol.add_SqrtXdag_gate()
MutableQuantumCircuitProtocol.add_SqrtY_gate()
MutableQuantumCircuitProtocol.add_SqrtYdag_gate()
MutableQuantumCircuitProtocol.add_T_gate()
MutableQuantumCircuitProtocol.add_Tdag_gate()
MutableQuantumCircuitProtocol.add_U1_gate()
MutableQuantumCircuitProtocol.add_U2_gate()
MutableQuantumCircuitProtocol.add_U3_gate()
MutableQuantumCircuitProtocol.add_RX_gate()
MutableQuantumCircuitProtocol.add_RY_gate()
MutableQuantumCircuitProtocol.add_RZ_gate()
MutableQuantumCircuitProtocol.add_CNOT_gate()
MutableQuantumCircuitProtocol.add_CZ_gate()
MutableQuantumCircuitProtocol.add_SWAP_gate()
MutableQuantumCircuitProtocol.add_TOFFOLI_gate()
MutableQuantumCircuitProtocol.add_UnitaryMatrix_gate()
MutableQuantumCircuitProtocol.add_SingleQubitUnitaryMatrix_gate()
MutableQuantumCircuitProtocol.add_TwoQubitUnitaryMatrix_gate()
MutableQuantumCircuitProtocol.add_Pauli_gate()
MutableQuantumCircuitProtocol.add_PauliRotation_gate()
MutableQuantumCircuitProtocol.measure()
NonParametricQuantumCircuit
QuantumCircuit
ImmutableQuantumCircuit
- quri_parts.circuit.circuit_linear_mapped module
LinearMappedUnboundParametricQuantumCircuitBase
LinearMappedUnboundParametricQuantumCircuitBase.qubit_count
LinearMappedUnboundParametricQuantumCircuitBase.cbit_count
LinearMappedUnboundParametricQuantumCircuitBase.parameter_count
LinearMappedUnboundParametricQuantumCircuitBase.depth
LinearMappedUnboundParametricQuantumCircuitBase.gates
LinearMappedUnboundParametricQuantumCircuitBase.has_trivial_parameter_mapping
LinearMappedUnboundParametricQuantumCircuitBase.param_mapping
LinearMappedUnboundParametricQuantumCircuitBase.primitive_circuit()
LinearMappedUnboundParametricQuantumCircuitBase.get_mutable_copy()
LinearMappedUnboundParametricQuantumCircuitBase.combine()
LinearMappedUnboundParametricQuantumCircuitBase.bind_parameters()
LinearMappedUnboundParametricQuantumCircuit
LinearMappedUnboundParametricQuantumCircuit.add_parameters()
LinearMappedUnboundParametricQuantumCircuit.add_parameter()
LinearMappedUnboundParametricQuantumCircuit.add_gate()
LinearMappedUnboundParametricQuantumCircuit.add_ParametricRX_gate()
LinearMappedUnboundParametricQuantumCircuit.add_ParametricRY_gate()
LinearMappedUnboundParametricQuantumCircuit.add_ParametricRZ_gate()
LinearMappedUnboundParametricQuantumCircuit.add_ParametricPauliRotation_gate()
LinearMappedUnboundParametricQuantumCircuit.extend()
LinearMappedUnboundParametricQuantumCircuit.freeze()
ImmutableLinearMappedUnboundParametricQuantumCircuit
- quri_parts.circuit.circuit_parametric module
UnboundParametricQuantumCircuitProtocol
UnboundParametricQuantumCircuitProtocol.bind_parameters()
UnboundParametricQuantumCircuitProtocol.freeze()
UnboundParametricQuantumCircuitProtocol.get_mutable_copy()
UnboundParametricQuantumCircuitProtocol.primitive_circuit()
UnboundParametricQuantumCircuitProtocol.parameter_count
UnboundParametricQuantumCircuitProtocol.gates
UnboundParametricQuantumCircuitProtocol.has_trivial_parameter_mapping
UnboundParametricQuantumCircuitProtocol.param_mapping
UnboundParametricQuantumCircuitProtocol.bind_parameters_by_dict()
MutableUnboundParametricQuantumCircuitProtocol
UnboundParametricQuantumCircuitBase
UnboundParametricQuantumCircuitBase.depth
UnboundParametricQuantumCircuitBase.gates
UnboundParametricQuantumCircuitBase.gates_and_params
UnboundParametricQuantumCircuitBase.has_trivial_parameter_mapping
UnboundParametricQuantumCircuitBase.param_mapping
UnboundParametricQuantumCircuitBase.primitive_circuit()
UnboundParametricQuantumCircuitBase.get_mutable_copy()
UnboundParametricQuantumCircuitBase.combine()
UnboundParametricQuantumCircuitBase.freeze()
UnboundParametricQuantumCircuitBase.bind_parameters()
UnboundParametricQuantumCircuitBase.parameter_count
UnboundParametricQuantumCircuit
UnboundParametricQuantumCircuit.qubit_count
UnboundParametricQuantumCircuit.cbit_count
UnboundParametricQuantumCircuit.add_gate()
UnboundParametricQuantumCircuit.add_ParametricRX_gate()
UnboundParametricQuantumCircuit.add_ParametricRY_gate()
UnboundParametricQuantumCircuit.add_ParametricRZ_gate()
UnboundParametricQuantumCircuit.add_ParametricPauliRotation_gate()
UnboundParametricQuantumCircuit.extend()
UnboundParametricQuantumCircuit.freeze()
ImmutableUnboundParametricQuantumCircuit
ImmutableBoundParametricQuantumCircuit
- quri_parts.circuit.clifford_gate module
- quri_parts.circuit.gate module
- quri_parts.circuit.gate_names module
- quri_parts.circuit.gates module
IdentityFactory
Identity
XFactory
X
YFactory
Y
ZFactory
Z
HFactory
H
SFactory
S
SdagFactory
Sdag
SqrtXFactory
SqrtX
SqrtXdagFactory
SqrtXdag
SqrtYFactory
SqrtY
SqrtYdagFactory
SqrtYdag
TFactory
T
TdagFactory
Tdag
RXFactory
RX
RYFactory
RY
RZFactory
RZ
U1Factory
U1
U2Factory
U2
U3Factory
U3
CNOTFactory
CNOT
CZFactory
CZ
SWAPFactory
SWAP
TOFFOLIFactory
TOFFOLI
UnitaryMatrixFactory
UnitaryMatrix
SingleQubitUnitaryMatrixFactory
SingleQubitUnitaryMatrix
TwoQubitUnitaryMatrixFactory
TwoQubitUnitaryMatrix
PauliFactory
Pauli
PauliRotationFactory
PauliRotation
ParametricRXFactory
ParametricRX
ParametricRYFactory
ParametricRY
ParametricRZFactory
ParametricRZ
ParametricPauliRotationFactory
ParametricPauliRotation
MeasurementFactory
Measurement
- quri_parts.circuit.inverse module
- quri_parts.circuit.parameter module
- quri_parts.circuit.parameter_mapping module
- quri_parts.circuit.parameter_shift module