qaravan 0.2.2__tar.gz → 0.2.3__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 (70) hide show
  1. {qaravan-0.2.2/src/qaravan.egg-info → qaravan-0.2.3}/PKG-INFO +1 -1
  2. qaravan-0.2.3/README.md +103 -0
  3. {qaravan-0.2.2 → qaravan-0.2.3}/pyproject.toml +1 -1
  4. qaravan-0.2.3/src/qaravan/__init__.py +1 -0
  5. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/monte_carlo.py +1 -1
  6. {qaravan-0.2.2 → qaravan-0.2.3/src/qaravan.egg-info}/PKG-INFO +1 -1
  7. qaravan-0.2.2/README.md +0 -139
  8. qaravan-0.2.2/src/qaravan/__init__.py +0 -1
  9. {qaravan-0.2.2 → qaravan-0.2.3}/LICENSE +0 -0
  10. {qaravan-0.2.2 → qaravan-0.2.3}/setup.cfg +0 -0
  11. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/applications/__init__.py +0 -0
  12. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/applications/algorithms.py +0 -0
  13. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/applications/circuit_library.py +0 -0
  14. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/applications/compilation.py +0 -0
  15. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/applications/dynamic_circuit_execution.py +0 -0
  16. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/applications/dynamic_circuit_library.py +0 -0
  17. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/applications/quantum_info.py +0 -0
  18. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/applications/run_context.py +0 -0
  19. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/__init__.py +0 -0
  20. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/_ncon_compat.py +0 -0
  21. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/_tn_internals.py +0 -0
  22. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/clifford.py +0 -0
  23. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/density_matrix.py +0 -0
  24. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/matchgate.py +0 -0
  25. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/mpdo.py +0 -0
  26. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/mps.py +0 -0
  27. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/pauli_propagation.py +0 -0
  28. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/backends/statevector.py +0 -0
  29. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/__init__.py +0 -0
  30. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/_repr.py +0 -0
  31. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/base.py +0 -0
  32. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/circuit.py +0 -0
  33. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/dynamic_circuit.py +0 -0
  34. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/fermions.py +0 -0
  35. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/gates.py +0 -0
  36. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/hamiltonians.py +0 -0
  37. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/lattices.py +0 -0
  38. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/noise.py +0 -0
  39. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/core/observables.py +0 -0
  40. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/interop/__init__.py +0 -0
  41. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/interop/qasm.py +0 -0
  42. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/__init__.py +0 -0
  43. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/base_sim.py +0 -0
  44. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/circuits.py +0 -0
  45. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/clifford_sim.py +0 -0
  46. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/compilation.py +0 -0
  47. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/density_matrix_sim.py +0 -0
  48. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/environments.py +0 -0
  49. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/gates.py +0 -0
  50. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/hamiltonians.py +0 -0
  51. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/initializations.py +0 -0
  52. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/lattices.py +0 -0
  53. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/matchgate_sim.py +0 -0
  54. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/monte_carlo_sim.py +0 -0
  55. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/mpdo_sim.py +0 -0
  56. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/mps_sim.py +0 -0
  57. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/noise.py +0 -0
  58. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/param_gates.py +0 -0
  59. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/paulis.py +0 -0
  60. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/skeletons.py +0 -0
  61. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/statevector_sim.py +0 -0
  62. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/tn.py +0 -0
  63. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/trotter.py +0 -0
  64. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/legacy/utils.py +0 -0
  65. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan/plot.py +0 -0
  66. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan.egg-info/SOURCES.txt +0 -0
  67. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan.egg-info/dependency_links.txt +0 -0
  68. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan.egg-info/requires.txt +0 -0
  69. {qaravan-0.2.2 → qaravan-0.2.3}/src/qaravan.egg-info/top_level.txt +0 -0
  70. {qaravan-0.2.2 → qaravan-0.2.3}/tests/test_plot.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qaravan
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Unified classical simulation of noiseless and noisy quantum circuits
5
5
  Author-email: Faisal Alam <faisal@phasecraft.io>
6
6
  Requires-Python: >=3.11
@@ -0,0 +1,103 @@
1
+ # Qaravan
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/qaravan.svg)](https://pypi.org/project/qaravan/)
4
+ [![codecov](https://codecov.io/gh/alam-faisal/qaravan/branch/master/graph/badge.svg)](https://codecov.io/gh/alam-faisal/qaravan/branch/master)
5
+
6
+ **Qaravan** is a Python library for classical simulation of quantum circuits. It is designed for rapid prototyping of near-term quantum algorithms, error mitigation techniques, and mid-circuit measurement applications.
7
+
8
+ > **v0.2 is under active development.** Backends marked "In legacy" below still live under `qaravan.legacy` and are being ported to the new abstractions.
9
+
10
+ ## Design
11
+
12
+ Qaravan is built around four core abstractions:
13
+
14
+ - **`Gate`** — an operation with a name, site indices, and a matrix representation.
15
+ - **`Circuit`** — an ordered sequence of gates. Supports `+` (concatenation), `*` (repetition), `.dagger()`.
16
+ - **`State`** — the evolving data structure (statevector, density matrix, MPS, ...). Has `.expectation()`, `.sample()`, `.sample_and_collapse()`.
17
+ - **`Simulator`** — takes an initial `State`, a `Circuit`, and an optional `NoiseModel`. Compiles and evolves; returns the final `State`.
18
+
19
+ ## Installation
20
+
21
+ Install from PyPI:
22
+
23
+ ```bash
24
+ uv add qaravan
25
+ ```
26
+
27
+ For development (clone the repo first):
28
+
29
+ ```bash
30
+ uv sync --group dev
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Noiseless simulation
36
+
37
+ ```python
38
+ from qaravan.core import Circuit, PauliString
39
+ from qaravan.core.gates import H, CNOT
40
+ from qaravan.backends import Statevector
41
+
42
+ circ = Circuit([H(0), CNOT([0, 1])])
43
+ final_sv = Statevector(bitstring="00").apply(circ)
44
+ print("⟨ZZ⟩:", final_sv.expectation(PauliString("ZZ"))) # → 1.0
45
+ ```
46
+
47
+ `state.apply(circ)` is shorthand for `StatevectorSimulator(circ, state).run()`.
48
+
49
+ ### Noisy simulation
50
+
51
+ A single noisy `Statevector` run samples one error realization and returns one pure state. `Walkers` evolves an ensemble of independent trajectories, which represents the mixed state statistically (see [GOTCHAS](docs/GOTCHAS.md)).
52
+
53
+ ```python
54
+ from qaravan.backends import Walkers
55
+ from qaravan.core.noise import DepolarizingNoise
56
+
57
+ noise = DepolarizingNoise(num_sites=2, error_rate=0.1)
58
+ walkers = Walkers(Statevector(bitstring="00"), num_walkers=2000)
59
+ noisy = walkers.apply(circ, noise_model=noise, noise_rng=0)
60
+ print("⟨ZZ⟩:", noisy.expectation(PauliString("ZZ")))
61
+ ```
62
+
63
+ ### Dynamic circuits (mid-circuit measurement + feed-forward)
64
+
65
+ ```python
66
+ from qaravan.core import DynamicCircuit, DynamicRound
67
+
68
+ def decoder(outcome: str) -> Circuit:
69
+ return Circuit([]) if outcome == "0" else Circuit([H(1)])
70
+
71
+ dynamic = DynamicCircuit([DynamicRound(meas_sites=[0], decoder=decoder)])
72
+ final_state, record = dynamic.execute(final_sv, measurement_rng=1)
73
+ ```
74
+
75
+ ### Trotter time evolution
76
+
77
+ ```python
78
+ from qaravan.core import TFI, Magnetization
79
+ from qaravan.applications import trotter_circuit
80
+
81
+ ham = TFI(n=8, J=1.0, h=0.75)
82
+ step = trotter_circuit(ham, dt=0.1)
83
+ obs = Magnetization(n=8)
84
+
85
+ state = Statevector(bitstring="0" * 8)
86
+ mags = []
87
+ for _ in range(50):
88
+ mags.append(state.expectation(obs))
89
+ state = state.apply(step)
90
+ ```
91
+
92
+ ## Backends planned
93
+
94
+ | Backend | State type | Notes |
95
+ |---|---|---|
96
+ | `StatevectorSimulator` | `Statevector` | ![Complete](https://img.shields.io/badge/Complete-brightgreen) |
97
+ | `DensityMatrixSimulator` | `DensityMatrix` | ![In legacy](https://img.shields.io/badge/In_legacy-blue) |
98
+ | `MPSSimulator` | `MPS` | ![In legacy](https://img.shields.io/badge/In_legacy-blue) |
99
+ | `MPDOSimulator` | `MPDO` | ![In legacy](https://img.shields.io/badge/In_legacy-blue) |
100
+ | `MonteCarloSimulator` | `Walkers` | ![In development](https://img.shields.io/badge/In_development-orange) |
101
+ | `CliffordSimulator` | `StabilizerTableau` | ![In development](https://img.shields.io/badge/In_development-orange) |
102
+ | `MatchgateSimulator` | `GaussianState` | ![In legacy](https://img.shields.io/badge/In_legacy-blue) |
103
+ | `PauliPropagationSimulator` | `PauliSum` | ![In development](https://img.shields.io/badge/In_development-orange) |
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "qaravan"
7
- version = "0.2.2"
7
+ version = "0.2.3"
8
8
  description = "Unified classical simulation of noiseless and noisy quantum circuits"
9
9
  authors = [{ name = "Faisal Alam", email = "faisal@phasecraft.io" }]
10
10
  requires-python = ">=3.11"
@@ -0,0 +1 @@
1
+ __version__ = "0.2.3"
@@ -149,7 +149,7 @@ class MonteCarloSimulator(Simulator):
149
149
  circuit, initial_state, noise_model, decompose, noise_rng=noise_rng
150
150
  )
151
151
  representative = initial_state[0]
152
- member_simulator_type = initial_state.default_simulator
152
+ member_simulator_type = representative.default_simulator
153
153
  self.member_simulator = member_simulator_type(
154
154
  circuit,
155
155
  representative,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: qaravan
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Unified classical simulation of noiseless and noisy quantum circuits
5
5
  Author-email: Faisal Alam <faisal@phasecraft.io>
6
6
  Requires-Python: >=3.11
qaravan-0.2.2/README.md DELETED
@@ -1,139 +0,0 @@
1
- # Qaravan
2
-
3
- [![PyPI version](https://img.shields.io/pypi/v/qaravan.svg)](https://pypi.org/project/qaravan/)
4
- [![codecov](https://codecov.io/gh/alam-faisal/qaravan/branch/rewrite%2Fv0.2/graph/badge.svg)](https://codecov.io/gh/alam-faisal/qaravan/branch/rewrite%2Fv0.2)
5
-
6
- **Qaravan** is a Python library for classical simulation of quantum circuits. It is designed for rapid prototyping of near-term quantum algorithms, error mitigation techniques, and mid-circuit measurement applications.
7
-
8
- > **v0.2 is under active development.** The API described here reflects the target design. Legacy v0.1 code is preserved under `qaravan.legacy` for reference.
9
-
10
- ## Design
11
-
12
- Qaravan is built around four core abstractions:
13
-
14
- - **`Gate`** — an operation with a name, site indices, and a matrix representation. Backend-agnostic.
15
- - **`Circuit`** — an ordered sequence of gates. Supports `+` (concatenation), `*` (repetition), `.dagger()`.
16
- - **`State`** — the evolving data structure (statevector, density matrix, MPS, ...). Owns `.expectation()`, `.sample()`, `.sample_and_collapse()`.
17
- - **`Simulator`** — takes an initial `State`, a `Circuit`, and an optional `NoiseModel`. Compiles and evolves; returns the final `State`.
18
-
19
- The `State`/`Simulator` split is the key design choice: the returned `State` is independent of the simulator, which makes dynamic-circuit and feed-forward workflows natural.
20
-
21
- ## Installation
22
-
23
- Install from PyPI:
24
-
25
- ```bash
26
- uv add qaravan
27
- ```
28
-
29
- For development (clone the repo first):
30
-
31
- ```bash
32
- uv sync --group dev
33
- ```
34
-
35
- ## Usage
36
-
37
- ### Noiseless simulation
38
-
39
- ```python
40
- from qaravan.core.gates import H, CNOT
41
- from qaravan.core.circuits import Circuit
42
- from qaravan.core.observables import PauliString
43
- from qaravan.backends.statevector import Statevector, StatevectorSimulator
44
-
45
- circ = Circuit([H(0), CNOT([0, 1])])
46
- obs = PauliString("ZZ")
47
-
48
- sv = Statevector(bitstring="00")
49
- final_sv = StatevectorSimulator(circ, sv).run()
50
- print("⟨ZZ⟩:", final_sv.expectation(obs)) # → 1.0
51
- ```
52
-
53
- ### Noisy simulation
54
-
55
- ```python
56
- from qaravan.core.noise import ThermalNoise
57
- from qaravan.backends.density_matrix import DensityMatrix, DensityMatrixSimulator
58
-
59
- nm = ThermalNoise(t1=100, t2=75, t_q1=0.04, t_q2=0.5)
60
- dm = DensityMatrix(bitstring="00")
61
- final_dm = DensityMatrixSimulator(circ, dm, nm).run()
62
- print("⟨ZZ⟩:", final_dm.expectation(obs))
63
- ```
64
-
65
- ### Dynamic circuits (mid-circuit measurement + feed-forward)
66
-
67
- ```python
68
- from qaravan.backends.statevector import Statevector, StatevectorSimulator
69
-
70
- sv = Statevector(bitstring="0" * n)
71
- for round in range(n_rounds):
72
- outcome, sv = sv.sample_and_collapse(meas_sites)
73
- correction = decoder(outcome, round)
74
- sv = StatevectorSimulator(correction, sv).run()
75
- ```
76
-
77
- ### Trotter time evolution
78
-
79
- ```python
80
- from qaravan.core.hamiltonians import TFI
81
- from qaravan.core.observables import Magnetization
82
- from qaravan.backends.density_matrix import DensityMatrix, DensityMatrixSimulator
83
-
84
- ham = TFI(n=8, j=1.0, h=0.75)
85
- nm = ThermalNoise(t1=100, t2=75, t_q1=0.04, t_q2=0.5)
86
- obs = Magnetization(n=8)
87
-
88
- circ = ham.trotter_circuit(step_size=0.1)
89
- dm = DensityMatrix(bitstring="0" * 8)
90
- exp_list = []
91
- for _ in range(500):
92
- exp_list.append(dm.expectation(obs))
93
- dm = DensityMatrixSimulator(circ, dm, nm).run()
94
- ```
95
-
96
- ## Backends
97
-
98
- | Backend | State type | Noise | Notes |
99
- |---|---|---|---|
100
- | `StatevectorSimulator` | `Statevector` | ✗ | Reference backend |
101
- | `DensityMatrixSimulator` | `DensityMatrix` | ✓ | Full $d^{2n}$ density matrix |
102
- | `MPSSimulator` | `MPS` | ✗ | Bond-dimension truncation |
103
- | `MPDOSimulator` | `MPDO` | ✓ | Mixed-state MPS |
104
- | `MonteCarloSimulator` | `Walkers` | ✓ | Trajectory sampling |
105
- | `CliffordSimulator` | `StabilizerTableau` | ✓ | Wraps Stim |
106
- | `MatchgateSimulator` | `GaussianState` | — | Fermionic Gaussian circuits |
107
- | `PauliPropagationSimulator` | `PauliSum` | — | Heisenberg-picture propagation |
108
-
109
- ## Gotchas
110
-
111
- **`Circuit.copy()` resets layers but preserves decomposition.**
112
- `copy()` returns a new circuit with the same gate list but `layers = None`.
113
- `construct_layers()` must be called again on the copy before iterating over layers.
114
- Decomposition is *not* undone: `decompose()` mutates `self.gates` in place, so a copy of a decomposed circuit still has the decomposed gates.
115
-
116
- **Qubit ordering is big-endian: qubit 0 is the most significant bit.**
117
- Applying `H(0)` to a 2-qubit system embeds as `H ⊗ I`, not `I ⊗ H`.
118
- In general, gate `G` on qubit `k` of an `n`-qubit system embeds as:
119
-
120
- ```
121
- I^{⊗k} ⊗ G ⊗ I^{⊗(n−k−1)}
122
- ```
123
-
124
- Basis state index `i` corresponds to bitstring `q0 q1 … q_{n−1}` where `i = q0·2^{n−1} + q1·2^{n−2} + … + q_{n−1}·2^0`. Qubit 0 is the leftmost qubit in ket notation. This is the opposite of Qiskit's little-endian convention, where qubit 0 is the least significant bit and `H(0)` embeds as `I ⊗ H`.
125
-
126
- ## Roadmap
127
-
128
- - ✅ **v0.2 scaffold** — directory structure, legacy preservation, `uv` packaging
129
- - ✅ **Core ABCs** — `Gate`, `Circuit`, `State`, `Simulator`, `Observable`, `NoiseModel`
130
- - 🔧 **Concrete gates** — `H`, `X`, `Y`, `Z`, `CNOT`, `RX/Y/Z`, `RXX/YY/ZZ`, `Reset`, `Measure`
131
- - ⬜ **Statevector backend** — reference implementation
132
- - ⬜ **Density matrix backend** — first noisy backend
133
- - ⬜ **TFI Hamiltonian** — first end-to-end Trotter workflow
134
- - ⬜ **MPS / MPDO backends**
135
- - ⬜ **Mid-circuit measurements** — `Measure` gate, classical registers, feed-forward
136
- - ⬜ **Monte Carlo backend**
137
- - ⬜ **Clifford backend** (wraps Stim)
138
- - ⬜ **Matchgate backend**
139
- - ⬜ **Pauli propagation backend**
@@ -1 +0,0 @@
1
- __version__ = "0.2.0"
File without changes
File without changes
File without changes
File without changes