qb-compiler 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. qb_compiler-0.1.0/.gitignore +31 -0
  2. qb_compiler-0.1.0/.pre-commit-config.yaml +15 -0
  3. qb_compiler-0.1.0/.readthedocs.yml +16 -0
  4. qb_compiler-0.1.0/CHANGELOG.md +37 -0
  5. qb_compiler-0.1.0/CODE_OF_CONDUCT.md +54 -0
  6. qb_compiler-0.1.0/CONTRIBUTING.md +212 -0
  7. qb_compiler-0.1.0/Dockerfile +11 -0
  8. qb_compiler-0.1.0/LICENSE +190 -0
  9. qb_compiler-0.1.0/Makefile +37 -0
  10. qb_compiler-0.1.0/NOTICE +7 -0
  11. qb_compiler-0.1.0/PKG-INFO +421 -0
  12. qb_compiler-0.1.0/README.md +347 -0
  13. qb_compiler-0.1.0/SECURITY.md +48 -0
  14. qb_compiler-0.1.0/docker-compose.yml +10 -0
  15. qb_compiler-0.1.0/pyproject.toml +176 -0
  16. qb_compiler-0.1.0/requirements-dev-lock.txt +284 -0
  17. qb_compiler-0.1.0/requirements-lock.txt +75 -0
  18. qb_compiler-0.1.0/sbom/.gitkeep +0 -0
  19. qb_compiler-0.1.0/sbom/README.md +42 -0
  20. qb_compiler-0.1.0/sbom/generate_sbom.py +46 -0
  21. qb_compiler-0.1.0/src/qb_compiler/__init__.py +81 -0
  22. qb_compiler-0.1.0/src/qb_compiler/_version.py +12 -0
  23. qb_compiler-0.1.0/src/qb_compiler/backends/__init__.py +53 -0
  24. qb_compiler-0.1.0/src/qb_compiler/backends/base.py +127 -0
  25. qb_compiler-0.1.0/src/qb_compiler/backends/ibm/__init__.py +21 -0
  26. qb_compiler-0.1.0/src/qb_compiler/backends/ibm/adapter.py +83 -0
  27. qb_compiler-0.1.0/src/qb_compiler/backends/ibm/calibration.py +114 -0
  28. qb_compiler-0.1.0/src/qb_compiler/backends/ibm/native_gates.py +31 -0
  29. qb_compiler-0.1.0/src/qb_compiler/backends/ionq/__init__.py +19 -0
  30. qb_compiler-0.1.0/src/qb_compiler/backends/ionq/calibration.py +102 -0
  31. qb_compiler-0.1.0/src/qb_compiler/backends/ionq/native_gates.py +26 -0
  32. qb_compiler-0.1.0/src/qb_compiler/backends/iqm/__init__.py +19 -0
  33. qb_compiler-0.1.0/src/qb_compiler/backends/iqm/calibration.py +99 -0
  34. qb_compiler-0.1.0/src/qb_compiler/backends/iqm/native_gates.py +24 -0
  35. qb_compiler-0.1.0/src/qb_compiler/backends/rigetti/__init__.py +19 -0
  36. qb_compiler-0.1.0/src/qb_compiler/backends/rigetti/calibration.py +100 -0
  37. qb_compiler-0.1.0/src/qb_compiler/backends/rigetti/native_gates.py +20 -0
  38. qb_compiler-0.1.0/src/qb_compiler/calibration/__init__.py +21 -0
  39. qb_compiler-0.1.0/src/qb_compiler/calibration/cached_provider.py +129 -0
  40. qb_compiler-0.1.0/src/qb_compiler/calibration/live_provider.py +162 -0
  41. qb_compiler-0.1.0/src/qb_compiler/calibration/models/__init__.py +13 -0
  42. qb_compiler-0.1.0/src/qb_compiler/calibration/models/backend_properties.py +122 -0
  43. qb_compiler-0.1.0/src/qb_compiler/calibration/models/coupling_properties.py +42 -0
  44. qb_compiler-0.1.0/src/qb_compiler/calibration/models/qubit_properties.py +107 -0
  45. qb_compiler-0.1.0/src/qb_compiler/calibration/provider.py +94 -0
  46. qb_compiler-0.1.0/src/qb_compiler/calibration/static_provider.py +117 -0
  47. qb_compiler-0.1.0/src/qb_compiler/cli/__init__.py +3 -0
  48. qb_compiler-0.1.0/src/qb_compiler/cli/main.py +178 -0
  49. qb_compiler-0.1.0/src/qb_compiler/compiler.py +1054 -0
  50. qb_compiler-0.1.0/src/qb_compiler/config.py +225 -0
  51. qb_compiler-0.1.0/src/qb_compiler/cost/__init__.py +15 -0
  52. qb_compiler-0.1.0/src/qb_compiler/cost/budget_optimizer.py +257 -0
  53. qb_compiler-0.1.0/src/qb_compiler/cost/estimator.py +174 -0
  54. qb_compiler-0.1.0/src/qb_compiler/cost/pricing.py +121 -0
  55. qb_compiler-0.1.0/src/qb_compiler/exceptions.py +90 -0
  56. qb_compiler-0.1.0/src/qb_compiler/ir/__init__.py +32 -0
  57. qb_compiler-0.1.0/src/qb_compiler/ir/circuit.py +196 -0
  58. qb_compiler-0.1.0/src/qb_compiler/ir/converters/__init__.py +21 -0
  59. qb_compiler-0.1.0/src/qb_compiler/ir/converters/openqasm_converter.py +302 -0
  60. qb_compiler-0.1.0/src/qb_compiler/ir/converters/qiskit_converter.py +179 -0
  61. qb_compiler-0.1.0/src/qb_compiler/ir/dag.py +237 -0
  62. qb_compiler-0.1.0/src/qb_compiler/ir/operations.py +161 -0
  63. qb_compiler-0.1.0/src/qb_compiler/ml/__init__.py +45 -0
  64. qb_compiler-0.1.0/src/qb_compiler/ml/_weights/gnn_heron_v1.meta.json +16 -0
  65. qb_compiler-0.1.0/src/qb_compiler/ml/_weights/gnn_heron_v1.pt +0 -0
  66. qb_compiler-0.1.0/src/qb_compiler/ml/_weights/ibm_heron_v1.json +1 -0
  67. qb_compiler-0.1.0/src/qb_compiler/ml/_weights/ibm_heron_v1.meta.json +44 -0
  68. qb_compiler-0.1.0/src/qb_compiler/ml/_weights/rl_router_v1.meta.json +13 -0
  69. qb_compiler-0.1.0/src/qb_compiler/ml/_weights/rl_router_v1.pt +0 -0
  70. qb_compiler-0.1.0/src/qb_compiler/ml/data_generator.py +275 -0
  71. qb_compiler-0.1.0/src/qb_compiler/ml/features.py +238 -0
  72. qb_compiler-0.1.0/src/qb_compiler/ml/gnn_router.py +682 -0
  73. qb_compiler-0.1.0/src/qb_compiler/ml/layout_predictor.py +178 -0
  74. qb_compiler-0.1.0/src/qb_compiler/ml/rl_router.py +746 -0
  75. qb_compiler-0.1.0/src/qb_compiler/ml/train.py +315 -0
  76. qb_compiler-0.1.0/src/qb_compiler/noise/__init__.py +14 -0
  77. qb_compiler-0.1.0/src/qb_compiler/noise/empirical_model.py +146 -0
  78. qb_compiler-0.1.0/src/qb_compiler/noise/fidelity_estimator.py +150 -0
  79. qb_compiler-0.1.0/src/qb_compiler/noise/ml_model.py +111 -0
  80. qb_compiler-0.1.0/src/qb_compiler/noise/noise_model.py +44 -0
  81. qb_compiler-0.1.0/src/qb_compiler/passes/__init__.py +19 -0
  82. qb_compiler-0.1.0/src/qb_compiler/passes/analysis/__init__.py +10 -0
  83. qb_compiler-0.1.0/src/qb_compiler/passes/analysis/connectivity_check.py +55 -0
  84. qb_compiler-0.1.0/src/qb_compiler/passes/analysis/depth_analysis.py +21 -0
  85. qb_compiler-0.1.0/src/qb_compiler/passes/analysis/error_budget_estimator.py +124 -0
  86. qb_compiler-0.1.0/src/qb_compiler/passes/analysis/gate_count.py +28 -0
  87. qb_compiler-0.1.0/src/qb_compiler/passes/base.py +209 -0
  88. qb_compiler-0.1.0/src/qb_compiler/passes/mapping/__init__.py +11 -0
  89. qb_compiler-0.1.0/src/qb_compiler/passes/mapping/calibration_mapper.py +758 -0
  90. qb_compiler-0.1.0/src/qb_compiler/passes/mapping/correlated_error_router.py +251 -0
  91. qb_compiler-0.1.0/src/qb_compiler/passes/mapping/noise_aware_router.py +280 -0
  92. qb_compiler-0.1.0/src/qb_compiler/passes/mapping/temporal_correlation.py +229 -0
  93. qb_compiler-0.1.0/src/qb_compiler/passes/mapping/topology_mapper.py +193 -0
  94. qb_compiler-0.1.0/src/qb_compiler/passes/qec/__init__.py +13 -0
  95. qb_compiler-0.1.0/src/qb_compiler/passes/qec/correlated_error_avoidance.py +68 -0
  96. qb_compiler-0.1.0/src/qb_compiler/passes/qec/logical_mapping.py +59 -0
  97. qb_compiler-0.1.0/src/qb_compiler/passes/qec/syndrome_scheduling.py +61 -0
  98. qb_compiler-0.1.0/src/qb_compiler/passes/scheduling/__init__.py +9 -0
  99. qb_compiler-0.1.0/src/qb_compiler/passes/scheduling/alap_scheduler.py +121 -0
  100. qb_compiler-0.1.0/src/qb_compiler/passes/scheduling/asap_scheduler.py +67 -0
  101. qb_compiler-0.1.0/src/qb_compiler/passes/scheduling/noise_aware_scheduler.py +166 -0
  102. qb_compiler-0.1.0/src/qb_compiler/passes/transformation/__init__.py +15 -0
  103. qb_compiler-0.1.0/src/qb_compiler/passes/transformation/circuit_simplification.py +206 -0
  104. qb_compiler-0.1.0/src/qb_compiler/passes/transformation/commutation_analysis.py +147 -0
  105. qb_compiler-0.1.0/src/qb_compiler/passes/transformation/gate_cancellation.py +104 -0
  106. qb_compiler-0.1.0/src/qb_compiler/passes/transformation/gate_decomposition.py +199 -0
  107. qb_compiler-0.1.0/src/qb_compiler/qiskit_plugin/__init__.py +30 -0
  108. qb_compiler-0.1.0/src/qb_compiler/qiskit_plugin/analysis_passes.py +108 -0
  109. qb_compiler-0.1.0/src/qb_compiler/qiskit_plugin/pass_manager.py +149 -0
  110. qb_compiler-0.1.0/src/qb_compiler/qiskit_plugin/transformation_passes.py +130 -0
  111. qb_compiler-0.1.0/src/qb_compiler/qiskit_plugin/transpiler_plugin.py +308 -0
  112. qb_compiler-0.1.0/src/qb_compiler/strategies/__init__.py +76 -0
  113. qb_compiler-0.1.0/src/qb_compiler/strategies/base.py +104 -0
  114. qb_compiler-0.1.0/src/qb_compiler/strategies/budget_aware.py +175 -0
  115. qb_compiler-0.1.0/src/qb_compiler/strategies/cost_optimal.py +165 -0
  116. qb_compiler-0.1.0/src/qb_compiler/strategies/depth_optimal.py +126 -0
  117. qb_compiler-0.1.0/src/qb_compiler/strategies/fidelity_optimal.py +194 -0
  118. qb_compiler-0.1.0/src/qb_compiler/strategies/speed_optimal.py +74 -0
  119. qb_compiler-0.1.0/src/qb_compiler/telemetry/__init__.py +3 -0
  120. qb_compiler-0.1.0/src/qb_compiler/telemetry/collector.py +88 -0
  121. qb_compiler-0.1.0/tests/__init__.py +0 -0
  122. qb_compiler-0.1.0/tests/conftest.py +103 -0
  123. qb_compiler-0.1.0/tests/fixtures/circuits/bell_state.qasm +10 -0
  124. qb_compiler-0.1.0/tests/fixtures/circuits/qaoa_maxcut_4q.qasm +47 -0
  125. qb_compiler-0.1.0/tests/fixtures/circuits/qft_16q.qasm +83 -0
  126. qb_compiler-0.1.0/tests/fixtures/circuits/vqe_h2_8q.qasm +73 -0
  127. qb_compiler-0.1.0/tests/fuzz/README.md +74 -0
  128. qb_compiler-0.1.0/tests/fuzz/__init__.py +0 -0
  129. qb_compiler-0.1.0/tests/fuzz/fuzz_calibration_parser.py +186 -0
  130. qb_compiler-0.1.0/tests/fuzz/fuzz_circuit_ir.py +131 -0
  131. qb_compiler-0.1.0/tests/fuzz/fuzz_cli_input.py +82 -0
  132. qb_compiler-0.1.0/tests/fuzz/fuzz_compiler_config.py +79 -0
  133. qb_compiler-0.1.0/tests/fuzz/fuzz_qasm_parser.py +88 -0
  134. qb_compiler-0.1.0/tests/integration/__init__.py +0 -0
  135. qb_compiler-0.1.0/tests/integration/test_full_pipeline.py +448 -0
  136. qb_compiler-0.1.0/tests/integration/test_multi_backend.py +166 -0
  137. qb_compiler-0.1.0/tests/integration/test_qiskit_plugin.py +209 -0
  138. qb_compiler-0.1.0/tests/unit/__init__.py +0 -0
  139. qb_compiler-0.1.0/tests/unit/test_backends/__init__.py +0 -0
  140. qb_compiler-0.1.0/tests/unit/test_backends/test_ibm_adapter.py +176 -0
  141. qb_compiler-0.1.0/tests/unit/test_backends/test_native_gates.py +362 -0
  142. qb_compiler-0.1.0/tests/unit/test_backends/test_rigetti_adapter.py +174 -0
  143. qb_compiler-0.1.0/tests/unit/test_calibration/__init__.py +0 -0
  144. qb_compiler-0.1.0/tests/unit/test_calibration/test_models.py +250 -0
  145. qb_compiler-0.1.0/tests/unit/test_calibration/test_providers.py +138 -0
  146. qb_compiler-0.1.0/tests/unit/test_compiler.py +96 -0
  147. qb_compiler-0.1.0/tests/unit/test_cost/__init__.py +0 -0
  148. qb_compiler-0.1.0/tests/unit/test_cost/test_budget_optimizer.py +91 -0
  149. qb_compiler-0.1.0/tests/unit/test_cost/test_estimator.py +73 -0
  150. qb_compiler-0.1.0/tests/unit/test_ir/__init__.py +0 -0
  151. qb_compiler-0.1.0/tests/unit/test_ir/test_circuit.py +111 -0
  152. qb_compiler-0.1.0/tests/unit/test_ir/test_converters.py +293 -0
  153. qb_compiler-0.1.0/tests/unit/test_ir/test_dag.py +108 -0
  154. qb_compiler-0.1.0/tests/unit/test_ml/__init__.py +0 -0
  155. qb_compiler-0.1.0/tests/unit/test_ml/test_data_generator.py +100 -0
  156. qb_compiler-0.1.0/tests/unit/test_ml/test_features.py +153 -0
  157. qb_compiler-0.1.0/tests/unit/test_ml/test_gnn_router.py +366 -0
  158. qb_compiler-0.1.0/tests/unit/test_ml/test_layout_predictor.py +148 -0
  159. qb_compiler-0.1.0/tests/unit/test_ml/test_rl_router.py +390 -0
  160. qb_compiler-0.1.0/tests/unit/test_passes/__init__.py +0 -0
  161. qb_compiler-0.1.0/tests/unit/test_passes/test_alap_scheduler.py +64 -0
  162. qb_compiler-0.1.0/tests/unit/test_passes/test_asap_scheduler.py +79 -0
  163. qb_compiler-0.1.0/tests/unit/test_passes/test_calibration_mapper.py +518 -0
  164. qb_compiler-0.1.0/tests/unit/test_passes/test_commutation.py +78 -0
  165. qb_compiler-0.1.0/tests/unit/test_passes/test_connectivity_check.py +97 -0
  166. qb_compiler-0.1.0/tests/unit/test_passes/test_correlated_error_router.py +127 -0
  167. qb_compiler-0.1.0/tests/unit/test_passes/test_error_budget_estimator.py +120 -0
  168. qb_compiler-0.1.0/tests/unit/test_passes/test_gate_cancellation.py +90 -0
  169. qb_compiler-0.1.0/tests/unit/test_passes/test_gate_decomposition.py +125 -0
  170. qb_compiler-0.1.0/tests/unit/test_passes/test_noise_aware_router.py +342 -0
  171. qb_compiler-0.1.0/tests/unit/test_passes/test_noise_aware_scheduler.py +88 -0
  172. qb_compiler-0.1.0/tests/unit/test_passes/test_simplification.py +82 -0
  173. qb_compiler-0.1.0/tests/unit/test_passes/test_t1_asymmetry.py +195 -0
  174. qb_compiler-0.1.0/tests/unit/test_passes/test_temporal_correlation.py +221 -0
  175. qb_compiler-0.1.0/tests/unit/test_passes/test_topology_mapper.py +72 -0
  176. qb_compiler-0.1.0/tests/unit/test_strategies/__init__.py +0 -0
  177. qb_compiler-0.1.0/tests/unit/test_strategies/test_fidelity_optimal.py +145 -0
  178. qb_compiler-0.1.0/tests/unit/test_strategies/test_strategies.py +238 -0
@@ -0,0 +1,31 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .eggs/
9
+ *.egg
10
+ .venv/
11
+ venv/
12
+ env/
13
+ .mypy_cache/
14
+ .ruff_cache/
15
+ .pytest_cache/
16
+ .coverage
17
+ htmlcov/
18
+ *.log
19
+ .DS_Store
20
+ Thumbs.db
21
+ *.swp
22
+ *.swo
23
+ *~
24
+ .idea/
25
+ .vscode/
26
+ *.iml
27
+ .env
28
+ .env.local
29
+ docs/_build/
30
+ *.ipynb_checkpoints/
31
+ *:Zone.Identifier
@@ -0,0 +1,15 @@
1
+ repos:
2
+ - repo: https://github.com/astral-sh/ruff-pre-commit
3
+ rev: v0.5.0
4
+ hooks:
5
+ - id: ruff
6
+ args: [--fix]
7
+ - id: ruff-format
8
+ - repo: https://github.com/pre-commit/pre-commit-hooks
9
+ rev: v4.6.0
10
+ hooks:
11
+ - id: trailing-whitespace
12
+ - id: end-of-file-fixer
13
+ - id: check-yaml
14
+ - id: check-added-large-files
15
+ args: [--maxkb=500]
@@ -0,0 +1,16 @@
1
+ version: 2
2
+
3
+ build:
4
+ os: ubuntu-22.04
5
+ tools:
6
+ python: "3.11"
7
+
8
+ sphinx:
9
+ configuration: docs/conf.py
10
+
11
+ python:
12
+ install:
13
+ - method: pip
14
+ path: .
15
+ extra_requirements:
16
+ - dev
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ All notable changes to qb-compiler will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-03-13
11
+
12
+ ### Added
13
+ - Core IR: QBCircuit, QBDag, QBGate, QBMeasure, QBBarrier
14
+ - Qiskit and OpenQASM 2.0 converters
15
+ - CalibrationMapper: VF2-based calibration-weighted qubit placement
16
+ - NoiseAwareRouter: Dijkstra shortest-error-path SWAP routing
17
+ - NoiseAwareScheduler: ALAP scheduling with T1/T2 urgency scoring
18
+ - GateDecomposition: Native basis decomposition (IBM ECR/RZ/SX/X, Rigetti CZ/RX/RZ, IonQ MS/GPI/GPI2, IQM CZ/PRX)
19
+ - ErrorBudgetEstimator: Pre-execution fidelity prediction
20
+ - T1 asymmetry awareness: readout-scaled penalty for qubits with high |1> decay
21
+ - Temporal correlation detection: Pearson correlation across calibration snapshots
22
+ - Calibration subsystem: StaticCalibrationProvider, CachedCalibrationProvider, BackendProperties
23
+ - Noise modelling: EmpiricalNoiseModel, FidelityEstimator
24
+ - Backend support: IBM Heron, Rigetti Ankaa, IonQ Aria/Forte, IQM Garnet/Emerald
25
+ - Cost estimation with vendor pricing
26
+ - Qiskit transpiler plugin: QBCalibrationLayout, qb_transpile(), QBPassManager
27
+ - CLI: `qbc compile`, `qbc info`, `qbc calibration show`
28
+ - Gate cancellation and commutation analysis optimisation passes
29
+ - Depth and gate count analysis passes
30
+ - ML Phase 2: XGBoost layout predictor (AUC=0.94, 454KB, +5.4% fidelity on GHZ-8)
31
+ - ML Phase 3: GNN layout predictor (dual-graph GCN, 42KB, +6.5% fidelity on QAOA-8)
32
+ - ML Phase 4: RL SWAP router (PPO actor-critic, 190KB, calibration-aware routing)
33
+ - ML training infrastructure: data generator, feature extraction, model training scripts
34
+ - 461 tests covering all passes, IR, calibration, backends, ML pipeline
35
+ - CI/CD: GitHub Actions for lint, typecheck, test matrix (Python 3.10-3.12)
36
+ - 10 example scripts demonstrating key features
37
+ - Comprehensive benchmark suite comparing all ML phases
@@ -0,0 +1,54 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to a positive environment:
15
+
16
+ * Using welcoming and inclusive language
17
+ * Being respectful of differing viewpoints and experiences
18
+ * Gracefully accepting constructive criticism
19
+ * Focusing on what is best for the community
20
+ * Showing empathy towards other community members
21
+
22
+ Examples of unacceptable behavior:
23
+
24
+ * The use of sexualized language or imagery, and sexual attention or advances
25
+ * Trolling, insulting or derogatory comments, and personal or political attacks
26
+ * Public or private harassment
27
+ * Publishing others' private information without explicit permission
28
+ * Other conduct which could reasonably be considered inappropriate
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of
33
+ acceptable behavior and will take appropriate and fair corrective action in
34
+ response to any behavior that they deem inappropriate, threatening, offensive,
35
+ or harmful.
36
+
37
+ ## Scope
38
+
39
+ This Code of Conduct applies within all community spaces, and also applies when
40
+ an individual is officially representing the community in public spaces.
41
+
42
+ ## Enforcement
43
+
44
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
45
+ reported to the community leaders responsible for enforcement at
46
+ conduct@qubitboost.io.
47
+
48
+ All complaints will be reviewed and investigated promptly and fairly.
49
+
50
+ ## Attribution
51
+
52
+ This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/),
53
+ version 2.1, available at
54
+ https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
@@ -0,0 +1,212 @@
1
+ # Contributing to qb-compiler
2
+
3
+ Thank you for your interest in contributing to qb-compiler. This guide covers
4
+ everything you need to get started.
5
+
6
+ ## Getting Started
7
+
8
+ 1. Fork the repository on GitHub.
9
+ 2. Clone your fork locally:
10
+ ```bash
11
+ git clone https://github.com/<your-username>/qb-compiler.git
12
+ cd qb-compiler
13
+ ```
14
+ 3. Set up your development environment:
15
+ ```bash
16
+ make dev
17
+ ```
18
+ This installs the package in editable mode with all development dependencies.
19
+
20
+ ## Development Setup
21
+
22
+ **Requirements:**
23
+ - Python 3.10 or later
24
+ - A virtual environment is strongly recommended
25
+
26
+ **Manual setup (alternative to `make dev`):**
27
+ ```bash
28
+ python -m venv .venv
29
+ source .venv/bin/activate
30
+ pip install -e ".[dev]"
31
+ ```
32
+
33
+ **Pre-commit hooks:**
34
+ ```bash
35
+ pre-commit install
36
+ ```
37
+
38
+ This enables automatic linting and formatting checks before each commit.
39
+
40
+ ## Code Style
41
+
42
+ - **Linter/formatter:** ruff (line-length 100).
43
+ - **Type checking:** mypy in strict mode.
44
+ - **Future annotations:** Every module must begin with `from __future__ import annotations`.
45
+ - **Docstrings:** Use Google-style docstrings for all public classes and functions.
46
+ - **Imports:** Sort with ruff's isort rules. Prefer absolute imports.
47
+
48
+ Run checks locally:
49
+ ```bash
50
+ make lint # ruff check + ruff format --check
51
+ make typecheck # mypy
52
+ ```
53
+
54
+ ## Testing
55
+
56
+ Run the full test suite:
57
+ ```bash
58
+ make test
59
+ ```
60
+
61
+ **Pytest markers:**
62
+ | Marker | Purpose |
63
+ |---------------|------------------------------------------|
64
+ | `unit` | Fast, isolated unit tests (default) |
65
+ | `integration` | Tests that exercise multiple components |
66
+ | `benchmark` | Performance benchmarks (excluded by default) |
67
+
68
+ Run a specific marker:
69
+ ```bash
70
+ pytest -m unit
71
+ pytest -m integration
72
+ pytest -m benchmark
73
+ ```
74
+
75
+ **Test naming conventions:**
76
+ - Test files: `test_<module>.py`
77
+ - Test functions: `test_<behaviour_under_test>`
78
+ - Place tests in `tests/` mirroring the `src/` directory structure.
79
+
80
+ **Coverage:** Aim for at least 80% line coverage on new code. Check with:
81
+ ```bash
82
+ pytest --cov=qb_compiler --cov-report=term-missing
83
+ ```
84
+
85
+ ## Architecture Overview
86
+
87
+ qb-compiler uses a linear pass pipeline that transforms circuits through
88
+ well-defined stages:
89
+
90
+ ```
91
+ Input (Qiskit / OpenQASM 2.0)
92
+ -> IR conversion (QBCircuit / QBDag)
93
+ -> Mapping (CalibrationMapper — VF2 placement)
94
+ -> Routing (NoiseAwareRouter — SWAP insertion)
95
+ -> Scheduling (NoiseAwareScheduler — ALAP with T1/T2 urgency)
96
+ -> Decomposition (GateDecomposition — native basis gates)
97
+ -> Analysis (depth, gate count, error budget estimation)
98
+ -> Output (QBCircuit / Qiskit QuantumCircuit)
99
+ ```
100
+
101
+ Each pass inherits from `BasePass` and implements a `run(dag: QBDag) -> QBDag`
102
+ method. Passes are stateless: all configuration is supplied at construction time.
103
+
104
+ ## Adding a New Pass
105
+
106
+ 1. **Create the pass** in `src/qb_compiler/passes/`:
107
+ ```python
108
+ from __future__ import annotations
109
+ from qb_compiler.passes.base import BasePass
110
+ from qb_compiler.ir.dag import QBDag
111
+
112
+ class MyNewPass(BasePass):
113
+ """One-line description of what this pass does."""
114
+
115
+ def run(self, dag: QBDag) -> QBDag:
116
+ # Transform the DAG and return it.
117
+ return dag
118
+ ```
119
+ 2. **Export** the pass from `src/qb_compiler/passes/__init__.py`.
120
+ 3. **Write tests** in `tests/passes/test_my_new_pass.py`. Include at least:
121
+ - A trivial circuit (1-2 qubits) verifying correctness.
122
+ - An edge case (empty circuit, single gate, barriers).
123
+ 4. **Integrate** the pass into the pipeline in the appropriate position.
124
+ 5. **Document** the pass with a docstring and, if user-facing, update the README.
125
+
126
+ ## Adding a Backend
127
+
128
+ Backend configurations live in `src/qb_compiler/backends/`. To add support for
129
+ a new hardware backend:
130
+
131
+ 1. **Create a configuration module** (e.g., `my_backend.py`) that defines:
132
+ - Native gate set and gate durations.
133
+ - Connectivity map (coupling graph).
134
+ - Default noise parameters (T1, T2, gate fidelities).
135
+ 2. **Implement a calibration provider** if the backend exposes live calibration
136
+ data, extending `BaseCalibrationProvider`.
137
+ 3. **Add decomposition rules** in `src/qb_compiler/passes/decomposition.py` for
138
+ the backend's native gate set.
139
+ 4. **Write tests** covering mapping, routing, and decomposition for the new
140
+ backend's topology.
141
+ 5. **Add a configuration entry** so the CLI and transpiler plugin can reference
142
+ the backend by name.
143
+
144
+ ## ML Models
145
+
146
+ ML models live in `src/qb_compiler/ml/`. The pipeline has four phases:
147
+
148
+ | Phase | Module | Architecture | Install |
149
+ |-------|--------|-------------|---------|
150
+ | 1 | `data_generator.py` | Training data pipeline | Core |
151
+ | 2 | `layout_predictor.py` | XGBoost qubit scorer | `[ml]` |
152
+ | 3 | `gnn_router.py` | Dual-graph GCN | `[gnn]` |
153
+ | 4 | `rl_router.py` | PPO SWAP routing | `[gnn]` |
154
+
155
+ **Model weights** are stored in `src/qb_compiler/ml/_weights/` with
156
+ `*.meta.json` metadata files. To retrain:
157
+
158
+ ```bash
159
+ # Phase 2: XGBoost
160
+ python -m qb_compiler.ml.train
161
+
162
+ # Phase 3: GNN
163
+ python -c "from qb_compiler.ml.gnn_router import train_gnn_model; train_gnn_model()"
164
+ ```
165
+
166
+ **Adding a new ML model:**
167
+ 1. Create the model in `src/qb_compiler/ml/`.
168
+ 2. Follow the `predict_candidate_qubits(circuit, backend) -> list[int]` interface
169
+ so it's plug-compatible with `CalibrationMapper`.
170
+ 3. Save weights in `_weights/` with a `.meta.json` metadata file.
171
+ 4. Write tests in `tests/unit/test_ml/`.
172
+ 5. Guard imports behind optional dependency checks (see `ml/__init__.py`).
173
+
174
+ ## Pull Request Process
175
+
176
+ **Branch naming:**
177
+ - `feat/<short-description>` for new features
178
+ - `fix/<short-description>` for bug fixes
179
+ - `docs/<short-description>` for documentation changes
180
+ - `refactor/<short-description>` for refactoring
181
+
182
+ **Commit messages:** Use conventional commit style:
183
+ ```
184
+ feat: add Quantinuum H2 backend configuration
185
+ fix: correct SWAP count in noise-aware routing
186
+ docs: update calibration provider examples
187
+ ```
188
+
189
+ **Before opening a PR:**
190
+ 1. Ensure all checks pass: `make lint && make typecheck && make test`
191
+ 2. Add or update tests for any changed behaviour.
192
+ 3. Update documentation if the public API changed.
193
+
194
+ **PR expectations:**
195
+ - Keep PRs focused on a single concern.
196
+ - Provide a clear description of what changed and why.
197
+ - Link any related issues.
198
+ - Respond to review feedback promptly.
199
+
200
+ ## Code of Conduct
201
+
202
+ This project follows the
203
+ [Contributor Covenant Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/).
204
+ By participating, you agree to uphold a welcoming and inclusive environment.
205
+
206
+ Please report unacceptable behaviour to the maintainers.
207
+
208
+ ## License
209
+
210
+ By contributing to qb-compiler, you agree that your contributions will be
211
+ licensed under the [Apache License 2.0](LICENSE), the same license that covers
212
+ the project.
@@ -0,0 +1,11 @@
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY pyproject.toml LICENSE README.md ./
6
+ COPY src/ src/
7
+ COPY tests/ tests/
8
+
9
+ RUN pip install --no-cache-dir -e ".[dev]"
10
+
11
+ CMD ["pytest", "tests/", "-v", "--timeout=60"]
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 QubitBoost (https://www.qubitboost.io)
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,37 @@
1
+ .PHONY: install dev test lint type-check format clean docs bench
2
+
3
+ install:
4
+ pip install -e .
5
+
6
+ dev:
7
+ pip install -e ".[dev,qiskit]"
8
+ pre-commit install
9
+
10
+ test:
11
+ pytest tests/unit -v --timeout=30
12
+
13
+ test-all:
14
+ pytest tests/ -v --timeout=120
15
+
16
+ test-cov:
17
+ pytest tests/unit -v --cov=src/qb_compiler --cov-report=term-missing --cov-report=html
18
+
19
+ lint:
20
+ ruff check src/ tests/
21
+
22
+ format:
23
+ ruff format src/ tests/
24
+ ruff check --fix src/ tests/
25
+
26
+ type-check:
27
+ mypy src/qb_compiler/
28
+
29
+ clean:
30
+ rm -rf dist/ build/ *.egg-info .mypy_cache .ruff_cache .pytest_cache htmlcov/
31
+ find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
32
+
33
+ docs:
34
+ cd docs && make html
35
+
36
+ bench:
37
+ pytest tests/benchmarks/ -v --benchmark-only
@@ -0,0 +1,7 @@
1
+ qb-compiler
2
+ Copyright 2026 Walshe Thornwell Fotheringham Trading Ltd.
3
+
4
+ This product includes software developed at
5
+ Walshe Thornwell Fotheringham Trading Ltd. (https://qubitboost.io).
6
+
7
+ Licensed under the Apache License, Version 2.0.