Quantum Backends ​
Kettle supports multiple backends for executing quantum programs. This guide covers how to use each backend and export your circuits.
Overview ​
When you run a quantum program, Kettle needs somewhere to execute it. Backends handle this execution:
| Backend | Description | Use Case |
|---|---|---|
| Simulator | Local statevector simulation | Development and testing |
| OpenQASM 3 | Export to standard format | Running on real hardware |
| IBM Quantum | Cloud quantum computers | Production workloads |
Local Simulator ​
The default backend is a local statevector simulator. It runs entirely on your machine and supports up to 20 qubits.
Basic Usage ​
Use quantum_simulator in your using clause:
fn bell_pair() -> Tuple[Int, Int] with Quantum
(a, b) = bell()
(measure(a), measure(b))
end fn
fn main() -> Unit using quantum_simulator, file_io
result = bell_pair()
print(result)
end fnMultiple Shots ​
Run your circuit multiple times to see the probability distribution:
fn coin_flip() -> Int with Quantum
q = qubit()
q <- hadamard
measure(q)
end fn
fn main() -> Unit using quantum_simulator(shots = 1000), file_io
results = coin_flip() -- returns List[Int] with 1000 results
print(counts(results)) -- {"0": ~500, "1": ~500}
end fnNoise Simulation ​
The simulator can model realistic quantum hardware noise using physically accurate qubit models:
fn bell_pair() -> Tuple[Int, Int] with Quantum
(a, b) = bell()
(measure(a), measure(b))
end fn
-- Use transmon (superconducting) qubit model with realistic noise
fn main() -> Unit using quantum_simulator(qubit_type = "transmon", shots = 100), file_io
results = bell_pair()
print(counts(results)) -- occasionally see "01" or "10" due to noise
end fnAvailable qubit types:
| Type | T1 | T2 | Description |
|---|---|---|---|
ideal | ∞ | ∞ | No noise (default) |
transmon | 150μs | 100μs | IBM-like superconducting qubits |
trapped_ion | ∞ | 1s | IonQ-like trapped ion systems |
cat | 100μs | 50μs | Biased noise (phase >> bit flip) |
You can override coherence times for any qubit type:
-- Custom T1/T2 values (in microseconds)
fn main() -> Unit using quantum_simulator(qubit_type = "transmon", t1 = 200.0, t2 = 150.0), file_io
results = bell_pair()
print(counts(results))
end fnSee the Noise Models guide for detailed physics explanations.
Exact Mode ​
By default, expect_z uses statistical sampling to estimate expectation values, matching real hardware behavior. For debugging, you can enable exact mode to peek at the statevector directly:
fn energy() -> Expectation with Quantum
q = qubit()
q <- hadamard
(exp, q) = expect_z(q)
discard(q)
exp
end fn
-- Statistical mode (default): samples to estimate expectation
fn main() -> Unit using quantum_simulator(shots = 1), file_io
exp = energy()
print("E = ${to_string(exp.value)} +/- ${to_string(exp.std_error)}")
end fnWith exact = True, you get the exact expectation value with zero error:
-- Exact mode: computes directly from statevector
fn main() -> Unit using quantum_simulator(exact = True), file_io
exp = energy()
print("E = ${to_string(exp.value)}") -- exp.std_error is always 0.0
end fn| Mode | exp.value | exp.std_error |
|---|---|---|
quantum_simulator(shots = N) | Statistical estimate | Non-zero |
quantum_simulator(exact = True) | Exact from statevector | 0.0 |
Use exact = True when you need precise values for debugging or verification. Use the default statistical mode when you want realistic behavior matching real quantum hardware.
OpenQASM 3 Export ​
Kettle can export your quantum circuits to OpenQASM 3.0, the standard format accepted by most quantum hardware providers.
Command Line ​
# Generate OpenQASM from a Kettle program
kettle qasm my_program.ketThis outputs standard OpenQASM 3.0:
OPENQASM 3;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
cx q[0], q[1];
c[0] = measure q[0];
c[1] = measure q[1];IBM Quantum ​
Coming Soon
IBM Quantum backend integration is planned but not yet implemented. The infrastructure is ready—Kettle generates valid OpenQASM 3.0 that IBM systems accept.
Current Workflow ​
Until native IBM support is added, use the OpenQASM export:
- Export your circuit to OpenQASM 3
- Submit via IBM Quantum Platform or Qiskit
# Export to file
kettle qasm my_algorithm.ket > circuit.qasm
# Then use IBM's tools to run itPlanned Features ​
The upcoming IBM backend will support:
- Direct execution on IBM quantum hardware
- Automatic transpilation to device basis gates
- Job queuing and result retrieval
- Device topology-aware compilation
Choosing a Backend ​
| Scenario | Recommended Backend |
|---|---|
| Learning and experimentation | quantum_simulator |
| Algorithm development | quantum_simulator(shots = 1000) |
| Testing with realistic noise | quantum_simulator(qubit_type = "transmon") |
| High-fidelity simulation | quantum_simulator(qubit_type = "trapped_ion") |
| Running on real hardware | Export to OpenQASM 3 |
Simulator Limits ​
The local simulator supports up to 20 qubits by default. This is a practical limit based on memory—statevector simulation requires storing 2^n complex amplitudes:
| Qubits | State Vector Size | Memory |
|---|---|---|
| 10 | 1,024 amplitudes | ~16 KB |
| 15 | 32,768 amplitudes | ~512 KB |
| 20 | 1,048,576 amplitudes | ~16 MB |
| 25 | 33,554,432 amplitudes | ~512 MB |
| 30 | 1,073,741,824 amplitudes | ~16 GB |
If you exceed the limit, you'll see an error like:
Runtime error: cannot allocate qubit: maximum of 20 qubits reachedFuture Improvements
- Configurable limits: A
max_qubitsparameter is planned to allow 25-30 qubits on machines with sufficient RAM - GPU acceleration: A GPU-accelerated simulator backend is under consideration for even larger circuits
For circuits exceeding simulator capacity, export to OpenQASM 3 and use cloud backends like IBM Quantum.
Next Steps ​
- Qubits - Understanding qubit states
- Gates - Available quantum operations
- Measurement - Extracting results