Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

qamomile.circuit.algorithm

Algorithm building blocks for quantum circuits.

Overview

FunctionDescription
cost_layerApply the cost (phase separation) layer.
cz_entangling_layerApply CZ entangling layer with linear connectivity.
fqaoa_layersApply p layers of cost + mixer.
fqaoa_stateGenerate complete FQAOA state.
givens_rotationApply a single Givens rotation between qubits i and j.
givens_rotationsApply a sequence of Givens rotations.
hopping_gateApply the fermionic hopping gate between qubits i and j.
hubo_ising_costApply the full cost layer including higher-order terms.
hubo_qaoa_layersApply p layers of the HUBO QAOA circuit (cost + mixer).
hubo_qaoa_stateGenerate HUBO QAOA state.
initial_occupationsApply X gates to the first num_fermions qubits.
ising_costApply the Ising cost layer for quadratic interactions.
mixer_layerApply the fermionic mixer layer (even-odd-boundary hopping).
qaoa_layersApply p layers of the QAOA circuit (cost + mixer).
qaoa_stateGenerate QAOA State for Ising model.
rx_layerApply RX rotation to each qubit.
ry_layerApply RY rotation to each qubit.
rz_layerApply RZ rotation to each qubit.
superposition_vectorCreate a uniform superposition state by applying Hadamard to all qubits.
x_mixerApply the X-mixer layer.

Functions

cost_layer [source]

def cost_layer(
    q: qmc.Vector[qmc.Qubit],
    gamma: qmc.Float,
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Apply the cost (phase separation) layer.


cz_entangling_layer [source]

def cz_entangling_layer(q: qmc.Vector[qmc.Qubit]) -> qmc.Vector[qmc.Qubit]

Apply CZ entangling layer with linear connectivity.

Applies CZ gates between consecutive qubits: (0,1), (1,2), ..., (n-2,n-1).

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit vector

Returns:

qmc.Vector[qmc.Qubit] — Qubit vector after entanglement


fqaoa_layers [source]

def fqaoa_layers(
    q: qmc.Vector[qmc.Qubit],
    betas: qmc.Vector[qmc.Float],
    gammas: qmc.Vector[qmc.Float],
    p: qmc.UInt,
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    hopping: qmc.Float,
    num_qubits: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply p layers of cost + mixer.


fqaoa_state [source]

def fqaoa_state(
    p: qmc.UInt,
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    num_qubits: qmc.UInt,
    num_fermions: qmc.UInt,
    givens_ij: qmc.Matrix[qmc.UInt],
    givens_theta: qmc.Vector[qmc.Float],
    hopping: qmc.Float,
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Generate complete FQAOA state.

Parameters:

NameTypeDescription
pqmc.UIntNumber of FQAOA layers.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of Ising model.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of Ising model.
num_qubitsqmc.UIntNumber of qubits.
num_fermionsqmc.UIntNumber of fermions for initial state.
givens_ijqmc.Matrix[qmc.UInt]Matrix of shape (N, 2) with qubit index pairs for Givens rotations.
givens_thetaqmc.Vector[qmc.Float]Vector of length N with Givens rotation angles.
hoppingqmc.FloatHopping integral for the mixer.
gammasqmc.Vector[qmc.Float]Vector of gamma parameters.
betasqmc.Vector[qmc.Float]Vector of beta parameters.

Returns:

qmc.Vector[qmc.Qubit] — FQAOA state vector.


givens_rotation [source]

def givens_rotation(
    q: qmc.Vector[qmc.Qubit],
    i: qmc.UInt,
    j: qmc.UInt,
    theta: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply a single Givens rotation between qubits i and j.


givens_rotations [source]

def givens_rotations(
    q: qmc.Vector[qmc.Qubit],
    givens_ij: qmc.Matrix[qmc.UInt],
    givens_theta: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Apply a sequence of Givens rotations.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit register.
givens_ijqmc.Matrix[qmc.UInt]Matrix of shape (N, 2) where each row [i, j] contains the qubit indices for one Givens rotation.
givens_thetaqmc.Vector[qmc.Float]Vector of length N with the rotation angles.

hopping_gate [source]

def hopping_gate(
    q: qmc.Vector[qmc.Qubit],
    i: qmc.UInt,
    j: qmc.UInt,
    beta: qmc.Float,
    hopping: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply the fermionic hopping gate between qubits i and j.


hubo_ising_cost [source]

def hubo_ising_cost(
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    higher: qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float],
    q: qmc.Vector[qmc.Qubit],
    gamma: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply the full cost layer including higher-order terms.

Applies the standard quadratic Ising cost circuit, then decomposes each higher-order term into phase gadgets.

Parameters:

NameTypeDescription
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients J_{ij} of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients h_i of the Ising model.
higherqmc.Dict[qmc.Vector[qmc.UInt], qmc.Float]Higher-order coefficients keyed by index vectors.
qqmc.Vector[qmc.Qubit]Qubit register.
gammaqmc.FloatVariational parameter for the cost layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register.


hubo_qaoa_layers [source]

def hubo_qaoa_layers(
    p_val: qmc.UInt,
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    higher: qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float],
    q: qmc.Vector[qmc.Qubit],
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Apply p layers of the HUBO QAOA circuit (cost + mixer).

Each layer applies the HUBO cost circuit (quadratic + higher-order terms) followed by the X-mixer circuit.

Parameters:

NameTypeDescription
p_valqmc.UIntNumber of QAOA layers.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of the Ising model.
higherqmc.Dict[qmc.Vector[qmc.UInt], qmc.Float]Higher-order coefficients keyed by index vectors.
qqmc.Vector[qmc.Qubit]Qubit register.
gammasqmc.Vector[qmc.Float]Cost-layer parameters, one per layer.
betasqmc.Vector[qmc.Float]Mixer-layer parameters, one per layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register after all layers.


hubo_qaoa_state [source]

def hubo_qaoa_state(
    p_val: qmc.UInt,
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    higher: qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float],
    n: qmc.UInt,
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Generate HUBO QAOA state.

Creates a uniform superposition and applies p layers of the HUBO QAOA circuit.

Parameters:

NameTypeDescription
p_valqmc.UIntNumber of QAOA layers.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of the Ising model.
higherqmc.Dict[qmc.Vector[qmc.UInt], qmc.Float]Higher-order coefficients keyed by index vectors.
nqmc.UIntNumber of qubits.
gammasqmc.Vector[qmc.Float]Cost-layer parameters, one per layer.
betasqmc.Vector[qmc.Float]Mixer-layer parameters, one per layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: HUBO QAOA state vector.


initial_occupations [source]

def initial_occupations(q: qmc.Vector[qmc.Qubit], num_fermions: qmc.UInt) -> qmc.Vector[qmc.Qubit]

Apply X gates to the first num_fermions qubits.


ising_cost [source]

def ising_cost(
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    q: qmc.Vector[qmc.Qubit],
    gamma: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply the Ising cost layer for quadratic interactions.

Applies RZZ gates for quadratic terms and RZ gates for linear terms, each scaled by the variational parameter gamma.

Parameters:

NameTypeDescription
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients J_{ij} of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients h_i of the Ising model.
qqmc.Vector[qmc.Qubit]Qubit register.
gammaqmc.FloatVariational parameter for the cost layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register.


mixer_layer [source]

def mixer_layer(
    q: qmc.Vector[qmc.Qubit],
    beta: qmc.Float,
    hopping: qmc.Float,
    num_qubits: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply the fermionic mixer layer (even-odd-boundary hopping).


qaoa_layers [source]

def qaoa_layers(
    p: qmc.UInt,
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    q: qmc.Vector[qmc.Qubit],
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Apply p layers of the QAOA circuit (cost + mixer).

Each layer applies the Ising cost circuit followed by the X-mixer circuit.

Parameters:

NameTypeDescription
pqmc.UIntNumber of QAOA layers.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of the Ising model.
qqmc.Vector[qmc.Qubit]Qubit register.
gammasqmc.Vector[qmc.Float]Cost-layer parameters, one per layer.
betasqmc.Vector[qmc.Float]Mixer-layer parameters, one per layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register after all layers.


qaoa_state [source]

def qaoa_state(
    p: qmc.UInt,
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    n: qmc.UInt,
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Generate QAOA State for Ising model.

Parameters:

NameTypeDescription
pqmc.UIntNumber of QAOA layers.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of the Ising model.
nqmc.UIntNumber of qubits.
gammasqmc.Vector[qmc.Float]Cost-layer parameters, one per layer.
betasqmc.Vector[qmc.Float]Mixer-layer parameters, one per layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: QAOA state vector.


rx_layer [source]

def rx_layer(
    q: qmc.Vector[qmc.Qubit],
    thetas: qmc.Vector[qmc.Float],
    offset: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply RX rotation to each qubit.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit vector
thetasqmc.Vector[qmc.Float]Parameter vector
offsetqmc.UIntStarting index in thetas (consumes q.shape[0] parameters)

Returns:

qmc.Vector[qmc.Qubit] — Qubit vector after rotations


ry_layer [source]

def ry_layer(
    q: qmc.Vector[qmc.Qubit],
    thetas: qmc.Vector[qmc.Float],
    offset: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply RY rotation to each qubit.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit vector
thetasqmc.Vector[qmc.Float]Parameter vector
offsetqmc.UIntStarting index in thetas (consumes q.shape[0] parameters)

Returns:

qmc.Vector[qmc.Qubit] — Qubit vector after rotations


rz_layer [source]

def rz_layer(
    q: qmc.Vector[qmc.Qubit],
    thetas: qmc.Vector[qmc.Float],
    offset: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply RZ rotation to each qubit.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit vector
thetasqmc.Vector[qmc.Float]Parameter vector
offsetqmc.UIntStarting index in thetas (consumes q.shape[0] parameters)

Returns:

qmc.Vector[qmc.Qubit] — Qubit vector after rotations


superposition_vector [source]

def superposition_vector(n: qmc.UInt) -> qmc.Vector[qmc.Qubit]

Create a uniform superposition state by applying Hadamard to all qubits.

Parameters:

NameTypeDescription
nqmc.UIntNumber of qubits.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Qubit register in the |+>^n state.


x_mixer [source]

def x_mixer(q: qmc.Vector[qmc.Qubit], beta: qmc.Float) -> qmc.Vector[qmc.Qubit]

Apply the X-mixer layer.

Applies RX(2*beta) to every qubit in the register.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit register.
betaqmc.FloatVariational parameter for the mixer layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register.


qamomile.circuit.algorithm.basic

Basic building blocks for variational quantum circuits.

This module provides fundamental rotation layers and entanglement layers that can be composed to build variational ansatze.

Overview

FunctionDescription
cz_entangling_layerApply CZ entangling layer with linear connectivity.
phase_gadgetApply exp(-i * angle/2 * Z_{i0} Z_{i1} ... Z_{ik-1}).
rx_layerApply RX rotation to each qubit.
ry_layerApply RY rotation to each qubit.
rz_layerApply RZ rotation to each qubit.
superposition_vectorCreate a uniform superposition state by applying Hadamard to all qubits.

Functions

cz_entangling_layer [source]

def cz_entangling_layer(q: qmc.Vector[qmc.Qubit]) -> qmc.Vector[qmc.Qubit]

Apply CZ entangling layer with linear connectivity.

Applies CZ gates between consecutive qubits: (0,1), (1,2), ..., (n-2,n-1).

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit vector

Returns:

qmc.Vector[qmc.Qubit] — Qubit vector after entanglement


phase_gadget [source]

def phase_gadget(
    q: qmc.Vector[qmc.Qubit],
    indices: qmc.Vector[qmc.UInt],
    angle: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply exp(-i * angle/2 * Z_{i0} Z_{i1} ... Z_{ik-1}).

Decomposes a k-body Z-rotation into CX + RZ primitives.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit register.
indicesqmc.Vector[qmc.UInt]Qubit indices for the interaction term. Must be non-empty.
angleqmc.FloatRotation angle in radians.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register.


rx_layer [source]

def rx_layer(
    q: qmc.Vector[qmc.Qubit],
    thetas: qmc.Vector[qmc.Float],
    offset: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply RX rotation to each qubit.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit vector
thetasqmc.Vector[qmc.Float]Parameter vector
offsetqmc.UIntStarting index in thetas (consumes q.shape[0] parameters)

Returns:

qmc.Vector[qmc.Qubit] — Qubit vector after rotations


ry_layer [source]

def ry_layer(
    q: qmc.Vector[qmc.Qubit],
    thetas: qmc.Vector[qmc.Float],
    offset: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply RY rotation to each qubit.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit vector
thetasqmc.Vector[qmc.Float]Parameter vector
offsetqmc.UIntStarting index in thetas (consumes q.shape[0] parameters)

Returns:

qmc.Vector[qmc.Qubit] — Qubit vector after rotations


rz_layer [source]

def rz_layer(
    q: qmc.Vector[qmc.Qubit],
    thetas: qmc.Vector[qmc.Float],
    offset: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply RZ rotation to each qubit.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit vector
thetasqmc.Vector[qmc.Float]Parameter vector
offsetqmc.UIntStarting index in thetas (consumes q.shape[0] parameters)

Returns:

qmc.Vector[qmc.Qubit] — Qubit vector after rotations


superposition_vector [source]

def superposition_vector(n: qmc.UInt) -> qmc.Vector[qmc.Qubit]

Create a uniform superposition state by applying Hadamard to all qubits.

Parameters:

NameTypeDescription
nqmc.UIntNumber of qubits.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Qubit register in the |+>^n state.


qamomile.circuit.algorithm.fqaoa

FQAOA (Fermionic QAOA) circuit building blocks.

This module provides the quantum circuit components for the Fermionic Quantum Approximate Optimization Algorithm (FQAOA), including Givens rotations for initial state preparation, hopping gates for the fermionic mixer, and cost layer construction.

All functions are decorated with @qm_c.qkernel and use Handle-typed parameters so they can be composed inside other @qkernel functions.

Overview

FunctionDescription
cost_layerApply the cost (phase separation) layer.
fqaoa_layersApply p layers of cost + mixer.
fqaoa_stateGenerate complete FQAOA state.
givens_rotationApply a single Givens rotation between qubits i and j.
givens_rotationsApply a sequence of Givens rotations.
hopping_gateApply the fermionic hopping gate between qubits i and j.
initial_occupationsApply X gates to the first num_fermions qubits.
mixer_layerApply the fermionic mixer layer (even-odd-boundary hopping).

Functions

cost_layer [source]

def cost_layer(
    q: qmc.Vector[qmc.Qubit],
    gamma: qmc.Float,
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Apply the cost (phase separation) layer.


fqaoa_layers [source]

def fqaoa_layers(
    q: qmc.Vector[qmc.Qubit],
    betas: qmc.Vector[qmc.Float],
    gammas: qmc.Vector[qmc.Float],
    p: qmc.UInt,
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    hopping: qmc.Float,
    num_qubits: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply p layers of cost + mixer.


fqaoa_state [source]

def fqaoa_state(
    p: qmc.UInt,
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    num_qubits: qmc.UInt,
    num_fermions: qmc.UInt,
    givens_ij: qmc.Matrix[qmc.UInt],
    givens_theta: qmc.Vector[qmc.Float],
    hopping: qmc.Float,
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Generate complete FQAOA state.

Parameters:

NameTypeDescription
pqmc.UIntNumber of FQAOA layers.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of Ising model.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of Ising model.
num_qubitsqmc.UIntNumber of qubits.
num_fermionsqmc.UIntNumber of fermions for initial state.
givens_ijqmc.Matrix[qmc.UInt]Matrix of shape (N, 2) with qubit index pairs for Givens rotations.
givens_thetaqmc.Vector[qmc.Float]Vector of length N with Givens rotation angles.
hoppingqmc.FloatHopping integral for the mixer.
gammasqmc.Vector[qmc.Float]Vector of gamma parameters.
betasqmc.Vector[qmc.Float]Vector of beta parameters.

Returns:

qmc.Vector[qmc.Qubit] — FQAOA state vector.


givens_rotation [source]

def givens_rotation(
    q: qmc.Vector[qmc.Qubit],
    i: qmc.UInt,
    j: qmc.UInt,
    theta: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply a single Givens rotation between qubits i and j.


givens_rotations [source]

def givens_rotations(
    q: qmc.Vector[qmc.Qubit],
    givens_ij: qmc.Matrix[qmc.UInt],
    givens_theta: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Apply a sequence of Givens rotations.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit register.
givens_ijqmc.Matrix[qmc.UInt]Matrix of shape (N, 2) where each row [i, j] contains the qubit indices for one Givens rotation.
givens_thetaqmc.Vector[qmc.Float]Vector of length N with the rotation angles.

hopping_gate [source]

def hopping_gate(
    q: qmc.Vector[qmc.Qubit],
    i: qmc.UInt,
    j: qmc.UInt,
    beta: qmc.Float,
    hopping: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply the fermionic hopping gate between qubits i and j.


initial_occupations [source]

def initial_occupations(q: qmc.Vector[qmc.Qubit], num_fermions: qmc.UInt) -> qmc.Vector[qmc.Qubit]

Apply X gates to the first num_fermions qubits.


mixer_layer [source]

def mixer_layer(
    q: qmc.Vector[qmc.Qubit],
    beta: qmc.Float,
    hopping: qmc.Float,
    num_qubits: qmc.UInt,
) -> qmc.Vector[qmc.Qubit]

Apply the fermionic mixer layer (even-odd-boundary hopping).


qamomile.circuit.algorithm.qaoa

Overview

FunctionDescription
hubo_ising_costApply the full cost layer including higher-order terms.
hubo_qaoa_layersApply p layers of the HUBO QAOA circuit (cost + mixer).
hubo_qaoa_stateGenerate HUBO QAOA state.
ising_costApply the Ising cost layer for quadratic interactions.
qaoa_layersApply p layers of the QAOA circuit (cost + mixer).
qaoa_stateGenerate QAOA State for Ising model.
x_mixerApply the X-mixer layer.

Functions

hubo_ising_cost [source]

def hubo_ising_cost(
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    higher: qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float],
    q: qmc.Vector[qmc.Qubit],
    gamma: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply the full cost layer including higher-order terms.

Applies the standard quadratic Ising cost circuit, then decomposes each higher-order term into phase gadgets.

Parameters:

NameTypeDescription
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients J_{ij} of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients h_i of the Ising model.
higherqmc.Dict[qmc.Vector[qmc.UInt], qmc.Float]Higher-order coefficients keyed by index vectors.
qqmc.Vector[qmc.Qubit]Qubit register.
gammaqmc.FloatVariational parameter for the cost layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register.


hubo_qaoa_layers [source]

def hubo_qaoa_layers(
    p_val: qmc.UInt,
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    higher: qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float],
    q: qmc.Vector[qmc.Qubit],
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Apply p layers of the HUBO QAOA circuit (cost + mixer).

Each layer applies the HUBO cost circuit (quadratic + higher-order terms) followed by the X-mixer circuit.

Parameters:

NameTypeDescription
p_valqmc.UIntNumber of QAOA layers.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of the Ising model.
higherqmc.Dict[qmc.Vector[qmc.UInt], qmc.Float]Higher-order coefficients keyed by index vectors.
qqmc.Vector[qmc.Qubit]Qubit register.
gammasqmc.Vector[qmc.Float]Cost-layer parameters, one per layer.
betasqmc.Vector[qmc.Float]Mixer-layer parameters, one per layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register after all layers.


hubo_qaoa_state [source]

def hubo_qaoa_state(
    p_val: qmc.UInt,
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    higher: qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float],
    n: qmc.UInt,
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Generate HUBO QAOA state.

Creates a uniform superposition and applies p layers of the HUBO QAOA circuit.

Parameters:

NameTypeDescription
p_valqmc.UIntNumber of QAOA layers.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of the Ising model.
higherqmc.Dict[qmc.Vector[qmc.UInt], qmc.Float]Higher-order coefficients keyed by index vectors.
nqmc.UIntNumber of qubits.
gammasqmc.Vector[qmc.Float]Cost-layer parameters, one per layer.
betasqmc.Vector[qmc.Float]Mixer-layer parameters, one per layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: HUBO QAOA state vector.


ising_cost [source]

def ising_cost(
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    q: qmc.Vector[qmc.Qubit],
    gamma: qmc.Float,
) -> qmc.Vector[qmc.Qubit]

Apply the Ising cost layer for quadratic interactions.

Applies RZZ gates for quadratic terms and RZ gates for linear terms, each scaled by the variational parameter gamma.

Parameters:

NameTypeDescription
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients J_{ij} of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients h_i of the Ising model.
qqmc.Vector[qmc.Qubit]Qubit register.
gammaqmc.FloatVariational parameter for the cost layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register.


qaoa_layers [source]

def qaoa_layers(
    p: qmc.UInt,
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    q: qmc.Vector[qmc.Qubit],
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Apply p layers of the QAOA circuit (cost + mixer).

Each layer applies the Ising cost circuit followed by the X-mixer circuit.

Parameters:

NameTypeDescription
pqmc.UIntNumber of QAOA layers.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of the Ising model.
qqmc.Vector[qmc.Qubit]Qubit register.
gammasqmc.Vector[qmc.Float]Cost-layer parameters, one per layer.
betasqmc.Vector[qmc.Float]Mixer-layer parameters, one per layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register after all layers.


qaoa_state [source]

def qaoa_state(
    p: qmc.UInt,
    quad: qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float],
    linear: qmc.Dict[qmc.UInt, qmc.Float],
    n: qmc.UInt,
    gammas: qmc.Vector[qmc.Float],
    betas: qmc.Vector[qmc.Float],
) -> qmc.Vector[qmc.Qubit]

Generate QAOA State for Ising model.

Parameters:

NameTypeDescription
pqmc.UIntNumber of QAOA layers.
quadqmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float]Quadratic coefficients of the Ising model.
linearqmc.Dict[qmc.UInt, qmc.Float]Linear coefficients of the Ising model.
nqmc.UIntNumber of qubits.
gammasqmc.Vector[qmc.Float]Cost-layer parameters, one per layer.
betasqmc.Vector[qmc.Float]Mixer-layer parameters, one per layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: QAOA state vector.


x_mixer [source]

def x_mixer(q: qmc.Vector[qmc.Qubit], beta: qmc.Float) -> qmc.Vector[qmc.Qubit]

Apply the X-mixer layer.

Applies RX(2*beta) to every qubit in the register.

Parameters:

NameTypeDescription
qqmc.Vector[qmc.Qubit]Qubit register.
betaqmc.FloatVariational parameter for the mixer layer.

Returns:

qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register.