File size: 1,785 Bytes
98d5347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# 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")