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 QuantumGates (non-parametric gates).

Some methods (add_???_gate) have implementations using an abstract method add_gate().

abstract add_gate(gate, gate_index=None)#

Add a (non-parametric) quantum gate to the circuit.

Parameters:
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 with GateSequence.

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:

QuantumCircuit

abstract freeze()#

Returns a “freezed” version of itself.

The “freezed” version is an immutable object and can be reused safely without copying.

Return type:

ImmutableQuantumCircuit

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:

QuantumCircuit

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:

ImmutableQuantumCircuit

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:

QuantumCircuit

add_gate(gate, gate_index=None)#

Add a (non-parametric) quantum gate to the circuit.

Parameters:
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:

ImmutableQuantumCircuit

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:

QuantumCircuit

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 in_params: Sequence[Parameter]#

Returns a sequence of input Parameters.

abstract property out_params: Sequence[Parameter]#

Returns a sequence of output Parameters.

abstract property mapper: circuit.parameter_mapping.Mapper#

Returns a function that maps an input ParameterValueAssignment to an output ParameterValueAssignment (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 the ParameterMapping 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 the ParameterMapping instance.

get_derivatives()#

Returns a sequence of ParameterMappings of derivatives of the original ParameterMapping 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:

ImmutableBoundParametricQuantumCircuit

abstract freeze()#

Returns a “freezed” version of itself.

The “freezed” version is an immutable object and can be reused safely without copying.

Return type:

UnboundParametricQuantumCircuitProtocol

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:

MutableUnboundParametricQuantumCircuitProtocol

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:

ImmutableUnboundParametricQuantumCircuit

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.

bind_parameters_by_dict(params_dict)#

Returns a new circuit with the parameters assigned concrete values.

This method does not modify self but returns a newly created circuit.

Parameters:

params_dict (dict[Parameter, float]) –

Return type:

ImmutableBoundParametricQuantumCircuit

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:

ImmutableUnboundParametricQuantumCircuit

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:

UnboundParametricQuantumCircuit

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:

UnboundParametricQuantumCircuit

abstract freeze()#

Returns a “freezed” version of itself.

The “freezed” version is an immutable object and can be reused safely without copying.

Return type:

ImmutableUnboundParametricQuantumCircuit

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:

ImmutableBoundParametricQuantumCircuit

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:
Return type:

None

add_ParametricRX_gate(qubit_index)#

Add a parametric RX gate to the circuit.

Parameters:

qubit_index (int) –

Return type:

Parameter

add_ParametricRY_gate(qubit_index)#
Parameters:

qubit_index (int) –

Return type:

Parameter

add_ParametricRZ_gate(qubit_index)#
Parameters:

qubit_index (int) –

Return type:

Parameter

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:

Parameter

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:

ImmutableUnboundParametricQuantumCircuit

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:

ImmutableUnboundParametricQuantumCircuit

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:
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:

ImmutableBoundParametricQuantumCircuit

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 for CONST.

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 from Parameters to ParameterOrLinearFunctions. 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) and out_param_0(1) are input and output Parameter instances respectively.

Parameters:
with_data_updated(*, in_params_addition=(), out_params_addition=(), mapping_update={})#
Parameters:
  • in_params_addition (Sequence[Parameter]) –

  • out_params_addition (Sequence[Parameter]) –

  • mapping_update (Mapping[Parameter, circuit.parameter_mapping.ParameterOrLinearFunction]) –

Return type:

LinearParameterMapping

property in_params: Sequence[Parameter]#
property out_params: Sequence[Parameter]#
property mapping: Mapping[Parameter, circuit.parameter_mapping.ParameterOrLinearFunction]#
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 LinearParameterMappings of derivatives of the original LinearParameterMapping 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:

LinearParameterMapping

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:

ImmutableUnboundParametricQuantumCircuit

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:

LinearMappedUnboundParametricQuantumCircuit

combine(gates)#
Parameters:

gates (circuit.circuit.GateSequence | UnboundParametricQuantumCircuitProtocol) –

Return type:

LinearMappedUnboundParametricQuantumCircuit

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:

ImmutableBoundParametricQuantumCircuit

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:

Parameter

add_gate(gate, gate_index=None)#

Add a (non-parametric) quantum gate to the circuit.

Parameters:
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:

ImmutableLinearMappedUnboundParametricQuantumCircuit

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:

ImmutableLinearMappedUnboundParametricQuantumCircuit

inverse_gate(gate)#
Parameters:

gate (QuantumGate) –

Return type:

QuantumGate

inverse_circuit(circuit)#
Parameters:

circuit (NonParametricQuantumCircuit) –

Return type:

QuantumCircuit

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#

Submodules#