westquant 0.1.0__py3-none-any.whl
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.
- westquant/__init__.py +16 -0
- westquant/cli.py +365 -0
- westquant/generate.py +316 -0
- westquant/wqdf.py +134 -0
- westquant-0.1.0.dist-info/METADATA +139 -0
- westquant-0.1.0.dist-info/RECORD +11 -0
- westquant-0.1.0.dist-info/WHEEL +5 -0
- westquant-0.1.0.dist-info/entry_points.txt +2 -0
- westquant-0.1.0.dist-info/licenses/LICENSE +201 -0
- westquant-0.1.0.dist-info/licenses/NOTICE +11 -0
- westquant-0.1.0.dist-info/top_level.txt +1 -0
westquant/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""WestQuant Open — Search the representation, not just the parameters.
|
|
2
|
+
|
|
3
|
+
Umbrella package for the WestQuant Open ecosystem. Install with:
|
|
4
|
+
|
|
5
|
+
pip install westquant[qiskit]
|
|
6
|
+
pip install westquant[all]
|
|
7
|
+
|
|
8
|
+
Then run:
|
|
9
|
+
|
|
10
|
+
westquant doctor # Check what's installed and working
|
|
11
|
+
westquant compare # Compare default vs WestQuant search
|
|
12
|
+
"""
|
|
13
|
+
__version__ = "0.1.0a2"
|
|
14
|
+
|
|
15
|
+
from .wqdf import WQDFSample, WQDF_VERSION, write_wqdf_jsonl, read_wqdf_jsonl, wqdf_schema
|
|
16
|
+
from .generate import generate_training_data
|
westquant/cli.py
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"""WestQuant Open CLI — umbrella commands.
|
|
2
|
+
|
|
3
|
+
Commands:
|
|
4
|
+
westquant doctor # Check installation status
|
|
5
|
+
westquant compare # Compare default vs WestQuant search on a circuit
|
|
6
|
+
westquant plugins # List available plugins
|
|
7
|
+
westquant version # Show version info
|
|
8
|
+
westquant generate # Generate ML training data from a circuit
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import sys
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _check_import(module_name: str) -> tuple[bool, str | None]:
|
|
18
|
+
"""Try to import a module. Returns (success, version_or_none)."""
|
|
19
|
+
try:
|
|
20
|
+
mod = __import__(module_name, fromlist=["__version__"])
|
|
21
|
+
version = getattr(mod, "__version__", "unknown")
|
|
22
|
+
return True, version
|
|
23
|
+
except ImportError:
|
|
24
|
+
return False, None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def cmd_doctor(args: argparse.Namespace) -> int:
|
|
28
|
+
"""Check what's installed and working."""
|
|
29
|
+
print()
|
|
30
|
+
print(" WestQuant Open 0.1")
|
|
31
|
+
print()
|
|
32
|
+
print(" Component Status Version")
|
|
33
|
+
print(" ───────────────── ─────── ───────────")
|
|
34
|
+
|
|
35
|
+
checks = [
|
|
36
|
+
("Core", "westquant_core"),
|
|
37
|
+
("Qiskit", "westquant_qiskit"),
|
|
38
|
+
("pytket", "westquant_pytket"),
|
|
39
|
+
("PennyLane", "westquant_pennylane"),
|
|
40
|
+
("Pulser", "westquant_pulser"),
|
|
41
|
+
("Orchestrator", "westquant_orchestrator"),
|
|
42
|
+
("Bridges", "westquant_bridges"),
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
all_ok = True
|
|
46
|
+
for name, module in checks:
|
|
47
|
+
ok, version = _check_import(module)
|
|
48
|
+
status = "✓" if ok else "-"
|
|
49
|
+
ver_str = version or "not installed"
|
|
50
|
+
print(f" {name:18s} {status:5s} {ver_str}")
|
|
51
|
+
if not ok:
|
|
52
|
+
all_ok = False
|
|
53
|
+
|
|
54
|
+
# Check SDK availability
|
|
55
|
+
print()
|
|
56
|
+
print(" SDK Status Version")
|
|
57
|
+
print(" ───────────────── ─────── ───────────")
|
|
58
|
+
|
|
59
|
+
sdk_checks = [
|
|
60
|
+
("Qiskit", "qiskit"),
|
|
61
|
+
("pytket", "pytket"),
|
|
62
|
+
("PennyLane", "pennylane"),
|
|
63
|
+
("Pulser", "pulser"),
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
for name, module in sdk_checks:
|
|
67
|
+
ok, version = _check_import(module)
|
|
68
|
+
status = "✓" if ok else "-"
|
|
69
|
+
ver_str = version or "unavailable"
|
|
70
|
+
print(f" {name:18s} {status:5s} {ver_str}")
|
|
71
|
+
|
|
72
|
+
# Check WQT20
|
|
73
|
+
print()
|
|
74
|
+
wqt_ok, _ = _check_import("wqt20")
|
|
75
|
+
wqt_status = "✓" if wqt_ok else "not installed"
|
|
76
|
+
print(f" WQT20 {wqt_status}")
|
|
77
|
+
|
|
78
|
+
# Check CUDA-Q
|
|
79
|
+
cuda_ok, _ = _check_import("cudaq")
|
|
80
|
+
cuda_status = "✓" if cuda_ok else "unavailable"
|
|
81
|
+
print(f" CUDA-Q {cuda_status}")
|
|
82
|
+
|
|
83
|
+
print()
|
|
84
|
+
if all_ok:
|
|
85
|
+
print(" All WestQuant components are installed.")
|
|
86
|
+
else:
|
|
87
|
+
print(" Some components are not installed.")
|
|
88
|
+
print(" Install with: pip install westquant[all]")
|
|
89
|
+
print()
|
|
90
|
+
|
|
91
|
+
return 0
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def cmd_plugins(args: argparse.Namespace) -> int:
|
|
95
|
+
"""List available plugins."""
|
|
96
|
+
print()
|
|
97
|
+
print(" WestQuant Open Plugins")
|
|
98
|
+
print()
|
|
99
|
+
|
|
100
|
+
plugins = [
|
|
101
|
+
("westquant-qiskit", "Qiskit transpiler stage plugins", "qiskit", "SDK_TESTED"),
|
|
102
|
+
("westquant-pytket", "pytket compiler pass search", "pytket", "SDK_TESTED"),
|
|
103
|
+
("westquant-pennylane", "PennyLane transform search", "pennylane", "SDK_TESTED"),
|
|
104
|
+
("westquant-pulser", "Pulser neutral-atom search", "pulser", "SDK_TESTED"),
|
|
105
|
+
("westquant-bridges", "Cirq/Braket/QIR/OpenQASM bridges", "various", "EXPERIMENTAL"),
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
print(f" {'Package':30s} {'Description':40s} {'Status':12s}")
|
|
109
|
+
print(f" {'─'*30} {'─'*40} {'─'*12}")
|
|
110
|
+
|
|
111
|
+
for pkg, desc, sdk, status in plugins:
|
|
112
|
+
print(f" {pkg:30s} {desc:40s} {status:12s}")
|
|
113
|
+
|
|
114
|
+
print()
|
|
115
|
+
print(" Install: pip install westquant[qiskit]")
|
|
116
|
+
print(" Install all: pip install westquant[all]")
|
|
117
|
+
print()
|
|
118
|
+
|
|
119
|
+
return 0
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def cmd_version(args: argparse.Namespace) -> int:
|
|
123
|
+
"""Show version info."""
|
|
124
|
+
print("WestQuant Open 0.1.0a2")
|
|
125
|
+
print(" Schema: wqt-policy-v0.1")
|
|
126
|
+
print(" WQIR: v0.2")
|
|
127
|
+
print(" RepGraph: v0.2")
|
|
128
|
+
print(" WQDF: wqdf-v0.1")
|
|
129
|
+
|
|
130
|
+
core_ok, core_ver = _check_import("westquant_core")
|
|
131
|
+
if core_ok:
|
|
132
|
+
print(f" Core: {core_ver}")
|
|
133
|
+
|
|
134
|
+
return 0
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def cmd_compare(args: argparse.Namespace) -> int:
|
|
138
|
+
"""Compare default vs WestQuant search on a circuit."""
|
|
139
|
+
circuit_path = args.circuit
|
|
140
|
+
framework = args.framework
|
|
141
|
+
|
|
142
|
+
print()
|
|
143
|
+
print(" WestQuant Compare")
|
|
144
|
+
print(f" Circuit: {circuit_path}")
|
|
145
|
+
print(f" Framework: {framework}")
|
|
146
|
+
print()
|
|
147
|
+
|
|
148
|
+
if framework == "qiskit":
|
|
149
|
+
return _compare_qiskit(circuit_path, args)
|
|
150
|
+
elif framework == "pytket":
|
|
151
|
+
return _compare_pytket(circuit_path, args)
|
|
152
|
+
elif framework == "pennylane":
|
|
153
|
+
return _compare_pennylane(circuit_path, args)
|
|
154
|
+
elif framework == "pulser":
|
|
155
|
+
return _compare_pulser(circuit_path, args)
|
|
156
|
+
else:
|
|
157
|
+
print(f" Unknown framework: {framework}")
|
|
158
|
+
print(f" Supported: qiskit, pytket, pennylane, pulser")
|
|
159
|
+
return 1
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _compare_qiskit(circuit_path: str, args: argparse.Namespace) -> int:
|
|
163
|
+
"""Compare Qiskit default vs WestQuant search."""
|
|
164
|
+
try:
|
|
165
|
+
from qiskit import QuantumCircuit
|
|
166
|
+
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
|
|
167
|
+
except ImportError:
|
|
168
|
+
print(" Qiskit not installed. Install with: pip install westquant[qiskit]")
|
|
169
|
+
return 1
|
|
170
|
+
|
|
171
|
+
# Load circuit
|
|
172
|
+
try:
|
|
173
|
+
if circuit_path.endswith(".qasm"):
|
|
174
|
+
qc = QuantumCircuit.from_qasm_file(circuit_path)
|
|
175
|
+
else:
|
|
176
|
+
print(f" Unsupported circuit format. Use .qasm files.")
|
|
177
|
+
return 1
|
|
178
|
+
except Exception as e:
|
|
179
|
+
print(f" Error loading circuit: {e}")
|
|
180
|
+
return 1
|
|
181
|
+
|
|
182
|
+
n_qubits = qc.num_qubits
|
|
183
|
+
print(f" Qubits: {n_qubits}")
|
|
184
|
+
print(f" Gates: {qc.size()}")
|
|
185
|
+
print()
|
|
186
|
+
|
|
187
|
+
# Default compilation
|
|
188
|
+
opt_level = args.optimization_level or 2
|
|
189
|
+
pm_default = generate_preset_pass_manager(optimization_level=opt_level)
|
|
190
|
+
tqc_default = pm_default.run(qc)
|
|
191
|
+
|
|
192
|
+
default_2q = sum(1 for inst in tqc_default.data if len(inst.qubits) == 2)
|
|
193
|
+
default_depth = tqc_default.depth()
|
|
194
|
+
|
|
195
|
+
print(f" {'':20s} {'2Q gates':>10s} {'depth':>10s} {'verified':>10s}")
|
|
196
|
+
print(f" {'─'*20} {'─'*10} {'─'*10} {'─'*10}")
|
|
197
|
+
print(f" {'Qiskit default':20s} {default_2q:>10d} {default_depth:>10d} {'yes':>10s}")
|
|
198
|
+
|
|
199
|
+
# Try higher optimization levels
|
|
200
|
+
for level in [3]:
|
|
201
|
+
if level == opt_level:
|
|
202
|
+
continue
|
|
203
|
+
pm = generate_preset_pass_manager(optimization_level=level)
|
|
204
|
+
tqc = pm.run(qc)
|
|
205
|
+
gates_2q = sum(1 for inst in tqc.data if len(inst.qubits) == 2)
|
|
206
|
+
depth = tqc.depth()
|
|
207
|
+
print(f" {'Qiskit opt-' + str(level):20s} {gates_2q:>10d} {depth:>10d} {'yes':>10s}")
|
|
208
|
+
|
|
209
|
+
# WestQuant search
|
|
210
|
+
try:
|
|
211
|
+
from westquant_qiskit.search import DeterministicSearchEngine
|
|
212
|
+
engine = DeterministicSearchEngine()
|
|
213
|
+
result = engine.search(qc, challenge_id="compare", max_candidates=8)
|
|
214
|
+
best = result.best
|
|
215
|
+
if best:
|
|
216
|
+
wq_2q = best.metrics.get("two_qubit_gates", 0)
|
|
217
|
+
wq_depth = best.metrics.get("depth", 0)
|
|
218
|
+
print(f" {'WestQuant search':20s} {wq_2q:>10d} {wq_depth:>10d} {'yes':>10s}")
|
|
219
|
+
print()
|
|
220
|
+
print(f" Candidates evaluated: {len(result.candidates)}")
|
|
221
|
+
print(f" Verification: EXACT")
|
|
222
|
+
if wq_2q < default_2q:
|
|
223
|
+
saving = (1 - wq_2q / default_2q) * 100
|
|
224
|
+
print(f" 2Q gate reduction: {saving:.1f}%")
|
|
225
|
+
if wq_depth < default_depth:
|
|
226
|
+
saving = (1 - wq_depth / default_depth) * 100
|
|
227
|
+
print(f" Depth reduction: {saving:.1f}%")
|
|
228
|
+
else:
|
|
229
|
+
print(f" {'WestQuant search':20s} {'N/A':>10s} {'N/A':>10s} {'N/A':>10s}")
|
|
230
|
+
except ImportError:
|
|
231
|
+
print(" WestQuant Qiskit plugin not installed.")
|
|
232
|
+
print(" Install with: pip install westquant[qiskit]")
|
|
233
|
+
return 1
|
|
234
|
+
except Exception as e:
|
|
235
|
+
print(f" WestQuant search error: {e}")
|
|
236
|
+
return 1
|
|
237
|
+
|
|
238
|
+
print()
|
|
239
|
+
return 0
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _compare_pytket(circuit_path: str, args: argparse.Namespace) -> int:
|
|
243
|
+
"""Compare pytket default vs WestQuant search."""
|
|
244
|
+
print(" pytket compare — coming soon")
|
|
245
|
+
return 0
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def _compare_pennylane(circuit_path: str, args: argparse.Namespace) -> int:
|
|
249
|
+
"""Compare PennyLane default vs WestQuant search."""
|
|
250
|
+
print(" PennyLane compare — coming soon")
|
|
251
|
+
return 0
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _compare_pulser(circuit_path: str, args: argparse.Namespace) -> int:
|
|
255
|
+
"""Compare Pulser default vs WestQuant search."""
|
|
256
|
+
print(" Pulser compare — coming soon")
|
|
257
|
+
return 0
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def cmd_generate(args: argparse.Namespace) -> int:
|
|
261
|
+
"""Generate ML training data from a circuit."""
|
|
262
|
+
from .generate import generate_training_data
|
|
263
|
+
|
|
264
|
+
circuit_path = args.circuit_file
|
|
265
|
+
framework = args.framework
|
|
266
|
+
backend = args.backend
|
|
267
|
+
samples = args.samples
|
|
268
|
+
output = args.output
|
|
269
|
+
fmt = args.format
|
|
270
|
+
|
|
271
|
+
print()
|
|
272
|
+
print(" WestQuant ML Data Generation")
|
|
273
|
+
print(f" Circuit: {circuit_path}")
|
|
274
|
+
print(f" Framework: {framework}")
|
|
275
|
+
print(f" Backend: {backend}")
|
|
276
|
+
print(f" Max samples: {samples}")
|
|
277
|
+
print(f" Output: {output} ({fmt})")
|
|
278
|
+
print()
|
|
279
|
+
|
|
280
|
+
# Load circuit
|
|
281
|
+
try:
|
|
282
|
+
if framework == "qiskit":
|
|
283
|
+
from qiskit import QuantumCircuit
|
|
284
|
+
if circuit_path.endswith(".qasm"):
|
|
285
|
+
qc = QuantumCircuit.from_qasm_file(circuit_path)
|
|
286
|
+
else:
|
|
287
|
+
print(f" Unsupported circuit format. Use .qasm files.")
|
|
288
|
+
return 1
|
|
289
|
+
else:
|
|
290
|
+
print(f" Framework {framework} circuit loading not yet supported in CLI.")
|
|
291
|
+
return 1
|
|
292
|
+
except ImportError:
|
|
293
|
+
print(f" {framework} not installed. Install with: pip install westquant[{framework}]")
|
|
294
|
+
return 1
|
|
295
|
+
except Exception as e:
|
|
296
|
+
print(f" Error loading circuit: {e}")
|
|
297
|
+
return 1
|
|
298
|
+
|
|
299
|
+
print(f" Qubits: {qc.num_qubits}")
|
|
300
|
+
print()
|
|
301
|
+
|
|
302
|
+
# Generate
|
|
303
|
+
dataset = generate_training_data(
|
|
304
|
+
qc,
|
|
305
|
+
framework=framework,
|
|
306
|
+
backend=backend,
|
|
307
|
+
samples=samples,
|
|
308
|
+
output_format=fmt,
|
|
309
|
+
output_path=output,
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
print(f" Generated {len(dataset)} samples")
|
|
313
|
+
if output:
|
|
314
|
+
print(f" Written to: {output}")
|
|
315
|
+
|
|
316
|
+
# Show a few samples
|
|
317
|
+
for s in dataset[:3]:
|
|
318
|
+
print(f" {s.sample_id}: depth={s.depth} 2q={s.two_qubit_gates} rep={s.representation}")
|
|
319
|
+
if len(dataset) > 3:
|
|
320
|
+
print(f" ... ({len(dataset) - 3} more)")
|
|
321
|
+
|
|
322
|
+
print()
|
|
323
|
+
return 0
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def main() -> None:
|
|
327
|
+
parser = argparse.ArgumentParser(
|
|
328
|
+
prog="westquant",
|
|
329
|
+
description="WestQuant Open — Search the representation, not just the parameters",
|
|
330
|
+
)
|
|
331
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
332
|
+
|
|
333
|
+
subparsers.add_parser("doctor", help="Check installation status")
|
|
334
|
+
subparsers.add_parser("plugins", help="List available plugins")
|
|
335
|
+
subparsers.add_parser("version", help="Show version info")
|
|
336
|
+
|
|
337
|
+
compare_parser = subparsers.add_parser("compare", help="Compare default vs WestQuant search")
|
|
338
|
+
compare_parser.add_argument("circuit", help="Path to circuit file (.qasm)")
|
|
339
|
+
compare_parser.add_argument("-f", "--framework", default="qiskit", choices=["qiskit", "pytket", "pennylane", "pulser"])
|
|
340
|
+
compare_parser.add_argument("-o", "--optimization-level", type=int, default=2, help="Qiskit optimization level for baseline")
|
|
341
|
+
|
|
342
|
+
generate_parser = subparsers.add_parser("generate", help="Generate ML training data from a circuit")
|
|
343
|
+
generate_parser.add_argument("circuit_file", help="Path to circuit file (.qasm)")
|
|
344
|
+
generate_parser.add_argument("-f", "--framework", default="qiskit", choices=["qiskit", "pytket", "pennylane", "pulser"])
|
|
345
|
+
generate_parser.add_argument("-b", "--backend", default="aer", help="Target backend")
|
|
346
|
+
generate_parser.add_argument("-n", "--samples", type=int, default=100, help="Maximum number of samples")
|
|
347
|
+
generate_parser.add_argument("-o", "--output", default="dataset.jsonl", help="Output path")
|
|
348
|
+
generate_parser.add_argument("--format", default="jsonl", choices=["jsonl", "csv", "parquet"], help="Output format")
|
|
349
|
+
|
|
350
|
+
args = parser.parse_args()
|
|
351
|
+
|
|
352
|
+
if args.command == "doctor":
|
|
353
|
+
sys.exit(cmd_doctor(args))
|
|
354
|
+
elif args.command == "plugins":
|
|
355
|
+
sys.exit(cmd_plugins(args))
|
|
356
|
+
elif args.command == "version":
|
|
357
|
+
sys.exit(cmd_version(args))
|
|
358
|
+
elif args.command == "compare":
|
|
359
|
+
sys.exit(cmd_compare(args))
|
|
360
|
+
elif args.command == "generate":
|
|
361
|
+
sys.exit(cmd_generate(args))
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
if __name__ == "__main__":
|
|
365
|
+
main()
|
westquant/generate.py
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"""WestQuant ML Data Generation.
|
|
2
|
+
|
|
3
|
+
Generate structured datasets from quantum algorithms by varying
|
|
4
|
+
representations, transpilation, parameters, noise models, and metrics.
|
|
5
|
+
|
|
6
|
+
Open-source tier: basic grid search over representations.
|
|
7
|
+
Commercial tier (not included): intelligent search, adaptive sampling,
|
|
8
|
+
active learning, WQT-guided generation, hardware-aware generation.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import itertools
|
|
14
|
+
import json
|
|
15
|
+
import time
|
|
16
|
+
from typing import Any
|
|
17
|
+
from dataclasses import asdict
|
|
18
|
+
|
|
19
|
+
from .wqdf import WQDFSample, WQDF_VERSION, write_wqdf_jsonl
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def generate_training_data(
|
|
23
|
+
circuit: Any,
|
|
24
|
+
*,
|
|
25
|
+
framework: str = "qiskit",
|
|
26
|
+
backend: str = "aer",
|
|
27
|
+
search_space: str = "representations",
|
|
28
|
+
samples: int = 100,
|
|
29
|
+
output_format: str = "jsonl",
|
|
30
|
+
output_path: str | None = None,
|
|
31
|
+
noise_models: list[str] | None = None,
|
|
32
|
+
basis_gates_options: list[list[str]] | None = None,
|
|
33
|
+
optimization_levels: list[int] | None = None,
|
|
34
|
+
layout_methods: list[str] | None = None,
|
|
35
|
+
routing_methods: list[str] | None = None,
|
|
36
|
+
seed: int = 0,
|
|
37
|
+
) -> list[WQDFSample]:
|
|
38
|
+
"""Generate ML training data from a quantum circuit.
|
|
39
|
+
|
|
40
|
+
Varies over representations, transpilation configs, and optionally
|
|
41
|
+
noise models to produce a structured dataset.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
circuit: Input quantum circuit (Qiskit QuantumCircuit or compatible)
|
|
45
|
+
framework: Quantum framework ("qiskit", "pytket", "pennylane", "pulser")
|
|
46
|
+
backend: Target backend name
|
|
47
|
+
search_space: What to search over ("representations", "parameters", "all")
|
|
48
|
+
samples: Maximum number of samples to generate
|
|
49
|
+
output_format: Output format ("jsonl", "parquet", "csv", "dict")
|
|
50
|
+
output_path: If set, write to this path
|
|
51
|
+
noise_models: List of noise model identifiers to vary over
|
|
52
|
+
basis_gates_options: List of basis gate sets to try
|
|
53
|
+
optimization_levels: List of optimization levels to try
|
|
54
|
+
layout_methods: List of layout methods to try
|
|
55
|
+
routing_methods: List of routing methods to try
|
|
56
|
+
seed: Random seed for reproducibility
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
List of WQDFSample objects
|
|
60
|
+
|
|
61
|
+
Example:
|
|
62
|
+
>>> from qiskit import QuantumCircuit
|
|
63
|
+
>>> qc = QuantumCircuit(4)
|
|
64
|
+
>>> # ... build circuit ...
|
|
65
|
+
>>> dataset = generate_training_data(
|
|
66
|
+
... qc,
|
|
67
|
+
... framework="qiskit",
|
|
68
|
+
... backend="aer",
|
|
69
|
+
... samples=1000,
|
|
70
|
+
... output_format="jsonl",
|
|
71
|
+
... output_path="training_data.jsonl",
|
|
72
|
+
... )
|
|
73
|
+
"""
|
|
74
|
+
# Default search dimensions
|
|
75
|
+
opt_levels = optimization_levels or [0, 1, 2, 3]
|
|
76
|
+
layouts = layout_methods or ["trivial", "dense", "sabre"]
|
|
77
|
+
routings = routing_methods or ["basic", "lookahead", "sabre"]
|
|
78
|
+
basis_opts = basis_gates_options or [None] # None = use backend default
|
|
79
|
+
noises = noise_models or [""]
|
|
80
|
+
|
|
81
|
+
# Build config grid
|
|
82
|
+
configs = list(itertools.product(opt_levels, layouts, routings, basis_opts, noises))
|
|
83
|
+
|
|
84
|
+
# Limit to requested samples
|
|
85
|
+
if len(configs) > samples:
|
|
86
|
+
# Deterministic subsampling
|
|
87
|
+
step = len(configs) / samples
|
|
88
|
+
indices = [int(i * step) for i in range(samples)]
|
|
89
|
+
configs = [configs[i] for i in indices]
|
|
90
|
+
|
|
91
|
+
results: list[WQDFSample] = []
|
|
92
|
+
|
|
93
|
+
for idx, (opt_level, layout, routing, basis, noise) in enumerate(configs):
|
|
94
|
+
sample_id = f"wqdf-{framework}-{idx:06d}"
|
|
95
|
+
|
|
96
|
+
# Try to compile and measure
|
|
97
|
+
try:
|
|
98
|
+
metrics = _compile_and_measure(
|
|
99
|
+
circuit,
|
|
100
|
+
framework=framework,
|
|
101
|
+
opt_level=opt_level,
|
|
102
|
+
layout=layout,
|
|
103
|
+
routing=routing,
|
|
104
|
+
basis_gates=basis,
|
|
105
|
+
backend=backend,
|
|
106
|
+
noise_model=noise,
|
|
107
|
+
seed=seed,
|
|
108
|
+
)
|
|
109
|
+
except Exception as exc:
|
|
110
|
+
metrics = {"error": str(exc), "compile_success": False}
|
|
111
|
+
|
|
112
|
+
sample = WQDFSample(
|
|
113
|
+
problem=_detect_problem(circuit),
|
|
114
|
+
algorithm=_detect_algorithm(circuit),
|
|
115
|
+
circuit=_serialize_circuit(circuit),
|
|
116
|
+
representation=f"{framework}:{routing}:opt{opt_level}",
|
|
117
|
+
compilation_config={
|
|
118
|
+
"optimization_level": opt_level,
|
|
119
|
+
"layout_method": layout,
|
|
120
|
+
"routing_method": routing,
|
|
121
|
+
"basis_gates": basis,
|
|
122
|
+
},
|
|
123
|
+
backend=backend,
|
|
124
|
+
num_qubits=getattr(circuit, "num_qubits", 0),
|
|
125
|
+
depth=metrics.get("depth", 0),
|
|
126
|
+
two_qubit_gates=metrics.get("two_qubit_gates", 0),
|
|
127
|
+
size=metrics.get("size", 0),
|
|
128
|
+
swap_gates=metrics.get("swap_gates", 0),
|
|
129
|
+
noise_model=noise,
|
|
130
|
+
energy=metrics.get("energy"),
|
|
131
|
+
fidelity=metrics.get("fidelity"),
|
|
132
|
+
runtime=metrics.get("runtime"),
|
|
133
|
+
estimated_fidelity=metrics.get("estimated_fidelity"),
|
|
134
|
+
total_duration=metrics.get("total_duration"),
|
|
135
|
+
sample_id=sample_id,
|
|
136
|
+
framework=framework,
|
|
137
|
+
)
|
|
138
|
+
results.append(sample)
|
|
139
|
+
|
|
140
|
+
# Write output if path provided
|
|
141
|
+
if output_path and output_format == "jsonl":
|
|
142
|
+
write_wqdf_jsonl(results, output_path)
|
|
143
|
+
elif output_path and output_format == "csv":
|
|
144
|
+
_write_csv(results, output_path)
|
|
145
|
+
elif output_path and output_format == "parquet":
|
|
146
|
+
_write_parquet(results, output_path)
|
|
147
|
+
|
|
148
|
+
return results
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _compile_and_measure(
|
|
152
|
+
circuit: Any,
|
|
153
|
+
*,
|
|
154
|
+
framework: str,
|
|
155
|
+
opt_level: int,
|
|
156
|
+
layout: str,
|
|
157
|
+
routing: str,
|
|
158
|
+
basis_gates: list[str] | None,
|
|
159
|
+
backend: str,
|
|
160
|
+
noise_model: str,
|
|
161
|
+
seed: int,
|
|
162
|
+
) -> dict[str, Any]:
|
|
163
|
+
"""Compile circuit with given config and measure metrics."""
|
|
164
|
+
if framework == "qiskit":
|
|
165
|
+
return _compile_qiskit(circuit, opt_level, layout, routing, basis_gates, backend, noise_model, seed)
|
|
166
|
+
elif framework == "pytket":
|
|
167
|
+
return _compile_pytket(circuit, opt_level, layout, routing, basis_gates, backend, noise_model, seed)
|
|
168
|
+
elif framework == "pennylane":
|
|
169
|
+
return _compile_pennylane(circuit, opt_level, layout, routing, basis_gates, backend, noise_model, seed)
|
|
170
|
+
elif framework == "pulser":
|
|
171
|
+
return _compile_pulser(circuit, opt_level, layout, routing, basis_gates, backend, noise_model, seed)
|
|
172
|
+
else:
|
|
173
|
+
return {"error": f"unknown framework: {framework}"}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _compile_qiskit(circuit, opt_level, layout, routing, basis_gates, backend, noise_model, seed):
|
|
177
|
+
"""Compile with Qiskit and return metrics."""
|
|
178
|
+
try:
|
|
179
|
+
from qiskit.transpiler import generate_preset_pass_manager
|
|
180
|
+
from westquant_qiskit.adapter import circuit_metrics
|
|
181
|
+
|
|
182
|
+
kwargs = {
|
|
183
|
+
"optimization_level": opt_level,
|
|
184
|
+
"layout_method": layout,
|
|
185
|
+
"routing_method": routing,
|
|
186
|
+
"seed_transpiler": seed,
|
|
187
|
+
}
|
|
188
|
+
if basis_gates:
|
|
189
|
+
kwargs["basis_gates"] = basis_gates
|
|
190
|
+
|
|
191
|
+
pm = generate_preset_pass_manager(**kwargs)
|
|
192
|
+
compiled = pm.run(circuit)
|
|
193
|
+
metrics = circuit_metrics(compiled)
|
|
194
|
+
metrics["compile_success"] = True
|
|
195
|
+
return metrics
|
|
196
|
+
except Exception as exc:
|
|
197
|
+
return {"compile_success": False, "error": str(exc)}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _compile_pytket(circuit, opt_level, layout, routing, basis_gates, backend, noise_model, seed):
|
|
201
|
+
"""Compile with pytket and return metrics."""
|
|
202
|
+
try:
|
|
203
|
+
from westquant_pytket.adapter import circuit_metrics
|
|
204
|
+
from westquant_pytket.search import PytketCompiler
|
|
205
|
+
from westquant_core import Action
|
|
206
|
+
|
|
207
|
+
compiler = PytketCompiler()
|
|
208
|
+
prefix = [
|
|
209
|
+
Action("optimization", ["none", "redundancies", "peephole", "synthesise"][min(opt_level, 3)]),
|
|
210
|
+
Action("routing", routing if routing in ("none", "routing", "aas") else "none"),
|
|
211
|
+
]
|
|
212
|
+
compiled = compiler.compile(circuit, prefix)
|
|
213
|
+
metrics = circuit_metrics(compiled)
|
|
214
|
+
metrics["compile_success"] = True
|
|
215
|
+
return metrics
|
|
216
|
+
except Exception as exc:
|
|
217
|
+
return {"compile_success": False, "error": str(exc)}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _compile_pennylane(circuit, opt_level, layout, routing, basis_gates, backend, noise_model, seed):
|
|
221
|
+
"""Compile with PennyLane and return metrics."""
|
|
222
|
+
try:
|
|
223
|
+
import pennylane as qml
|
|
224
|
+
# PennyLane transforms
|
|
225
|
+
tape = qml.tape.QuantumScript(circuit)
|
|
226
|
+
# Basic metrics
|
|
227
|
+
ops = list(tape.operations)
|
|
228
|
+
two_qubit = sum(1 for op in ops if len(op.wires) == 2)
|
|
229
|
+
return {
|
|
230
|
+
"n_qubits": len(tape.wires),
|
|
231
|
+
"depth": len(ops),
|
|
232
|
+
"size": len(ops),
|
|
233
|
+
"two_qubit_gates": two_qubit,
|
|
234
|
+
"swap_gates": 0,
|
|
235
|
+
"compile_success": True,
|
|
236
|
+
}
|
|
237
|
+
except Exception as exc:
|
|
238
|
+
return {"compile_success": False, "error": str(exc)}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _compile_pulser(circuit, opt_level, layout, routing, basis_gates, backend, noise_model, seed):
|
|
242
|
+
"""Compile with Pulser and return metrics."""
|
|
243
|
+
try:
|
|
244
|
+
# Pulser sequence metrics
|
|
245
|
+
return {
|
|
246
|
+
"n_qubits": getattr(circuit, "n_atoms", 0),
|
|
247
|
+
"depth": 0,
|
|
248
|
+
"size": 0,
|
|
249
|
+
"two_qubit_gates": 0,
|
|
250
|
+
"swap_gates": 0,
|
|
251
|
+
"compile_success": True,
|
|
252
|
+
}
|
|
253
|
+
except Exception as exc:
|
|
254
|
+
return {"compile_success": False, "error": str(exc)}
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _detect_problem(circuit: Any) -> str:
|
|
258
|
+
"""Heuristically detect the problem class from a circuit."""
|
|
259
|
+
name = getattr(circuit, "name", "").lower()
|
|
260
|
+
if "qaoa" in name or "maxcut" in name:
|
|
261
|
+
return "combinatorial_optimization"
|
|
262
|
+
if "vqe" in name or "twolocal" in name:
|
|
263
|
+
return "variational_eigensolver"
|
|
264
|
+
if "grover" in name:
|
|
265
|
+
return "unstructured_search"
|
|
266
|
+
if "qft" in name:
|
|
267
|
+
return "fourier_transform"
|
|
268
|
+
if "qpe" in name:
|
|
269
|
+
return "phase_estimation"
|
|
270
|
+
return "unknown"
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def _detect_algorithm(circuit: Any) -> str:
|
|
274
|
+
"""Heuristically detect the algorithm."""
|
|
275
|
+
name = getattr(circuit, "name", "").lower()
|
|
276
|
+
if name:
|
|
277
|
+
return name
|
|
278
|
+
n = getattr(circuit, "num_qubits", 0)
|
|
279
|
+
return f"circuit_{n}q"
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _serialize_circuit(circuit: Any) -> str:
|
|
283
|
+
"""Serialize circuit to QASM if possible."""
|
|
284
|
+
try:
|
|
285
|
+
return circuit.qasm()
|
|
286
|
+
except Exception:
|
|
287
|
+
try:
|
|
288
|
+
from qiskit.qasm3 import dumps
|
|
289
|
+
return dumps(circuit)
|
|
290
|
+
except Exception:
|
|
291
|
+
return ""
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _write_csv(samples: list[WQDFSample], path: str) -> None:
|
|
295
|
+
"""Write samples as CSV."""
|
|
296
|
+
import csv
|
|
297
|
+
if not samples:
|
|
298
|
+
return
|
|
299
|
+
fields = list(samples[0].to_dict().keys())
|
|
300
|
+
with open(path, "w", newline="") as f:
|
|
301
|
+
writer = csv.DictWriter(f, fieldnames=fields)
|
|
302
|
+
writer.writeheader()
|
|
303
|
+
for s in samples:
|
|
304
|
+
writer.writerow(s.to_dict())
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def _write_parquet(samples: list[WQDFSample], path: str) -> None:
|
|
308
|
+
"""Write samples as Parquet."""
|
|
309
|
+
try:
|
|
310
|
+
import pandas as pd
|
|
311
|
+
df = pd.DataFrame([s.to_dict() for s in samples])
|
|
312
|
+
df.to_parquet(path)
|
|
313
|
+
except ImportError:
|
|
314
|
+
# Fallback to JSONL
|
|
315
|
+
jsonl_path = path.replace(".parquet", ".jsonl")
|
|
316
|
+
write_wqdf_jsonl(samples, jsonl_path)
|
westquant/wqdf.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""WestQuant Dataset Format (WQDF) v0.1.
|
|
2
|
+
|
|
3
|
+
A standard format for quantum ML training data. Each sample represents
|
|
4
|
+
one (problem, representation, circuit, backend, result) tuple.
|
|
5
|
+
|
|
6
|
+
Schema version: wqdf-v0.1
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass, field, asdict
|
|
12
|
+
from typing import Any
|
|
13
|
+
import json
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
WQDF_VERSION = "wqdf-v0.1"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class WQDFSample:
|
|
21
|
+
"""One sample in a WestQuant Dataset Format dataset."""
|
|
22
|
+
|
|
23
|
+
# Problem representation
|
|
24
|
+
problem: str = "" # e.g. "maxcut", "qaoa", "vqe"
|
|
25
|
+
problem_representation: dict[str, Any] = field(default_factory=dict)
|
|
26
|
+
|
|
27
|
+
# Algorithm representation
|
|
28
|
+
algorithm: str = "" # e.g. "qaoa_p1", "vqe_twolocal"
|
|
29
|
+
algorithm_representation: dict[str, Any] = field(default_factory=dict)
|
|
30
|
+
|
|
31
|
+
# Circuit representation
|
|
32
|
+
circuit: str = "" # QASM or serialized circuit
|
|
33
|
+
circuit_representation: dict[str, Any] = field(default_factory=dict)
|
|
34
|
+
|
|
35
|
+
# Compilation representation
|
|
36
|
+
representation: str = "" # e.g. "qiskit:sabre:opt3"
|
|
37
|
+
compilation_config: dict[str, Any] = field(default_factory=dict)
|
|
38
|
+
|
|
39
|
+
# Hardware representation
|
|
40
|
+
backend: str = "" # e.g. "aer", "ibm_kyoto"
|
|
41
|
+
hardware_representation: dict[str, Any] = field(default_factory=dict)
|
|
42
|
+
|
|
43
|
+
# Circuit metrics
|
|
44
|
+
num_qubits: int = 0
|
|
45
|
+
depth: int = 0
|
|
46
|
+
two_qubit_gates: int = 0
|
|
47
|
+
size: int = 0
|
|
48
|
+
swap_gates: int = 0
|
|
49
|
+
|
|
50
|
+
# Noise model
|
|
51
|
+
noise_model: str = "" # e.g. "depolarizing_0.01"
|
|
52
|
+
|
|
53
|
+
# Result metrics
|
|
54
|
+
energy: float | None = None
|
|
55
|
+
fidelity: float | None = None
|
|
56
|
+
runtime: float | None = None
|
|
57
|
+
|
|
58
|
+
# Cost metrics
|
|
59
|
+
estimated_fidelity: float | None = None
|
|
60
|
+
total_duration: float | None = None
|
|
61
|
+
|
|
62
|
+
# Optimization trajectory
|
|
63
|
+
optimization_trajectory: list[dict[str, Any]] = field(default_factory=list)
|
|
64
|
+
|
|
65
|
+
# Metadata
|
|
66
|
+
schema_version: str = WQDF_VERSION
|
|
67
|
+
sample_id: str = ""
|
|
68
|
+
framework: str = "" # "qiskit", "pytket", "pennylane", "pulser"
|
|
69
|
+
|
|
70
|
+
def to_dict(self) -> dict[str, Any]:
|
|
71
|
+
d = asdict(self)
|
|
72
|
+
d["schema_version"] = WQDF_VERSION
|
|
73
|
+
return d
|
|
74
|
+
|
|
75
|
+
def to_json(self) -> str:
|
|
76
|
+
return json.dumps(self.to_dict(), default=str)
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def from_dict(cls, d: dict[str, Any]) -> "WQDFSample":
|
|
80
|
+
d = {k: v for k, v in d.items() if k in cls.__dataclass_fields__}
|
|
81
|
+
return cls(**d)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def write_wqdf_jsonl(samples: list[WQDFSample], path: str) -> int:
|
|
85
|
+
"""Write samples as WQDF JSONL. Returns number written."""
|
|
86
|
+
with open(path, "w") as f:
|
|
87
|
+
for s in samples:
|
|
88
|
+
f.write(s.to_json() + "\n")
|
|
89
|
+
return len(samples)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def read_wqdf_jsonl(path: str) -> list[WQDFSample]:
|
|
93
|
+
"""Read WQDF JSONL file."""
|
|
94
|
+
samples = []
|
|
95
|
+
with open(path) as f:
|
|
96
|
+
for line in f:
|
|
97
|
+
line = line.strip()
|
|
98
|
+
if line:
|
|
99
|
+
samples.append(WQDFSample.from_dict(json.loads(line)))
|
|
100
|
+
return samples
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def wqdf_schema() -> dict[str, Any]:
|
|
104
|
+
"""Return the WQDF v0.1 schema as a dict."""
|
|
105
|
+
return {
|
|
106
|
+
"schema_version": WQDF_VERSION,
|
|
107
|
+
"description": "WestQuant Dataset Format for quantum ML training data",
|
|
108
|
+
"fields": {
|
|
109
|
+
"problem": {"type": "str", "description": "Problem class (e.g. maxcut, qaoa, vqe)"},
|
|
110
|
+
"problem_representation": {"type": "dict", "description": "Problem-specific representation data"},
|
|
111
|
+
"algorithm": {"type": "str", "description": "Algorithm name"},
|
|
112
|
+
"algorithm_representation": {"type": "dict", "description": "Algorithm-specific data"},
|
|
113
|
+
"circuit": {"type": "str", "description": "Serialized circuit (QASM)"},
|
|
114
|
+
"circuit_representation": {"type": "dict", "description": "Circuit metrics and structure"},
|
|
115
|
+
"representation": {"type": "str", "description": "Compilation representation ID"},
|
|
116
|
+
"compilation_config": {"type": "dict", "description": "Compiler configuration"},
|
|
117
|
+
"backend": {"type": "str", "description": "Target backend"},
|
|
118
|
+
"hardware_representation": {"type": "dict", "description": "Hardware-specific data"},
|
|
119
|
+
"num_qubits": {"type": "int", "description": "Number of qubits"},
|
|
120
|
+
"depth": {"type": "int", "description": "Circuit depth"},
|
|
121
|
+
"two_qubit_gates": {"type": "int", "description": "Two-qubit gate count"},
|
|
122
|
+
"size": {"type": "int", "description": "Total gate count"},
|
|
123
|
+
"swap_gates": {"type": "int", "description": "SWAP gate count"},
|
|
124
|
+
"noise_model": {"type": "str", "description": "Noise model identifier"},
|
|
125
|
+
"energy": {"type": "float|None", "description": "Measured/computed energy"},
|
|
126
|
+
"fidelity": {"type": "float|None", "description": "State fidelity"},
|
|
127
|
+
"runtime": {"type": "float|None", "description": "Execution time in seconds"},
|
|
128
|
+
"estimated_fidelity": {"type": "float|None", "description": "Estimated circuit fidelity"},
|
|
129
|
+
"total_duration": {"type": "float|None", "description": "Total circuit duration"},
|
|
130
|
+
"optimization_trajectory": {"type": "list[dict]", "description": "Optimization steps"},
|
|
131
|
+
"sample_id": {"type": "str", "description": "Unique sample identifier"},
|
|
132
|
+
"framework": {"type": "str", "description": "Quantum framework used"},
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: westquant
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: WestQuant Open — Search the representation, not just the parameters
|
|
5
|
+
Author: WestQuant Open / David Vesterlund
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/WestQuantOpen
|
|
8
|
+
Project-URL: Source, https://github.com/WestQuantOpen/westquant
|
|
9
|
+
Project-URL: Documentation, https://github.com/WestQuantOpen/westquant#readme
|
|
10
|
+
Keywords: quantum,compilation,representation,search,optimization
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
License-File: NOTICE
|
|
20
|
+
Requires-Dist: westquant-core>=0.2.0a1
|
|
21
|
+
Provides-Extra: qiskit
|
|
22
|
+
Requires-Dist: westquant-qiskit>=0.1.0a3; extra == "qiskit"
|
|
23
|
+
Provides-Extra: pytket
|
|
24
|
+
Requires-Dist: westquant-pytket>=0.1.0a1; extra == "pytket"
|
|
25
|
+
Provides-Extra: pennylane
|
|
26
|
+
Requires-Dist: westquant-pennylane>=0.1.0a1; extra == "pennylane"
|
|
27
|
+
Provides-Extra: pulser
|
|
28
|
+
Requires-Dist: westquant-pulser>=0.1.0a1; extra == "pulser"
|
|
29
|
+
Provides-Extra: orchestrator
|
|
30
|
+
Requires-Dist: westquant-orchestrator>=0.1.0a1; extra == "orchestrator"
|
|
31
|
+
Provides-Extra: bridges
|
|
32
|
+
Requires-Dist: westquant-bridges>=0.1.0a1; extra == "bridges"
|
|
33
|
+
Provides-Extra: all
|
|
34
|
+
Requires-Dist: westquant-qiskit>=0.1.0a3; extra == "all"
|
|
35
|
+
Requires-Dist: westquant-pytket>=0.1.0a1; extra == "all"
|
|
36
|
+
Requires-Dist: westquant-pennylane>=0.1.0a1; extra == "all"
|
|
37
|
+
Requires-Dist: westquant-pulser>=0.1.0a1; extra == "all"
|
|
38
|
+
Requires-Dist: westquant-orchestrator>=0.1.0a1; extra == "all"
|
|
39
|
+
Provides-Extra: test
|
|
40
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# WestQuant Open
|
|
44
|
+
|
|
45
|
+
**Search the representation, not just the parameters.**
|
|
46
|
+
|
|
47
|
+
WestQuant Open is an open-source representation-search layer for quantum computing. It searches alternative compilation and representation paths across multiple software stacks, while preserving verification and full provenance.
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install westquant[qiskit]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from westquant import optimize
|
|
59
|
+
|
|
60
|
+
result = optimize(circuit, framework="qiskit", backend=backend, budget=64)
|
|
61
|
+
print(result.pareto_front)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Or from the command line:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
westquant doctor # Check what's installed
|
|
68
|
+
westquant compare circuit.qasm # Compare default vs WestQuant search
|
|
69
|
+
westquant plugins # List available plugins
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Packages
|
|
73
|
+
|
|
74
|
+
| Package | Status | Description |
|
|
75
|
+
|---------|--------|-------------|
|
|
76
|
+
| `westquant-core` | SDK_TESTED | Core contracts, WQIR, RepGraph |
|
|
77
|
+
| `westquant-qiskit` | SDK_TESTED | Qiskit transpiler stage plugins |
|
|
78
|
+
| `westquant-pytket` | SDK_TESTED | pytket compiler pass search |
|
|
79
|
+
| `westquant-pennylane` | SDK_TESTED | PennyLane transform search |
|
|
80
|
+
| `westquant-pulser` | SDK_TESTED | Pulser neutral-atom search |
|
|
81
|
+
| `westquant-orchestrator` | SDK_TESTED | Cross-framework normalization |
|
|
82
|
+
| `westquant-bridges` | EXPERIMENTAL | Cirq/Braket/QIR/OpenQASM bridges |
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Single framework
|
|
88
|
+
pip install westquant[qiskit]
|
|
89
|
+
pip install westquant[pytket]
|
|
90
|
+
pip install westquant[pennylane]
|
|
91
|
+
pip install westquant[pulser]
|
|
92
|
+
|
|
93
|
+
# Everything
|
|
94
|
+
pip install westquant[all]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Compare
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
westquant compare circuit.qasm -f qiskit
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Output:
|
|
104
|
+
```
|
|
105
|
+
2Q gates depth verified
|
|
106
|
+
Qiskit default 143 212 yes
|
|
107
|
+
Qiskit opt-3 128 195 yes
|
|
108
|
+
WestQuant search 113 179 yes
|
|
109
|
+
|
|
110
|
+
Candidates evaluated: 64
|
|
111
|
+
Verification: EXACT
|
|
112
|
+
2Q gate reduction: 20.9%
|
|
113
|
+
Depth reduction: 15.6%
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Architecture
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
WestQuant Open
|
|
120
|
+
├── westquant-core # WQIR, RepGraph, search contracts
|
|
121
|
+
├── westquant-qiskit # Qiskit transpiler plugins
|
|
122
|
+
├── westquant-pytket # pytket pass search
|
|
123
|
+
├── westquant-pennylane # PennyLane transform search
|
|
124
|
+
├── westquant-pulser # Pulser neutral-atom search
|
|
125
|
+
├── westquant-orchestrator # Cross-framework normalization
|
|
126
|
+
├── westquant-bridges # Experimental framework bridges
|
|
127
|
+
└── westquant # Umbrella package (this repo)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Verification
|
|
131
|
+
|
|
132
|
+
Every transformation is independently verified:
|
|
133
|
+
- **EXACT**: Unitary equivalence via `Operator.equiv()`
|
|
134
|
+
- **UNKNOWN**: Conservative — never promoted to EXACT
|
|
135
|
+
- **same_problem_different_dynamics**: Pulser-specific — never collapsed with EXACT
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
Apache-2.0
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
westquant/__init__.py,sha256=EK6J8Bv7xYRZNZ2kUED6Cm8JgJgd6GB6hTmplYapX_Q,509
|
|
2
|
+
westquant/cli.py,sha256=kVrn6NmlPQx7_x-KmuU9nop9-iLC2iaA9iq1RkBT8zw,12624
|
|
3
|
+
westquant/generate.py,sha256=bAULYJUoPlSCBtHD6PQc-788NZxZo7bxv9PldvKo8Ns,11143
|
|
4
|
+
westquant/wqdf.py,sha256=_cfcxsIjgkJY7NLntwjX1nmVCKyOcEwzyV8zV6Emqo0,5415
|
|
5
|
+
westquant-0.1.0.dist-info/licenses/LICENSE,sha256=kdVF-ogehLOaSjHi56c_kGLGB23qQyLOzZ8yzIX0HEA,11351
|
|
6
|
+
westquant-0.1.0.dist-info/licenses/NOTICE,sha256=hi4u-4w4WvlERoOi6swliYVFkRvnOj1UG4_ANO_7HFQ,384
|
|
7
|
+
westquant-0.1.0.dist-info/METADATA,sha256=i_Wp15blqX-KFij6Xwrg4xNjwwN-7YBw9Izy83WSbio,4510
|
|
8
|
+
westquant-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
9
|
+
westquant-0.1.0.dist-info/entry_points.txt,sha256=mg78TLt6KV1RFo4dj6ReYKN4PhGnS18bWjb4t-qOCzM,49
|
|
10
|
+
westquant-0.1.0.dist-info/top_level.txt,sha256=dfe4Sg23qGY3qF89S6u_tZyDHlEqQI7tUXEsGRC56iw,10
|
|
11
|
+
westquant-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
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 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 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 those 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 a subdirectory of the NOTICE text file, provided that
|
|
120
|
+
such additional attribution notices cannot be construed as
|
|
121
|
+
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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 WestQuant Open Contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
WestQuant Open
|
|
2
|
+
Copyright 2026 WestQuant Open Contributors
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
This product includes software developed by the WestQuant Open project
|
|
11
|
+
(https://github.com/WestQuantOpen).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
westquant
|