quri_parts.algo.ansatz.two_local module#

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

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.

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