itsalissonsilva commited on
Commit
97bf11c
·
verified ·
1 Parent(s): 8eb2152

Freeze fresh all-framework quantum circuits with phase gates, unseen angles and larger nonlocal stress holdouts

Browse files
curriculum_v2/LICENSE.md ADDED
@@ -0,0 +1 @@
 
 
1
+ Original generated circuits and numerical labels: CC BY 4.0, attributed to itsalissonsilva. Generator/rendering code: Apache-2.0. Framework implementations are not redistributed. Simulator versions and exact parity checks are recorded in manifest.json.
curriculum_v2/manifest.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "seed": 2026110101,
3
+ "rows_sha256": "e3e1e79a39f145c0eb1749ca28dd0ab07931eeac48bc9b5e45a281e425d2e348",
4
+ "renderer_source_sha256": "602ee257d443fd2457409b849823cfdbc566f3bbe11bc1fca7123abdac0fdfaf",
5
+ "versions": {
6
+ "numpy": "2.5.4",
7
+ "qiskit": "2.2.3",
8
+ "pennylane": "0.43.1",
9
+ "cirq": "1.6.1"
10
+ },
11
+ "groups": {
12
+ "train": 216,
13
+ "validation": 48,
14
+ "test_iid": 96,
15
+ "test_stress": 96
16
+ },
17
+ "rows": 1368,
18
+ "original_groups_excluded": 2000,
19
+ "scope": "Fresh follow-up, no original test circuits reused. All three frameworks occur in training. Held-out circuit groups and rotation angles; separate five/six-qubit long-range/deeper-circuit stress. Exact zero-input state fidelity only, not full process equivalence or novel quantum algorithms. Deterministic reference renderer is a perfect oracle on this structured task. Original framework-held-out negative result remains reported separately.",
20
+ "initial_generator_source_sha256": "5264ff94e7675c311bfda6bfe21511a56f2e28215d7b4242800212f90fd7740c"
21
+ }
curriculum_v2/prepare_quantum_v2.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Fresh all-framework curriculum after the failed zero-shot-framework pilot.
2
+
3
+ Keep the original framework-held-out result intact. This is a distinct follow-up
4
+ with fresh circuit groups, all three training frameworks, and unseen size/topology
5
+ and rotation-angle stress tests. Every target is executed in all three simulators.
6
+ """
7
+
8
+ import hashlib
9
+ import inspect
10
+ import json
11
+ import random
12
+ import sys
13
+ from pathlib import Path
14
+
15
+ ROOT = Path(__file__).resolve().parent
16
+ sys.path.insert(0, str(ROOT / "vendor_quantum"))
17
+ import numpy as np
18
+ import qiskit
19
+ import cirq
20
+ import pennylane as qml
21
+ import pyarrow.parquet as pq
22
+
23
+
24
+ def render(ops, n, framework):
25
+ if framework == "qiskit":
26
+ lines = [
27
+ "from qiskit import QuantumCircuit",
28
+ "from qiskit.quantum_info import Statevector",
29
+ f"circuit = QuantumCircuit({n})",
30
+ ]
31
+ for gate, qubits, angle in ops:
32
+ args = ([repr(angle)] if gate in ["ry", "rz"] else []) + [str(q) for q in qubits]
33
+ lines.append(f"circuit.{gate}({', '.join(args)})")
34
+ return "\n".join(lines + ["state = Statevector.from_instruction(circuit).data"])
35
+ if framework == "cirq":
36
+ lines = [
37
+ "import cirq",
38
+ "import numpy as np",
39
+ f"qubits = cirq.LineQubit.range({n})",
40
+ "circuit = cirq.Circuit()",
41
+ ]
42
+ for gate, qubits, angle in ops:
43
+ expr = (
44
+ f"cirq.{gate}({angle!r})"
45
+ if gate in ["ry", "rz"]
46
+ else {"h": "cirq.H", "x": "cirq.X", "z": "cirq.Z", "cx": "cirq.CNOT"}[gate]
47
+ )
48
+ lines.append(
49
+ f"circuit.append({expr}({', '.join('qubits[' + str(q) + ']' for q in qubits)}))"
50
+ )
51
+ return "\n".join(
52
+ lines
53
+ + [
54
+ "state = cirq.Simulator(dtype=np.complex128).simulate(circuit, qubit_order=list(reversed(qubits))).final_state_vector"
55
+ ]
56
+ )
57
+ lines = [
58
+ "import pennylane as qml",
59
+ f"device = qml.device('default.qubit', wires={list(reversed(range(n)))!r})",
60
+ "@qml.qnode(device)",
61
+ "def circuit():",
62
+ ]
63
+ names = {"h": "Hadamard", "x": "PauliX", "z": "PauliZ", "cx": "CNOT", "ry": "RY", "rz": "RZ"}
64
+ for gate, qubits, angle in ops:
65
+ lines.append(
66
+ f" qml.{names[gate]}({repr(angle) + ', ' if gate in ['ry', 'rz'] else ''}wires={qubits!r})"
67
+ )
68
+ return "\n".join(lines + [" return qml.state()", "state = circuit()"])
69
+
70
+
71
+ def main():
72
+ source = ROOT / "build_exact_science.py"
73
+ code = render
74
+ old_groups = set()
75
+ for split in ["train", "validation", "test"]:
76
+ old_groups.update(
77
+ pq.read_table(
78
+ ROOT / f"datasets/quantum-circuit-specs-synthetic/data/{split}.parquet",
79
+ columns=["group_id"],
80
+ )
81
+ .column("group_id")
82
+ .to_pylist()
83
+ )
84
+ folder = ROOT / "models/QuantumCoder-9B/curriculum_v2"
85
+ folder.mkdir(parents=True, exist_ok=True)
86
+ rng = random.Random(2026110101)
87
+ seen = set()
88
+ rows = []
89
+ protocol = [("train", 216), ("validation", 48), ("test_iid", 96), ("test_stress", 96)]
90
+ for split, worlds in protocol:
91
+ produced = 0
92
+ while produced < worlds:
93
+ stress = split == "test_stress"
94
+ n = rng.choice([5, 6] if stress else [2, 3, 4])
95
+ angles = (
96
+ [0.17, 0.31, 0.67, 1.13, 1.71, 2.29]
97
+ if split == "train"
98
+ else [0.23, 0.83, 1.27, 2.07]
99
+ if split == "validation"
100
+ else [0.11, 0.53, 0.97, 1.91, 2.61]
101
+ )
102
+ operations = []
103
+ for _ in range(rng.randrange(16, 25) if stress else rng.randrange(6, 14)):
104
+ gate = rng.choice(["h", "x", "z", "ry", "rz", "cx"])
105
+ q = rng.randrange(n)
106
+ if gate == "cx":
107
+ others = (
108
+ [j for j in range(n) if abs(j - q) >= 2]
109
+ if stress
110
+ else [j for j in range(n) if abs(j - q) == 1]
111
+ )
112
+ qs = [q, rng.choice(others)]
113
+ else:
114
+ qs = [q]
115
+ operations.append([gate, qs, rng.choice(angles) if gate in ["ry", "rz"] else 0.0])
116
+ if not {"h", "ry", "rz", "cx"}.issubset({op[0] for op in operations}):
117
+ continue
118
+ digest = hashlib.sha256(
119
+ json.dumps([n, operations], sort_keys=True).encode()
120
+ ).hexdigest()
121
+ if digest in seen or digest[:24] in old_groups:
122
+ continue
123
+ seen.add(digest)
124
+ programs = {f: code(operations, n, f) for f in ["qiskit", "pennylane", "cirq"]}
125
+ states = {}
126
+ # Only trusted renderer output is executed locally; no model output.
127
+ for framework, program in programs.items():
128
+ context = {}
129
+ exec(program, context)
130
+ states[framework] = np.asarray(context["state"], dtype=np.complex128)
131
+ reference = states["qiskit"]
132
+ assert abs(np.vdot(reference, reference).real - 1) < 1e-10
133
+ if np.max(abs(reference) ** 2) > 0.999:
134
+ continue
135
+ fidelities = {f: float(abs(np.vdot(reference, v)) ** 2) for f, v in states.items()}
136
+ assert min(fidelities.values()) > 1 - 1e-10
137
+ for framework in programs:
138
+ rows.append(
139
+ dict(
140
+ id=f"v2-{digest[:24]}-{framework}",
141
+ group_id=digest,
142
+ split=split,
143
+ framework=framework,
144
+ qubits=n,
145
+ operations_json=json.dumps(operations),
146
+ program=programs[framework],
147
+ state_real=reference.real.tolist(),
148
+ state_imag=reference.imag.tolist(),
149
+ cross_framework_fidelity=fidelities[framework],
150
+ )
151
+ )
152
+ produced += 1
153
+ print(json.dumps(dict(split=split, circuit_groups=worlds, examples=worlds * 3)), flush=True)
154
+ payload = json.dumps(rows, ensure_ascii=False, indent=2).encode()
155
+ (folder / "rows.json").write_bytes(payload)
156
+ (folder / "program_renderer.py").write_text(inspect.getsource(render), encoding="utf-8")
157
+ (folder / "prepare_quantum_v2.py").write_bytes(Path(__file__).read_bytes())
158
+ manifest = dict(
159
+ seed=2026110101,
160
+ rows_sha256=hashlib.sha256(payload).hexdigest(),
161
+ renderer_source_sha256=hashlib.sha256((folder/"program_renderer.py").read_bytes()).hexdigest(),
162
+ initial_generator_source_sha256=hashlib.sha256(source.read_bytes()).hexdigest(),
163
+ versions=dict(
164
+ numpy=np.__version__,
165
+ qiskit=qiskit.__version__,
166
+ pennylane=qml.__version__,
167
+ cirq=cirq.__version__,
168
+ ),
169
+ groups={s: n for s, n in protocol},
170
+ rows=len(rows),
171
+ original_groups_excluded=len(old_groups),
172
+ scope="Fresh follow-up, all 2000 original circuit groups excluded. All three frameworks occur in training. Includes phase RZ gates; circuits require H/RY/RZ/CX and exclude near-basis outputs. Held-out circuit groups and angles; separate five/six-qubit long-range/deeper stress. Exact zero-input state fidelity only, not full process equivalence or novel algorithm discovery. Deterministic renderer is a perfect structured-input oracle. Original framework-held-out negative result remains separate.",
173
+ )
174
+ (folder / "manifest.json").write_text(json.dumps(manifest, indent=2))
175
+ (folder/"LICENSE.md").write_text("Original generated circuits and numerical labels: CC BY 4.0, attributed to itsalissonsilva. Generator/rendering code: Apache-2.0. Framework implementations are not redistributed. Simulator versions and exact parity checks are recorded in manifest.json.\n",encoding="utf-8")
176
+ print(json.dumps(manifest), flush=True)
177
+
178
+
179
+ if __name__ == "__main__":
180
+ main()
curriculum_v2/program_renderer.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def render(ops, n, framework):
2
+ if framework == "qiskit":
3
+ lines = [
4
+ "from qiskit import QuantumCircuit",
5
+ "from qiskit.quantum_info import Statevector",
6
+ f"circuit = QuantumCircuit({n})",
7
+ ]
8
+ for gate, qubits, angle in ops:
9
+ args = ([repr(angle)] if gate in ["ry", "rz"] else []) + [str(q) for q in qubits]
10
+ lines.append(f"circuit.{gate}({', '.join(args)})")
11
+ return "\n".join(lines + ["state = Statevector.from_instruction(circuit).data"])
12
+ if framework == "cirq":
13
+ lines = [
14
+ "import cirq",
15
+ "import numpy as np",
16
+ f"qubits = cirq.LineQubit.range({n})",
17
+ "circuit = cirq.Circuit()",
18
+ ]
19
+ for gate, qubits, angle in ops:
20
+ expr = (
21
+ f"cirq.{gate}({angle!r})"
22
+ if gate in ["ry", "rz"]
23
+ else {"h": "cirq.H", "x": "cirq.X", "z": "cirq.Z", "cx": "cirq.CNOT"}[gate]
24
+ )
25
+ lines.append(
26
+ f"circuit.append({expr}({', '.join('qubits[' + str(q) + ']' for q in qubits)}))"
27
+ )
28
+ return "\n".join(
29
+ lines
30
+ + [
31
+ "state = cirq.Simulator(dtype=np.complex128).simulate(circuit, qubit_order=list(reversed(qubits))).final_state_vector"
32
+ ]
33
+ )
34
+ lines = [
35
+ "import pennylane as qml",
36
+ f"device = qml.device('default.qubit', wires={list(reversed(range(n)))!r})",
37
+ "@qml.qnode(device)",
38
+ "def circuit():",
39
+ ]
40
+ names = {"h": "Hadamard", "x": "PauliX", "z": "PauliZ", "cx": "CNOT", "ry": "RY", "rz": "RZ"}
41
+ for gate, qubits, angle in ops:
42
+ lines.append(
43
+ f" qml.{names[gate]}({repr(angle) + ', ' if gate in ['ry', 'rz'] else ''}wires={qubits!r})"
44
+ )
45
+ return "\n".join(lines + [" return qml.state()", "state = circuit()"])
curriculum_v2/rows.json ADDED
The diff for this file is too large to render. See raw diff