Skip to content

01 Introduction

Santiago Nunez-Corrales edited this page May 19, 2026 · 3 revisions

Summary

lccfq-lang is a research compiler for quantum circuits implemented in Python. Programs are written using a Python API and lowered to a native gate set targeted at superconducting hardware. A backend layer is responsible for execution; at present, the backend layer is a stub.

This page describes the project's purpose, its position in the quantum-software stack, and presents a minimal worked example. Installation instructions are in 02 Setup.

Backend status. lccfq-lang performs compilation only. The method QPU.exec_circuit does not currently communicate with physical hardware. All compilation behavior described in this wiki is fully implemented and tested; execution semantics are not. References to "running" a circuit refer to lowering it to the point at which hardware would execute it.


Purpose

The compiler accepts a quantum program expressed in terms of ideal gates and produces an equivalent program expressed in the XYiSW native gate set. The transformation comprises six stages:

  1. Virtual-to-physical qubit mapping.
  2. Insertion of SWAP gates to satisfy hardware adjacency constraints.
  3. Decomposition of compound gates (u2, u3, controlled-U, multi-controlled gates) into elementary primitives.
  4. Optional optimization at the ideal-gate level (peephole, commutation, template rewrites).
  5. Transpilation into the native gate set (rx, ry, sqiSWAP, measure).
  6. Optional optimization at the native-gate level (rotation fusion, redundant-sandwich elision).

Each stage is documented as a distinct unit in 08 Pipeline Architecture.


Scope

lccfq-lang is a focused compiler for a single hardware family. It is not a general-purpose quantum software development kit. The intended use cases are:

  • Investigating compilation-pipeline behavior on small to medium circuits.
  • Generating native-gate sequences for the XYiSW gate set.
  • Extending the compiler with custom optimization passes or block libraries.

Programs are written at two levels of abstraction:

The native gate set is built around sqiSWAP (the square root of iSWAP), which is a perfect entangler natural to XY-coupled superconducting qubits. The full native vocabulary and the decompositions used to reach it from ideal gates are documented in 07 Native Gates.


Pipeline summary

A program submitted to the compiler passes through the following stages in order. Each stage may be inspected by setting last_pass on the QPU constructor.

Stage Function Input Output
mapped Virtual-to-physical qubit mapping Instruction (virtual) Instruction (physical)
swapped SWAP insertion for non-adjacent two-qubit gates Instruction Instruction (with SWAPs)
expanded Compound-gate decomposition Instruction Instruction (elementary)
arch_optimized Ideal-gate optimization Instruction Instruction (optimized)
transpiled Translation to native gate set Instruction Gate
mach_optimized Native-gate optimization Gate Gate (optimized)

The default behavior is to run all six stages. Detailed semantics are in 08 Pipeline Architecture.


Worked example: Bell-state preparation

The following program, taken verbatim from examples/bell_state.py, prepares a two-qubit Bell state.

from lccfq_lang import QPU, CRegister, Circuit


def bell_state():
    qpu = QPU(filename="config/default.toml")
    qreg = qpu.qregister(2)
    creg = CRegister(size=2)

    with Circuit(qreg, creg, qpu, shots=1000) as c:
        c >> qpu.isa.h(tg=0)
        c >> qpu.isa.cx(ct=0, tg=1)
        c >> qpu.isa.measure(tgs=[0, 1])

    print(creg.frequencies())


if __name__ == "__main__":
    bell_state()

Each statement is explained below.

  1. QPU(filename="config/default.toml") loads a QPU description from a TOML configuration file. The default configuration describes a four-qubit linear-topology device. The configuration schema is documented in 06 QPU Configuration.
  2. qpu.qregister(2) allocates a two-qubit quantum register on the loaded QPU.
  3. CRegister(size=2) allocates a two-bit classical register for measurement results.
  4. The with Circuit(...) context manager opens a circuit-building scope. The compilation pipeline runs at scope exit.
  5. c >> qpu.isa.h(tg=0) appends a Hadamard gate on qubit 0 to the circuit. The >> operator is the circuit-build operator; qpu.isa.<gate>(...) constructs an instruction from the instruction-set adapter. The complete gate vocabulary is documented in 03 Writing Programs with Gates.
  6. c >> qpu.isa.cx(ct=0, tg=1) appends a controlled-NOT gate with control on qubit 0 and target on qubit 1. The combination of Hadamard and controlled-NOT entangles the two qubits.
  7. c >> qpu.isa.measure(tgs=[0, 1]) appends measurement of both qubits into the classical register.
  8. creg.frequencies() returns the per-outcome frequency dictionary populated by the backend after execution.

On a functional backend, the expected outcome distribution is approximately 50 percent |00⟩ and 50 percent |11⟩, corresponding to the entangled Bell state. With the current stub backend, the returned dictionary is empty; the compiler has performed its work, and no execution has occurred.


Inspecting compiler output

The compilation pipeline may be terminated at any stage by passing the last_pass argument to the QPU constructor:

qpu = QPU(filename="config/default.toml", last_pass="transpiled")

When the circuit context exits, the pipeline runs through the transpiled stage and terminates. The intermediate program is then accessible for inspection. Per-pass telemetry — gate counts, circuit depth, pass execution time — is available by setting report=True on the Circuit constructor, which populates c.opt_report. The report format is documented in 10 Optimizations.


Where to read next

See also

Clone this wiki locally