Repository navigation
01 Introduction
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-langperforms compilation only. The methodQPU.exec_circuitdoes 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.
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:
- Virtual-to-physical qubit mapping.
- Insertion of SWAP gates to satisfy hardware adjacency constraints.
- Decomposition of compound gates (u2, u3, controlled-U, multi-controlled gates) into elementary primitives.
- Optional optimization at the ideal-gate level (peephole, commutation, template rewrites).
- Transpilation into the native gate set (rx, ry, sqiSWAP, measure).
- Optional optimization at the native-gate level (rotation fusion, redundant-sandwich elision).
Each stage is documented as a distinct unit in 08 Pipeline Architecture.
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:
- Direct gate emission, described in 03 Writing Programs with Gates.
- Algorithmic blocks, described in 04 Writing Programs with Blocks.
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.
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.
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.
-
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. -
qpu.qregister(2)allocates a two-qubit quantum register on the loaded QPU. -
CRegister(size=2)allocates a two-bit classical register for measurement results. - The
with Circuit(...)context manager opens a circuit-building scope. The compilation pipeline runs at scope exit. -
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. -
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. -
c >> qpu.isa.measure(tgs=[0, 1])appends measurement of both qubits into the classical register. -
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.
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.
- For installation instructions: 02 Setup.
- For the gate-level programming API: 03 Writing Programs with Gates.
- For the block-level programming API: 04 Writing Programs with Blocks.
- For additional worked examples: 05 Examples.
- For optimization configuration: 10 Optimizations.
- 09 Glossary for terminology used across the wiki.
- 13 Limitations & Roadmap for known gaps, including the backend status.