quri_parts.algo.ansatz package#

class EntanglementPatternType(value)#

Bases: Enum

An enum representing an entanglement pattern for entanglement layers.

FULL = 1#

Each qubit is entangled with all the others.

LINEAR = 2#

Each qubit (except the last one) is entangled with the next one.

CIRCULAR = 3#

Each qubit is entangled with the next one (the first one for the last qubit).

RotLayerMaker#

Function to rotate a qubit in a rotation layer.

alias of Callable[[LinearMappedUnboundParametricQuantumCircuit, RotLayerMakerArg], None]

EntLayerMaker#

Function to entangle a qubit pair in an entanglement layer.

alias of Callable[[LinearMappedUnboundParametricQuantumCircuit, EntLayerMakerArg], None]

class RotLayerMakerArg(layer_index, qubit_index)#

Bases: NamedTuple

Argument type for RotLayerMaker.

Parameters:
  • layer_index (int) –

  • qubit_index (int) –

layer_index: int#

Index of the rotation layer.

qubit_index: int#

Index of the qubit.

class EntLayerMakerArg(layer_index, qubit_indices)#

Bases: NamedTuple

Argument type for EntLayerMaker.

Parameters:
  • layer_index (int) –

  • qubit_indices (tuple[int, int]) –

layer_index: int#

Index of the entanglement layer.

qubit_indices: tuple[int, int]#

Indices of the qubit pair.

class TwoLocal(qubit_count, layer_pattern, rot_layer_maker, ent_layer_maker, rotation_indices, entangler_map_seq)#

Bases: ImmutableLinearMappedUnboundParametricQuantumCircuit

The 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.

build_entangler_map(qubit_count, entanglement_list)#

Build an entangler map for one entanglement layer.

Parameters:
  • qubit_count (int) – Number of qubits.

  • entanglement_list (Sequence[EntanglementPatternType]) – Specification of entanglement patterns in the entanglement layer. Each component in the sequence corresponds to a “sub layer” in the entanglement layer.

Returns:

An entangler map for TwoLocal class.

Raises:

ValueError – If the entanglement_list contains an unsupported entanglement pattern type.

Return type:

Sequence[Sequence[tuple[int, int]]]

Examples

>>> build_entangler_map(4, [
    EntanglementPatternType.LINEAR,
    EntanglementPatternType.CIRCULAR,
    EntanglementPatternType.FULL
])
(
    ((1, 2), (0, 1), (2, 3)),
    ((1, 2), (3, 0), (0, 1), (2, 3)),
    ((0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3))
)
class HardwareEfficient(qubit_count, reps, rotation_indices=None, entangler_map_seq=None, sub_width=0, sub_reps=0, sub_ent_map_seq=None)#

Bases: ImmutableLinearMappedUnboundParametricQuantumCircuit

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

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

Note

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

This 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.

Submodules#