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

Quantum Phase Estimation implementation.

Example:

@qmc.qkernel
def p_gate(q: qmc.Qubit, theta: float) -> qmc.Qubit:
    return qmc.p(q, theta)

@qmc.qkernel
def circuit(theta: float) -> qmc.Float:
    counting = qmc.qubit_array(3, name="counting")
    target = qmc.qubit(name="target")
    target = qmc.x(target)

    phase = qmc.qpe(target, counting, p_gate, theta=theta)
    return qmc.measure(phase)

Overview

FunctionDescription
for_loopCreate a traced for loop in the Qamomile frontend.
qpeQuantum Phase Estimation.
ClassDescription
QKernelLikeDescribe the frontend surface required by compiler entrypoints.

Functions

for_loop [source]

def for_loop(
    start,
    stop,
    step = 1,
    var_name: str = '_loop_idx',
    *,
    captures: tuple[tuple[str, Any], ...] = (),
) -> Generator[UInt, None, None]

Create a traced for loop in the Qamomile frontend.

Parameters:

NameTypeDescription
starttyping.AnyInclusive loop start as an integer or UInt.
stoptyping.AnyExclusive loop stop as an integer or UInt.
steptyping.AnyNonzero loop step as an integer or UInt. Defaults to 1.
var_namestrDisplay name of the loop variable. Defaults to "_loop_idx".
capturestuple[tuple[str, typing.Any], ...]Statically analyzed read-only body inputs. Defaults to an empty tuple.

Yields:

UInt — The loop iteration variable (can be used as array index)

Raises:

Example:

@QKernel
def my_kernel(qubits: Array[Qubit, Literal[3]]) -> Array[Qubit, Literal[3]]:
    for i in qm.range(3):
        qubits[i] = h(qubits[i])
    return qubits

@QKernel
def my_kernel2(qubits: Array[Qubit, Literal[5]]) -> Array[Qubit, Literal[5]]:
    for i in qm.range(1, 4):  # i = 1, 2, 3
        qubits[i] = h(qubits[i])
    return qubits

Classical scalar updates (total = total + i) become explicit RegionArg records on the ForOperation: the loop enters with the initializer, each iteration reads the previous iteration’s value, and post-loop code reads the loop result.


qpe [source]

def qpe(
    target: Qubit,
    counting: Vector[Qubit],
    unitary: QKernelLike,
    **params: Any = {},
) -> QFixed

Quantum Phase Estimation.

Estimates the phase φ where U|ψ> = e^{2πiφ}|ψ>.

Parameters:

NameTypeDescription
targetQubitEigenstate |psi> of the unitary.
countingVector[Qubit]Register that stores the phase estimate.
unitaryQKernelLikeUnitary qkernel to control.
**paramsAnyClassical parameters forwarded to the unitary.

Returns:

QFixed — Phase register as quantum fixed-point number

Classes

QKernelLike [source]

class QKernelLike(Protocol)

Describe the frontend surface required by compiler entrypoints.

This protocol is intentionally structural. It lets decorator-created composites reuse the qkernel inspection and build interface without making them inherit from QKernel or exposing the compiler-facing callable descriptor model as a frontend concept.

Attributes

Methods

build
def build(self, parameters: list[str] | None = None, **kwargs: Any = {}) -> Block

Build a traced body block.

Parameters:

NameTypeDescription
parameterslist[str] | NoneRuntime parameter names to preserve. Defaults to None.
**kwargsAnyCompile-time bindings for non-parameter arguments.

Returns:

Block — Traced hierarchical body block.