Algorithm building blocks for quantum circuits.
Overview¶
| Function | Description |
|---|---|
cost_layer | Apply the cost (phase separation) layer. |
cz_entangling_layer | Apply CZ entangling layer with linear connectivity. |
fqaoa_layers | Apply p layers of cost + mixer. |
fqaoa_state | Generate complete FQAOA state. |
givens_rotation | Apply a single Givens rotation between qubits i and j. |
givens_rotations | Apply a sequence of Givens rotations. |
hopping_gate | Apply the fermionic hopping gate between qubits i and j. |
hubo_ising_cost | Apply the full cost layer including higher-order terms. |
hubo_qaoa_layers | Apply p layers of the HUBO QAOA circuit (cost + mixer). |
hubo_qaoa_state | Generate HUBO QAOA state. |
initial_occupations | Apply X gates to the first num_fermions qubits. |
ising_cost | Apply the Ising cost layer for quadratic interactions. |
mixer_layer | Apply the fermionic mixer layer (even-odd-boundary hopping). |
qaoa_layers | Apply p layers of the QAOA circuit (cost + mixer). |
qaoa_state | Generate QAOA State for Ising model. |
rx_layer | Apply RX rotation to each qubit. |
ry_layer | Apply RY rotation to each qubit. |
rz_layer | Apply RZ rotation to each qubit. |
superposition_vector | Create a uniform superposition state by applying Hadamard to all qubits. |
x_mixer | Apply 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:
| Name | Type | Description |
|---|---|---|
q | qmc.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:
| Name | Type | Description |
|---|---|---|
p | qmc.UInt | Number of FQAOA layers. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of Ising model. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of Ising model. |
num_qubits | qmc.UInt | Number of qubits. |
num_fermions | qmc.UInt | Number of fermions for initial state. |
givens_ij | qmc.Matrix[qmc.UInt] | Matrix of shape (N, 2) with qubit index pairs for Givens rotations. |
givens_theta | qmc.Vector[qmc.Float] | Vector of length N with Givens rotation angles. |
hopping | qmc.Float | Hopping integral for the mixer. |
gammas | qmc.Vector[qmc.Float] | Vector of gamma parameters. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit register. |
givens_ij | qmc.Matrix[qmc.UInt] | Matrix of shape (N, 2) where each row [i, j] contains the qubit indices for one Givens rotation. |
givens_theta | qmc.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:
| Name | Type | Description |
|---|---|---|
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients J_{ij} of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients h_i of the Ising model. |
higher | qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float] | Higher-order coefficients keyed by index vectors. |
q | qmc.Vector[qmc.Qubit] | Qubit register. |
gamma | qmc.Float | Variational 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:
| Name | Type | Description |
|---|---|---|
p_val | qmc.UInt | Number of QAOA layers. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of the Ising model. |
higher | qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float] | Higher-order coefficients keyed by index vectors. |
q | qmc.Vector[qmc.Qubit] | Qubit register. |
gammas | qmc.Vector[qmc.Float] | Cost-layer parameters, one per layer. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
p_val | qmc.UInt | Number of QAOA layers. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of the Ising model. |
higher | qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float] | Higher-order coefficients keyed by index vectors. |
n | qmc.UInt | Number of qubits. |
gammas | qmc.Vector[qmc.Float] | Cost-layer parameters, one per layer. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients J_{ij} of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients h_i of the Ising model. |
q | qmc.Vector[qmc.Qubit] | Qubit register. |
gamma | qmc.Float | Variational 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:
| Name | Type | Description |
|---|---|---|
p | qmc.UInt | Number of QAOA layers. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of the Ising model. |
q | qmc.Vector[qmc.Qubit] | Qubit register. |
gammas | qmc.Vector[qmc.Float] | Cost-layer parameters, one per layer. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
p | qmc.UInt | Number of QAOA layers. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of the Ising model. |
n | qmc.UInt | Number of qubits. |
gammas | qmc.Vector[qmc.Float] | Cost-layer parameters, one per layer. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit vector |
thetas | qmc.Vector[qmc.Float] | Parameter vector |
offset | qmc.UInt | Starting 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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit vector |
thetas | qmc.Vector[qmc.Float] | Parameter vector |
offset | qmc.UInt | Starting 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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit vector |
thetas | qmc.Vector[qmc.Float] | Parameter vector |
offset | qmc.UInt | Starting 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:
| Name | Type | Description |
|---|---|---|
n | qmc.UInt | Number 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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit register. |
beta | qmc.Float | Variational 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¶
| Function | Description |
|---|---|
cz_entangling_layer | Apply CZ entangling layer with linear connectivity. |
phase_gadget | Apply exp(-i * angle/2 * Z_{i0} Z_{i1} ... Z_{ik-1}). |
rx_layer | Apply RX rotation to each qubit. |
ry_layer | Apply RY rotation to each qubit. |
rz_layer | Apply RZ rotation to each qubit. |
superposition_vector | Create 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:
| Name | Type | Description |
|---|---|---|
q | qmc.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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit register. |
indices | qmc.Vector[qmc.UInt] | Qubit indices for the interaction term. Must be non-empty. |
angle | qmc.Float | Rotation 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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit vector |
thetas | qmc.Vector[qmc.Float] | Parameter vector |
offset | qmc.UInt | Starting 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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit vector |
thetas | qmc.Vector[qmc.Float] | Parameter vector |
offset | qmc.UInt | Starting 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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit vector |
thetas | qmc.Vector[qmc.Float] | Parameter vector |
offset | qmc.UInt | Starting 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:
| Name | Type | Description |
|---|---|---|
n | qmc.UInt | Number 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¶
| Function | Description |
|---|---|
cost_layer | Apply the cost (phase separation) layer. |
fqaoa_layers | Apply p layers of cost + mixer. |
fqaoa_state | Generate complete FQAOA state. |
givens_rotation | Apply a single Givens rotation between qubits i and j. |
givens_rotations | Apply a sequence of Givens rotations. |
hopping_gate | Apply the fermionic hopping gate between qubits i and j. |
initial_occupations | Apply X gates to the first num_fermions qubits. |
mixer_layer | Apply 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:
| Name | Type | Description |
|---|---|---|
p | qmc.UInt | Number of FQAOA layers. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of Ising model. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of Ising model. |
num_qubits | qmc.UInt | Number of qubits. |
num_fermions | qmc.UInt | Number of fermions for initial state. |
givens_ij | qmc.Matrix[qmc.UInt] | Matrix of shape (N, 2) with qubit index pairs for Givens rotations. |
givens_theta | qmc.Vector[qmc.Float] | Vector of length N with Givens rotation angles. |
hopping | qmc.Float | Hopping integral for the mixer. |
gammas | qmc.Vector[qmc.Float] | Vector of gamma parameters. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit register. |
givens_ij | qmc.Matrix[qmc.UInt] | Matrix of shape (N, 2) where each row [i, j] contains the qubit indices for one Givens rotation. |
givens_theta | qmc.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¶
| Function | Description |
|---|---|
hubo_ising_cost | Apply the full cost layer including higher-order terms. |
hubo_qaoa_layers | Apply p layers of the HUBO QAOA circuit (cost + mixer). |
hubo_qaoa_state | Generate HUBO QAOA state. |
ising_cost | Apply the Ising cost layer for quadratic interactions. |
qaoa_layers | Apply p layers of the QAOA circuit (cost + mixer). |
qaoa_state | Generate QAOA State for Ising model. |
x_mixer | Apply 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:
| Name | Type | Description |
|---|---|---|
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients J_{ij} of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients h_i of the Ising model. |
higher | qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float] | Higher-order coefficients keyed by index vectors. |
q | qmc.Vector[qmc.Qubit] | Qubit register. |
gamma | qmc.Float | Variational 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:
| Name | Type | Description |
|---|---|---|
p_val | qmc.UInt | Number of QAOA layers. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of the Ising model. |
higher | qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float] | Higher-order coefficients keyed by index vectors. |
q | qmc.Vector[qmc.Qubit] | Qubit register. |
gammas | qmc.Vector[qmc.Float] | Cost-layer parameters, one per layer. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
p_val | qmc.UInt | Number of QAOA layers. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of the Ising model. |
higher | qmc.Dict[qmc.Vector[qmc.UInt], qmc.Float] | Higher-order coefficients keyed by index vectors. |
n | qmc.UInt | Number of qubits. |
gammas | qmc.Vector[qmc.Float] | Cost-layer parameters, one per layer. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients J_{ij} of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients h_i of the Ising model. |
q | qmc.Vector[qmc.Qubit] | Qubit register. |
gamma | qmc.Float | Variational 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:
| Name | Type | Description |
|---|---|---|
p | qmc.UInt | Number of QAOA layers. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of the Ising model. |
q | qmc.Vector[qmc.Qubit] | Qubit register. |
gammas | qmc.Vector[qmc.Float] | Cost-layer parameters, one per layer. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
p | qmc.UInt | Number of QAOA layers. |
quad | qmc.Dict[qmc.Tuple[qmc.UInt, qmc.UInt], qmc.Float] | Quadratic coefficients of the Ising model. |
linear | qmc.Dict[qmc.UInt, qmc.Float] | Linear coefficients of the Ising model. |
n | qmc.UInt | Number of qubits. |
gammas | qmc.Vector[qmc.Float] | Cost-layer parameters, one per layer. |
betas | qmc.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:
| Name | Type | Description |
|---|---|---|
q | qmc.Vector[qmc.Qubit] | Qubit register. |
beta | qmc.Float | Variational parameter for the mixer layer. |
Returns:
qmc.Vector[qmc.Qubit] — qmc.Vector[qmc.Qubit]: Updated qubit register.