Skip to content

Circuit primitives

hqnn_forge.circuits

hqnn_forge.circuits

Reusable, device-agnostic VQC ansatz primitives.

These functions are pure quantum functions — they are intended to be called inside a QNode context (i.e. called within a function decorated with @qml.qnode). They apply in-place gate sequences and return nothing.

Exported symbols

strongly_entangling_layer CNOT ring + per-qubit Rot(φ, θ, ω) block. hardware_efficient_layer CZ ladder + per-qubit RY(θ) block (lower CNOT depth).

These are the blocks the encoding layers run, selected by their entangler argument through hqnn_forge.encoding.angle_embedding.apply_variational_layers:

  • entangler="ring" (the default) is strongly_entangling_layer per layer. Despite the name, it is not entangler="strongly_entangling", which is PennyLane's qml.StronglyEntanglingLayers (Rot first, then a CNOT ring of growing range).
  • entangler="hardware_efficient" is hardware_efficient_layer per layer.

hardware_efficient_layer

hardware_efficient_layer(weights: Tensor, n_qubits: int) -> None

Apply one hardware-efficient block to the current quantum circuit.

Gate count per call:

  • n_qubits - 1 CZ gates (nearest-neighbour ladder)
  • n_qubits RY gates (1 trainable parameter each)

Parameters:

Name Type Description Default
weights Tensor

Rotation angles tensor of shape (n_qubits,). weights[i] is the RY angle θ_i applied to qubit i.

required
n_qubits int

Number of qubits. weights must have shape (n_qubits,).

required

Raises:

Type Description
ValueError

If weights.shape != (n_qubits,). A (n_qubits, 3) row of a Rot weight tensor would otherwise broadcast RY silently.

strongly_entangling_layer

strongly_entangling_layer(weights: Tensor, n_qubits: int) -> None

Apply one strongly-entangling block to the current quantum circuit.

Gate count per call:

  • n_qubits CNOT gates (entangling ring)
  • n_qubits Rot gates (3 parameters each → 3 * n_qubits trainable angles)

Parameters:

Name Type Description Default
weights Tensor

Rotation angles tensor of shape (n_qubits, 3). Each row [φ_i, θ_i, ω_i] parameterises the Euler rotation Rz(ω_i) · Ry(θ_i) · Rz(φ_i) applied to qubit i.

required
n_qubits int

Number of qubits. Must match weights.shape[0].

required

Raises:

Type Description
ValueError

If weights.shape != (n_qubits, 3).