Metadata-Version: 2.4
Name: ellis-qec
Version: 0.1.0
Summary: ELLIS: Efficient Loss and Leakage Invariant-reference Simulation. Exact masked Pauli-frame sampling of Clifford circuits with atom loss, and common-reference certificates.
Keywords: quantum error correction,stabilizer simulation,atom loss,leakage,stim,neutral atoms
Author: Yuewen Hou, Gokul Subramanian Ravi
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Physics
Project-URL: Repository, https://github.com/isaachyw/ELLIS
Project-URL: Documentation, https://github.com/isaachyw/ELLIS/blob/main/docs/sampling.md
Project-URL: Paper, https://arxiv.org/abs/2611.26173
Requires-Python: >=3.12
Requires-Dist: numpy>=2.2
Requires-Dist: stim<2,>=1.16
Requires-Dist: clifft<0.14,>=0.13
Provides-Extra: sinter
Requires-Dist: sinter<2,>=1.15; extra == "sinter"
Description-Content-Type: text/markdown

<p align="center">
  <img src="https://raw.githubusercontent.com/isaachyw/ELLIS/main/docs/assets/logos/ellis-logo-light.png" width="220" alt="ELLIS logo">
</p>

# ELLIS: Extremely Fast Quantum Circuit Simulation under Qubit Loss and Leakage

[![arXiv](https://img.shields.io/badge/Paper-2611.26173-B31B1B?style=flat-square)](https://arxiv.org/abs/2611.26173)

ELLIS (Efficient Loss and Leakage Invariant-reference Simulation) samples Clifford circuits with qubit loss and leakage
exactly. It uses a masked Pauli frame and one shared reference record, so each shot does not need its own
tableau reference.

- **One sampling API.** `ellis.compile_sampler` certifies the circuit. When one reference is proven exact, it samples
  with the C++ masked frame `ellis._core.MaskFrameSampler`, built on Stim's `FrameSimulator`. Otherwise it samples
  with Clifft's noncomputational sampler in online mode. Both drop a lost qubit's later gates and read its
  measurements as heralded fair coins.
- **Common-reference certificates.** `ellis.certify` proves that one reference is exact for every loss
  pattern by frame-CSS relabelling or closed S/CZ blocks, or returns a signed-parity contradiction that
  shows no such reference exists. Pass the circuit with its noise injected: losses and reloads happen at its
  `I_ERROR[loss]` and `I_ERROR[reload]` markers. A circuit with neither marker is certified under
  `PESSIMISTIC` (loss after every operation, |0> reload anywhere), so its reference holds under every loss
  model. An explicit `LossModel` overrides both. `frame_css` decides frame-CSS exactly; a circuit outside the
  assumptions that make the decision exact (classical feedback, multi-qubit measurements, a prefix with
  too many open frame choices) gets verdict `"outside-assumptions"` instead.

## Loss instructions

ELLIS reads Stim circuits and adds two tagged `I_ERROR` instructions. Stim parses both and ignores them.

| Instruction                 | Meaning                                                                                                           |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `I_ERROR[loss](p) q...`   | Each atom `q` is lost with probability `p`. Its later gates are dropped and its readouts become fair coins.   |
| `I_ERROR[reload](p) q...` | Each empty slot `q` gets a fresh atom in \|0> with probability `p` (default 1). A present atom is left alone. |

A reload happens only where its marker stands. To reload at a reset, write the marker just before it:

```
CX 0 1
I_ERROR[loss](0.001) 0 1
M 1
I_ERROR[reload] 1
R 1
```

## Sampling performance

<p>
  <img src="https://raw.githubusercontent.com/isaachyw/ELLIS/main/docs/assets/performance/sampling_single_core.png" width="49%" alt="Single-core sampling throughput for PPVM, Clifft online, and ELLIS on BB144 memory and the distance-7 transversal CNOT with atom loss.">
  <img src="https://raw.githubusercontent.com/isaachyw/ELLIS/main/docs/assets/performance/sampling_multicore_128.png" width="49%" alt="128-thread sampling throughput for PPVM, Clifft online, and ELLIS on BB144 memory and the distance-7 transversal CNOT with atom loss.">
</p>

## Install

```bash
uv add ellis-qec             # or: pip install ellis-qec
uv add "ellis-qec[sinter]"   # also sinter, for ellis.sinter
```

The distribution is `ellis-qec` and the import name is `ellis`. It installs Stim and Clifft with it. Wheels are
available for CPython 3.12, 3.13, and 3.14 on Linux x86-64 (manylinux_2_28) and macOS arm64 (macOS 15 or later, as
for Clifft). An x86-64 wheel contains two builds of the C++ core, one for CPUs with AVX2 and one for CPUs without it.
`import ellis` loads the faster build that the CPU runs, and `ellis._core.VARIANT` names it.

### Build from source

```bash
uv sync                  # builds ellis._core with CMake (fetches Stim 1.16.0 once)
uv sync --extra sinter   # also sinter, for ellis.sinter
```

The build needs a C++20 compiler: GCC 10 or newer, or Apple clang. A source build compiles one variant of the core,
the best one for the machine that runs the build (AVX2, SSE2, or 64-bit words on arm64). To build both x86-64 wheel
variants, run `uv sync -C cmake.define.ELLIS_SIMD="avx2;sse2"`, and then use `uv run --no-sync`, because a plain
`uv run` rebuilds with the default settings. To build
without network access, add `-C cmake.define.FETCHCONTENT_SOURCE_DIR_STIM=/path/to/Stim-1.16.0`. On Perlmutter,
CMake selects the `gcc-native` module's `g++` automatically. On a shared cluster, run the first build and the tests on
a compute node.

## Use

```python
import ellis
from ellis.noise import surface_memory

circuit = surface_memory(d=5, rounds=5, p=1e-3, p_loss=1e-3)  # I_ERROR[loss](p) marks loss sites
sampler = ellis.compile_sampler(circuit, seed=1)  # certifies: verdict "proven", method "frame-css"
sampler.method                                    # "frame"
r = sampler.sample(10**4)                         # r.measurements, r.detectors, r.observables, r.heralds
r = sampler.sample(10**6, bit_packed=True, threads=8)  # the same fields, bit-packed, on 8 threads
```

| `compile_sampler` route                                  | Sampler                                                                              |
| -------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| `method="auto"`, certificate proven without gauge Paulis | C++ masked frame with the certified reference                                        |
| `method="auto"`, any other certificate                   | Clifft online                                                                        |
| `method="frame"`                                         | C++ masked frame; Stim's reference (unverified) unless a proven certificate is given |
| `method="clifft"`                                        | Clifft online                                                                        |

`method="auto"` certifies with `ellis.certify.certify(circuit, model=MARKED, **certify_options)` unless
`certificate=` is given: sampling loses atoms only at the markers.
`sample` returns a `SampleResult` with all four fields from one simulation pass; `bit_packed=True` uses Stim's
layout. Detection events are relative to the noiseless reference sample, as in Stim.
[docs/sampling.md](https://github.com/isaachyw/ELLIS/blob/main/docs/sampling.md) is the full reference: supported operations, loss semantics, routing, result
layout, heralds, and performance.

The sinter adapter `ellis.sinter` is under development.

## Layout

| Path                     | Contents                                                                                                                                                                      |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `src/ellis/frame/`       | C++ masked frame: program compilation, `stim::FrameSimulator` with alive masks, batched sampler                                                                               |
| `src/python/`            | `bindings.cc` (the `ellis._core_<variant>` modules), `cpu.cc` (`ellis._cpu`, which picks the variant)                                                                         |
| `src/python/ellis/`      | `sampler` (`compile_sampler`), `_clifft` (Clifft route), `frame` (loss semantics), `certify/` (`frame_css`, `blocks`, `constraints`), `noise`, `sinter`, `gf2`, `check_exact` |
| `tests/python/`          | tests against Stim on explicit lossy circuits and between the frame and Clifft routes; fixtures in `tests/fixtures/`                                                          |
| `tools/`                 | `bench/bench_frame.py` (masked frame and Stim speed), `classify_lightstim.py` (certify each LightStim protocol), fixture exporters                                            |
| `cmake/`                 | Stim fetch, compiler selection, SIMD variants                                                                                                                                 |
| `.github/workflows/`     | `test.yml` (the tests on both x86-64 variants), `wheels.yml` (sdist and wheels; publishes to TestPyPI and PyPI on a `v*` tag, see `RELEASING.md`)                             |

## Test

```bash
uv run pytest -n 8
uv run python -m ellis.check_exact 'tests/fixtures/lightstim/*.stim'   # sampler vs Stim on random loss patterns
uv run python tools/classify_lightstim.py --benchmark                  # paper App. C classification
```

## License

Apache-2.0. ELLIS includes [Stim](https://github.com/quantumlib/Stim), which is also Apache-2.0.

## Citation

If you find ELLIS useful in your work, please cite our paper:

```bibtex
@misc{hou2026ellis,
      title={Ellis: Extremely Fast Quantum Circuit Simulation under Qubit Loss and Leakage},
      author={Yuewen Hou and Gokul Subramanian Ravi},
      year={2026},
      eprint={2611.26173},
      archivePrefix={arXiv},
      primaryClass={quant-ph},
      url={https://arxiv.org/abs/2611.26173},
}
```
