Quantum Trajectory Filter — runtime post-selection conditioning for quantum circuits
Project description
qgate — Quantum Trajectory Filter
Runtime post-selection conditioning for quantum circuits.
This package explores runtime trajectory filtering concepts from US Patent Application Nos. 63/983,831 & 63/989,632 and Israeli Patent Application No. 326915. The underlying invention is patent pending.
Installation
pip install qgate # core (numpy, pydantic, typer)
pip install qgate[csv] # + pandas for CSV logging
pip install qgate[parquet] # + pandas + pyarrow for Parquet logging
pip install qgate[qiskit] # + IBM Qiskit adapter
pip install qgate[cirq] # + Google Cirq adapter (stub)
pip install qgate[pennylane] # + PennyLane adapter (stub)
pip install qgate[all] # everything
Note: pandas is not required for core filtering; it is only needed if you write logs to CSV or Parquet. The default JSONL logger uses only the standard library.
For development:
git clone https://github.com/ranbuch/qgate-trajectory-filter.git
cd qgate-trajectory-filter/packages/qgate
pip install -e ".[dev]"
Quick Start
New API — TrajectoryFilter
from qgate import TrajectoryFilter, GateConfig
from qgate.adapters import MockAdapter
config = GateConfig(
n_subsystems=4,
n_cycles=2,
shots=1024,
variant="score_fusion",
)
adapter = MockAdapter(error_rate=0.05, seed=42)
tf = TrajectoryFilter(config, adapter)
result = tf.run()
print(f"Accepted: {result.accepted_shots}/{result.total_shots}")
print(f"P_accept: {result.acceptance_probability:.4f}")
print(f"TTS: {result.tts:.2f}")
Dynamic Thresholding
from qgate import GateConfig, DynamicThresholdConfig, TrajectoryFilter
from qgate.adapters import MockAdapter
config = GateConfig(
shots=200,
dynamic_threshold=DynamicThresholdConfig(
enabled=True, baseline=0.65, z_factor=1.0,
),
)
tf = TrajectoryFilter(config, MockAdapter(seed=42))
for _ in range(10):
result = tf.run()
print(f"threshold={tf.current_threshold:.4f} P_acc={result.acceptance_probability:.4f}")
Galton Adaptive Thresholding
Distribution-aware gating that maintains a stable acceptance fraction by adapting to the empirical score distribution. Supports quantile and robust z-score sub-modes.
from qgate import GateConfig, DynamicThresholdConfig, TrajectoryFilter
from qgate.adapters import MockAdapter
config = GateConfig(
shots=1000,
variant="score_fusion",
dynamic_threshold=DynamicThresholdConfig(
mode="galton", # distribution-aware adaptive gating
window_size=1000, # per-shot rolling window
min_window_size=100, # warmup period
target_acceptance=0.05, # target ~5% acceptance
robust_stats=True, # MAD-based sigma (outlier-resilient)
use_quantile=True, # empirical quantile (recommended)
),
)
tf = TrajectoryFilter(config, MockAdapter(error_rate=0.1, seed=42))
result = tf.run()
print(f"Threshold: {tf.current_threshold:.4f}")
print(f"Accepted: {result.accepted_shots}/{result.total_shots}")
# Galton telemetry in result.metadata["galton"]
CLI
qgate version
qgate validate config.json
qgate run config.json --adapter mock --seed 42
qgate run config.json --adapter mock --output results.jsonl
qgate run config.json --adapter mock --error-rate 0.1 --verbose
qgate run config.json --adapter mock --quiet # suppress info logs
qgate adapters # list installed adapters
qgate schema # print JSON Schema for GateConfig
Legacy API (backward compatible)
from qgate import decide_hierarchical, MultiRateMonitor
from qgate.conditioning import ParityOutcome
outcome = ParityOutcome(4, 2, [[0, 0, 1, 0], [0, 0, 0, 0]])
assert decide_hierarchical(outcome, k_fraction=0.75) is True
Architecture
qgate/
├── __init__.py # Public API re-exports (backward-compatible)
├── config.py # Pydantic v2 config models (GateConfig, FusionConfig, …)
│ All models are frozen & extra="forbid"
├── filter.py # TrajectoryFilter — main API class
│ Vectorised scoring via score_batch()
├── scoring.py # Fuse-scores, score_outcome, score_batch (NumPy)
├── threshold.py # Dynamic threshold: rolling z-score + Galton adaptive
├── run_logging.py # JSON-Lines / CSV / Parquet structured logging
│ RunLogger is a context manager; Parquet is buffered
├── cli.py # Typer CLI (run, validate, schema, adapters, version)
├── compat/ # Backward-compatible wrappers
│ ├── conditioning.py # ParityOutcome (ndarray), decision rules
│ └── monitors.py # MultiRateMonitor, should_abort_batch
├── conditioning.py # Re-export from compat/conditioning
├── monitors.py # Re-export from compat/monitors
└── adapters/
├── base.py # BaseAdapter ABC + MockAdapter
├── registry.py # list_adapters() / load_adapter()
├── qiskit_adapter.py # Full Qiskit implementation (copy-safe)
├── grover_adapter.py # Grover vs TSVF-Chaotic Grover adapter
├── qaoa_adapter.py # QAOA vs TSVF-QAOA MaxCut adapter
├── vqe_adapter.py # VQE vs TSVF-VQE (TFIM) adapter
├── qpe_adapter.py # QPE vs TSVF-QPE Phase Estimation adapter
├── cirq_adapter.py # Stub
└── pennylane_adapter.py # Stub
Key Design Decisions
- ParityOutcome stores an
np.ndarray— shape(n_cycles, n_subsystems), dtypeint8. Lists are coerced on construction. - All configuration is immutable —
GateConfigand sub-models are Pydanticfrozenmodels. Create a new config to change parameters. - pandas is optional — only imported lazily when CSV/Parquet logging is used. Core filtering needs only numpy + pydantic.
- Structured logging — all modules use
logging.getLogger("qgate.*")so users can control verbosity with standard Python logging.
Conditioning Strategies
| Strategy | Config | Scaling |
|---|---|---|
| Global | variant="global" |
Exponential decay at N ≥ 2 |
| Hierarchical k-of-N | variant="hierarchical", k_fraction=0.9 |
O(1) — scales to N = 64+ |
| Score Fusion | variant="score_fusion" |
Most robust on real hardware |
Algorithm-Specific TSVF Adapters
qgate ships with four algorithm-specific adapters that apply trajectory filtering to canonical quantum algorithms. Each adapter builds both a standard circuit and a TSVF variant (with chaotic perturbation + ancilla phase/parity probe), runs them, and extracts algorithm-specific metrics.
| Adapter | Algorithm | Entry Point | IBM Validated |
|---|---|---|---|
GroverTSVFAdapter |
Grover search | grover_tsvf |
✅ IBM Fez — 7.3× advantage |
QAOATSVFAdapter |
QAOA MaxCut | qaoa_tsvf |
✅ IBM Torino — 1.88× advantage |
VQETSVFAdapter |
VQE for TFIM | vqe_tsvf |
✅ IBM Fez — barren plateau avoidance |
QPETSVFAdapter |
QPE phase est. | qpe_tsvf |
✅ IBM Fez — phase coherence study |
Utility-Scale Validation (IBM Torino, 133 Qubits)
The VQETSVFAdapter has been stress-tested at utility scale on IBM Torino
(133 physical qubits, 16,709 ISA gate depth). At 37× T₁ decoherence, the
Galton filter achieved a negative cooling delta (Δ = −0.080), extracting
correlated thermodynamic signal from ~99% thermal noise. See the
simulations/tfim_127q directory for full
reproduction steps and raw data.
from qgate.adapters.grover_adapter import GroverTSVFAdapter
from qgate.adapters.qaoa_adapter import QAOATSVFAdapter
from qgate.adapters.vqe_adapter import VQETSVFAdapter
from qgate.adapters.qpe_adapter import QPETSVFAdapter
Run Logging
from qgate import TrajectoryFilter, GateConfig
from qgate.adapters import MockAdapter
from qgate.run_logging import RunLogger
config = GateConfig(shots=500, variant="score_fusion")
tf = TrajectoryFilter(config, MockAdapter(seed=42))
with RunLogger("results.jsonl") as logger:
result = tf.run()
logger.log(result)
# For CSV: RunLogger("results.csv") — requires pip install qgate[csv]
# For Parquet: RunLogger("results.parquet") — requires pip install qgate[parquet]
Each logged record includes a deterministic run ID (SHA-256 prefix), full config JSON, acceptance probability, TTS, and a UTC timestamp.
Running Tests
cd packages/qgate
pip install -e ".[dev]"
pytest -v tests/ # 376 tests, ~3 s
pytest --cov=qgate tests/ # with coverage
License
QGATE Source Available Evaluation License v1.2 — see LICENSE.
Academic research, peer review, and internal corporate evaluation are freely permitted. Commercial deployment requires a separate license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qgate-0.6.0.tar.gz.
File metadata
- Download URL: qgate-0.6.0.tar.gz
- Upload date:
- Size: 1.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
339f3ebca12e51c1d34b6ca4a2f3588d5e36fcaf2c096ae6654cb3dcbd620c4e
|
|
| MD5 |
70820925683c1271a0a96bd0a20285cd
|
|
| BLAKE2b-256 |
5c80cf1d3ce4f4f3e8e8cbc9f9f959c9c82ddde888a123144cef17d1e6668a5b
|
File details
Details for the file qgate-0.6.0-py3-none-any.whl.
File metadata
- Download URL: qgate-0.6.0-py3-none-any.whl
- Upload date:
- Size: 78.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4c62aa5322e88aa5f67620ae6ef83741897aea9552ff035cee7164597f99305
|
|
| MD5 |
e512e66ceaf4cdd5ce59f51e779c6de4
|
|
| BLAKE2b-256 |
657633b2dbd11c243b5b672f506f92bfdc8561c39a35302c0126ce5cd836ba4c
|