quri_parts.circuit.circuit_parametric module#
- class quri_parts.circuit.circuit_parametric.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: Sequence[float]) ImmutableBoundParametricQuantumCircuit #
Returns a new circuit with the parameters assigned concrete values.
This method does not modify self but returns a newly created circuit.
- abstract freeze() UnboundParametricQuantumCircuitProtocol #
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- abstract get_mutable_copy() MutableUnboundParametricQuantumCircuitProtocol #
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.
- abstract primitive_circuit() ImmutableUnboundParametricQuantumCircuit #
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.
- 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 quri_parts.circuit.circuit_parametric.MutableUnboundParametricQuantumCircuitProtocol(*args, **kwargs)#
Bases:
UnboundParametricQuantumCircuitProtocol
,MutableQuantumCircuitProtocol
,Protocol
- class quri_parts.circuit.circuit_parametric.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() ImmutableUnboundParametricQuantumCircuit #
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.
- get_mutable_copy() UnboundParametricQuantumCircuit #
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.
- combine(gates: NonParametricQuantumCircuit | Sequence[QuantumGate] | UnboundParametricQuantumCircuitBase) UnboundParametricQuantumCircuit #
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.
- abstract freeze() ImmutableUnboundParametricQuantumCircuit #
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- bind_parameters(params: Sequence[float]) ImmutableBoundParametricQuantumCircuit #
Returns a new circuit with the parameters assigned concrete values.
This method does not modify self but returns a newly created circuit.
- property parameter_count: int#
- class quri_parts.circuit.circuit_parametric.UnboundParametricQuantumCircuit(qubit_count: int, cbit_count: int = 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
.- 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: QuantumGate, gate_index: int | None = None) None #
Add a (non-parametric) quantum gate to the circuit.
- add_ParametricPauliRotation_gate(target_indices: Sequence[int], pauli_ids: Sequence[int]) Parameter #
Add a parametric Pauli rotation gate to the circuit.
- extend(gates: NonParametricQuantumCircuit | Sequence[QuantumGate] | UnboundParametricQuantumCircuitBase) None #
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.
- freeze() ImmutableUnboundParametricQuantumCircuit #
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- class quri_parts.circuit.circuit_parametric.ImmutableUnboundParametricQuantumCircuit(circuit: UnboundParametricQuantumCircuitBase)#
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
.- property qubit_count: int#
Number of qubits involved in the circuit.
- property cbit_count: int#
Number of classical bits involved in the circuit.
- freeze() ImmutableUnboundParametricQuantumCircuit #
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.
- class quri_parts.circuit.circuit_parametric.ImmutableBoundParametricQuantumCircuit(circuit: UnboundParametricQuantumCircuitBase, parameter_map: Mapping[Parameter, float])#
Bases:
ImmutableQuantumCircuit
An immutable “bound” parametric quantum circuit, i.e. a parametric circuit with its parameters assigned concrete values.
- property gates: Sequence[QuantumGate]#
Returns the gate sequence of the circuit.
- freeze() ImmutableBoundParametricQuantumCircuit #
Returns a “freezed” version of itself.
The “freezed” version is an immutable object and can be reused safely without copying.