quri_parts.algo package¶
- class TwoLocal(qubit_count, layer_pattern, rot_layer_maker, ent_layer_maker, rotation_indices, entangler_map_seq)¶
Bases:
ImmutableLinearMappedParametricQuantumCircuitThe two-local circuit that consists of rotation layers and entanglement layers.
Examples
def add_rotation_gate(circuit, arg): layer_index, qubit_index = arg theta = circuit.add_parameter("theta") if layer_index % 2 == 0: circuit.add_ParametricRY_gate(qubit_index, theta) else: circuit.add_ParametricRZ_gate(qubit_index, theta) def add_entanglement_gate(circuit, arg): layer_index, (i, j) = arg if layer_index % 2 == 0: circuit.add_CZ_gate(i, j) else: circuit.add_CZ_gate(i, j) qubit_count = 4 reps = 2 entangler_map_seq = build_entangler_map( qubit_count, [EntanglementPatternType.LINEAR] * reps ) two_local = TwoLocal( qubit_count=qubit_count, layer_pattern="rerer", rot_layer_maker=add_rotation_gate, ent_layer_maker=add_entanglement_gate, rotation_indices=range(4), entangler_map_seq=entangler_map_seq )
- Parameters:
qubit_count (int) – Number of qubits.
layer_pattern (str) – A string specifying layer pattern, which can contain “e” (referring an entanglement layer) or “r” (referring a rotation layer).
rot_layer_maker (RotLayerMaker) – Function to rotate a qubit in a rotation layer.
ent_layer_maker (EntLayerMaker) – Function to entangle a qubit pair in an entanglement layer.
rotation_indices (Sequence[int]) – Qubit indices specifying on which qubits each rotation layer acts.
entangler_map_seq (Sequence[Sequence[tuple[int, int]]]) – Qubit index pairs specifying on which qubit pairs each entanglement layer acts.
- Raises:
ValueError – If layer_pattern contains characters other than “e” and “r”.
- layer_pattern¶
A string specifying layer pattern, which can contain “e” (referring an entanglement layer) or “r” (referring a rotation layer).
- rotation_indices¶
Qubit indices specifying on which qubits each rotation layer acts.
- entangler_map_seq¶
Qubit index pairs specifying on which qubit pairs each entanglement layer acts.
- class HardwareEfficient(qubit_count, reps, rotation_indices=None, entangler_map_seq=None, sub_width=0, sub_reps=0, sub_ent_map_seq=None)¶
Bases:
ImmutableLinearMappedParametricQuantumCircuitHardware-efficient ansatz.
Ref: A. Kandala et. al., Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets, Nature 549, 242–246
For application of HWE ansatz to Subspace search VQE, see: Nakanishi et. al., Subspace-search variational quantum eigensolver for excited states, https://arxiv.org/abs/1810.09434
- Parameters:
qubit_count (int) – Number of qubits.
reps (int) – Number of repetitions of a single entanglement layer.
rotation_indices (Optional[Sequence[int]]) – Qubit indices specifying on which qubits each rotation layer acts.
entangler_map_seq (Optional[Sequence[Sequence[tuple[int, int]]]]) – Qubit index pairs specifying on which qubit pairs each entanglement layer acts.
sub_width (int) – Number of qubits in a subspace for SSVQE.
sub_reps (int) – Number of repetitions of a single entanglement layer in a subspace for SSVQE.
sub_ent_map_seq (Optional[Sequence[Sequence[tuple[int, int]]]]) – Qubit index pairs specifying on which qubit pairs each entanglement layer in a subspace for SSVQE acts.
- class HardwareEfficientReal(qubit_count, reps, rotation_indices=None, entangler_map_seq=None, sub_width=0, sub_reps=0, sub_ent_map_seq=None)¶
Bases:
HardwareEfficientReal-valued hardware-efficient ansatz.
Ref: A. Kandala et. al., Hardware-efficient variational quantum eigensolver for small molecules and quantum magnets, Nature 549, 242–246
This implementation explicitly removes Rz gates ensuring real states.
For application of HWE ansatz to Subspace search VQE, see: Nakanishi et. al., Subspace-search variational quantum eigensolver for excited states, https://arxiv.org/abs/1810.09434
- Parameters:
qubit_count (int) – Number of qubits.
reps (int) – Number of repetitions of a single entanglement layer.
rotation_indices (Optional[Sequence[int]]) – Qubit indices specifying on which qubits each rotation layer acts.
entangler_map_seq (Optional[Sequence[Sequence[tuple[int, int]]]]) – Qubit index pairs specifying on which qubit pairs each entanglement layer acts.
sub_width (int) – Number of qubits in a subspace for SSVQE.
sub_reps (int) – Number of repetitions of a single entanglement layer in a subspace for SSVQE.
sub_ent_map_seq (Optional[Sequence[Sequence[tuple[int, int]]]]) – Qubit index pairs specifying on which qubit pairs each entanglement layer in a subspace for SSVQE acts.
- class SymmetryPreserving(qubit_count, reps, entangler_map_seq=None)¶
Bases:
ImmutableLinearMappedParametricQuantumCircuitNote
Simple Nakanishi-Fujii-Todo method of period 2pi does not work for this ansatz.
- Ref:
Efficient Symmetry-Peserving State Preparation Circuits for the Variational Quantum Eigensolver Algorithm Bryan T. Gard, Linghua Zhu, George S. Barron, Nicholas J. Mayhall, Sophia E. Economou, Edwin Barnes, npj Quantum Inf 6, 10 (2020).
- Parameters:
qubit_count (int) – number of qubits.
reps (int) – number of layers.
entangler_map_seq (Optional[Sequence[Sequence[tuple[int, int]]]]) – indices specifying on which qubits each entanglement layer acts.
- Raises:
ValueError – if number of qubits is less than 2.
- class SymmetryPreservingReal(qubit_count, reps, entangler_map_seq=None)¶
Bases:
SymmetryPreservingThis is an alternative of Symmetry Preserving Ansatz, whose RZ rotation is omitted.
- Ref:
Yohei Ibe, Yuya O. Nakagawa, Nathan Earnest, Takahiro Yamamoto, Kosuke Mitarai, Qi Gao, and Takao Kobayashi, Calculating transition amplitudes by variational quantum deflation, Phys. Rev. Research 4, 013173 (2022).
- Parameters:
qubit_count (int) – Number of qubits.
reps (int) – Number of layers.
entangler_map_seq (Optional[Sequence[Sequence[tuple[int, int]]]]) – Indices specifying on which qubits each entanglement layer acts.
- Raises:
ValueError – if number of qubits is less than 2.
- class LBFGS(c1=0.0001, c2=0.4, amin=1e-100, amax=1e+100, maxiter_linesearch=20, rho_const=1000.0, m=5, gtol=1e-06)¶
Bases:
OptimizerL-BFGS (Limited memory Bryden-Fletcher-Goldfarb-Shanno) optimizer. Partially inspired by SciPy implementation of BFGS optimizer [1]. For the details of algorithm, see [2].
- Parameters:
c1 (float) – coefficient in strong Wolfe condition. It determines the range of the cost function.
c2 (float) – coefficient in strong Wolfe condition. It determines the range of the derivative of the cost function.
amin (float) – lower bound of the value of the step size that is computed in line search.
amax (float) – upper bound of the value of the step size that is computed in line search.
maxiter_linesearch (int) – the maximum number of the iteration used in line search.
rho_const (float) – when computing \(1/x\), where \(x\) is a scaler, sometimes it returns zero division error. In that case \(1/x\) is replaced by
rho_cost.m (int) – In parameters update of each step, it uses the info of the last
msteps.gtol (Optional[float]) – If not None, it is used for determining if the opotimization has terminated successfully. If
gtolis less than the infinity norm of the gradient of the cost function, the optimization is regarded to have terminated successfully. The infinity norm of the gradient \(g\) is defined as \(||g||_{\infty} = \max\{|g_1|, |g_2|, \ldots, |g_n|\}\)
- Refs:
[1]: https://github.com/scipy/scipy/blob/master/scipy/optimize/optimize.py [2]: Jorge Nocedal and Stephen J. Wright.
Numerical Optimization (Springer, New York, 2006).
- get_init_state(init_params)¶
Returns an initial state for optimization.
- Parameters:
init_params (algo.optimizer.interface.Params)
- Return type:
- step(state, cost_function, grad_function=None)¶
Run a single optimization step and returns a new state.
- Parameters:
state (OptimizerState)
cost_function (algo.optimizer.interface.CostFunction)
grad_function (algo.optimizer.interface.GradientFunction | None)
- Return type:
Subpackages¶
- quri_parts.algo.ansatz package
EntanglementPatternTypeRotLayerMakerEntLayerMakerRotLayerMakerArgEntLayerMakerArgTwoLocalbuild_entangler_map()HardwareEfficientHardwareEfficientRealSymmetryPreservingSymmetryPreservingRealZ2SymmetryPreservingReal- Submodules
- quri_parts.algo.mitigation package
- quri_parts.algo.optimizer package
ParamsCostFunctionGradientFunctionOptimizerStatusOptimizerStateOptimizerAdamAdaBeliefLBFGSNFTNFTfitSPSA- Submodules
- quri_parts.algo.utils package