Skip to content

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:

BackendDescriptionUse Case
SimulatorLocal statevector simulationDevelopment and testing
OpenQASM 3Export to standard formatRunning on real hardware
IBM QuantumCloud quantum computersProduction 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:

kettle
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 fn

Multiple Shots ​

Run your circuit multiple times to see the probability distribution:

kettle
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 fn

Noise Simulation ​

The simulator can model realistic quantum hardware noise using physically accurate qubit models:

kettle
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 fn

Available qubit types:

TypeT1T2Description
ideal∞∞No noise (default)
transmon150μs100μsIBM-like superconducting qubits
trapped_ion∞1sIonQ-like trapped ion systems
cat100μs50μsBiased noise (phase >> bit flip)

You can override coherence times for any qubit type:

kettle
-- 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 fn

See 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:

kettle
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 fn

With exact = True, you get the exact expectation value with zero error:

kettle
-- 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
Modeexp.valueexp.std_error
quantum_simulator(shots = N)Statistical estimateNon-zero
quantum_simulator(exact = True)Exact from statevector0.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 ​

bash
# Generate OpenQASM from a Kettle program
kettle qasm my_program.ket

This outputs standard OpenQASM 3.0:

text
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:

  1. Export your circuit to OpenQASM 3
  2. Submit via IBM Quantum Platform or Qiskit
bash
# Export to file
kettle qasm my_algorithm.ket > circuit.qasm

# Then use IBM's tools to run it

Planned 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 ​

ScenarioRecommended Backend
Learning and experimentationquantum_simulator
Algorithm developmentquantum_simulator(shots = 1000)
Testing with realistic noisequantum_simulator(qubit_type = "transmon")
High-fidelity simulationquantum_simulator(qubit_type = "trapped_ion")
Running on real hardwareExport 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:

QubitsState Vector SizeMemory
101,024 amplitudes~16 KB
1532,768 amplitudes~512 KB
201,048,576 amplitudes~16 MB
2533,554,432 amplitudes~512 MB
301,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 reached

Future Improvements

  • Configurable limits: A max_qubits parameter 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 ​