Metadata-Version: 2.4
Name: qec-diverse-circuits
Version: 0.1.0
Summary: A Gymnasium-compatible RL environment that generates quantum circuits diverse in QEC/noise-characterization-relevant properties (non-Clifford content, entangling-gate type/density, connectivity, depth/idle-time).
License: MIT License
        
        Copyright (c) 2026 qec-diverse-circuits
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: qiskit<2.0,>=1.2
Requires-Dist: gymnasium<1.1,>=0.29
Requires-Dist: numpy<2.0,>=1.24
Requires-Dist: networkx<4.0,>=3.0
Requires-Dist: netlsd<2.0,>=1.0.2
Requires-Dist: stable-baselines3<3.0,>=2.0
Requires-Dist: sb3-contrib<3.0,>=2.0
Requires-Dist: torch<3.0,>=2.0
Requires-Dist: tensorboard<3.0,>=2.14
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Dynamic: license-file

# qec-diverse-circuits

A Gymnasium-compatible RL environment that generates Qiskit circuits diverse in properties relevant to quantum error correction (QEC) and noise characterization: non-Clifford content, entangling-gate type and density, connectivity, depth, and idle time.

## Why these properties

Circuits that differ only in generic shape don't necessarily exercise different hardware error behavior. These specific properties do:

- **Non-Clifford content** (ratio, T-gate count) — determines whether a circuit needs magic-state resources, a different error regime than Clifford-only circuits.
- **Entangling-gate type and density** — different two-qubit gates stress different crosstalk channels.
- **Connectivity** — local vs. long-range interactions exercise different qubit pairs.
- **Depth and idle time** — proxy for decoherence exposure.

## Results

Validated on N=1000 generated circuits: the trained agent correlates with these properties at r=+0.574, beating a random baseline (r=0.554±0.023 across 5 seeds) by a small but real margin. It is not a large improvement — treat it as a modest, reproducible edge, not a dramatic one.

## Install

```bash
pip install qec-diverse-circuits
```

For local development:

```bash
pip install -e .
```

## Usage

```python
from qec_diverse_circuits import DiverseCircuitGenerationEnv

env = DiverseCircuitGenerationEnv(max_qubits=7, max_gates=13, target_circuits=30)
obs, info = env.reset()
terminated = truncated = False
while not (terminated or truncated):
    action = env.action_space.sample()  # replace with a trained policy
    obs, reward, terminated, truncated, info = env.step(action)

for circuit, qec_properties in env.all_circuits:
    print(qec_properties)
```

### Training

```python
from qec_diverse_circuits.base_generator import BaseGenerator

generator = BaseGenerator(model_dir="./models")
generator.train()
circuits = generator.generate()
```

No pretrained checkpoint is published yet — `generate()` trains one from scratch (~7e5 timesteps) the first time it's called if `model_dir` is empty. `train()` and `generate()` use SB3's `VecNormalize` internally, so the observation/reward scaling a generated checkpoint is loaded with always matches what it was trained under.

## Tests

```bash
pytest tests/
```

## Changelog

See [CHANGELOG.md](CHANGELOG.md). This project follows [Semantic Versioning](https://semver.org/).

## Citation

If you use this package in research, please cite it — see [CITATION.cff](CITATION.cff).

## License

MIT — see [LICENSE](LICENSE).
