quri_parts.circuit.circuit_parametric module#

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.

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