Download run_phase2.py from Snapkitty/black-hole-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/Snapkitty/black-hole-engine/resolve/main/run_phase2.py
- Command line
-
hf download hf://Snapkitty/black-hole-engine/run_phase2.py
-
curl -L -o run_phase2.py https://huggingface.co/Snapkitty/black-hole-engine/resolve/main/run_phase2.py
1.79 kB
| # | |
| # Copyright (c) 2026 BEL ESPRIT D ACCORD TRUST HOLDINGS INC | |
| # All rights reserved. | |
| # run_phase2.py — Classical driver for Phase 2 Lindblad Collapse | |
| import numpy as np | |
| def run_on_hardware(backend: str = "qsharp.simulator"): | |
| """Run Phase 2 on specified backend.""" | |
| import qsharp | |
| from BlackHoleEngine.Phase2 import RunPhase2Collapse | |
| qsharp.config.target = backend | |
| # 3-SAT instance: (x0 | x1 | x2) & (~x0 | x1 | ~x2) | |
| n = 3 | |
| clauses = [(0, 1, 2), (0, 1, 2)] | |
| violations = [(False, False, False), (True, False, True)] | |
| gamma_dt = 0.01 | |
| delta = 1e-4 | |
| scramble_interval = 5 | |
| scramble_time = 5.0 * np.log(2**n) | |
| max_steps = 1000 | |
| print(f"Running Phase 2 on {backend}...") | |
| print(f"n={n}, m={len(clauses)}, gamma_dt={gamma_dt}, delta={delta}") | |
| result = RunPhase2Collapse.simulate( | |
| nQubits=n, | |
| clauses=clauses, | |
| violations=violations, | |
| gamma_dt=gamma_dt, | |
| delta=delta, | |
| scrambleInterval=scramble_interval, | |
| scrambleTime=scramble_time, | |
| maxSteps=max_steps | |
| ) | |
| solution, final_energy = result | |
| print(f"Solution: {solution}") | |
| print(f"Final energy: {final_energy}") | |
| for (a, b, c), (va, vb, vc) in zip(clauses, violations): | |
| vals = (solution[a], solution[b], solution[c]) | |
| violated = (vals == (va, vb, vc)) | |
| print(f" Clause ({a},{b},{c}): assignment {vals}, violated={violated}") | |
| return solution, final_energy | |
| if __name__ == "__main__": | |
| run_on_hardware("qsharp.simulator") | |
| # run_on_hardware("ionq.simulator") | |
| # run_on_hardware("ionq.qpu") | |
| # run_on_hardware("quantinuum.simulator") | |
| # run_on_hardware("quantinuum.qpu") | |
| # run_on_hardware("ibm.heron") | |