|
|
|
|
|
|
|
|
|
|
| namespace BlackHoleEngine.Phase2 {
|
| open Microsoft.Quantum.Intrinsic;
|
| open Microsoft.Quantum.Canon;
|
| open Microsoft.Quantum.Measurement;
|
| open Microsoft.Quantum.Arrays;
|
| open Microsoft.Quantum.Math;
|
| open BlackHoleEngine.Primitives;
|
|
|
| @EntryPoint()
|
| operation RunPhase2Collapse(
|
| nQubits : Int,
|
| clauses : (Int, Int, Int)[],
|
| violations : ViolatingAssignment[],
|
| gamma_dt : Double,
|
| delta : Double,
|
| scrambleInterval : Int,
|
| scrambleTime : Double,
|
| maxSteps : Int
|
| ) : (Bool[], Double) {
|
|
|
| use qubits = Qubit[nQubits];
|
| use ancilla = Qubit();
|
|
|
| ApplyToEach(H, qubits);
|
|
|
| let m = Length(clauses);
|
| let couplings = GenerateCouplings(nQubits);
|
| let fields = GenerateFields(nQubits);
|
|
|
| mutable step = 0;
|
| mutable scrambleCount = 0;
|
| mutable energy = 1.0;
|
|
|
| while (step < maxSteps and energy > delta) {
|
| for idx in 0..m-1 {
|
| let (a, b, c) = clauses[idx];
|
| let viol = violations[idx];
|
| LindbladStepClause(ancilla, [qubits[a], qubits[b], qubits[c]], viol, gamma_dt);
|
| }
|
|
|
| set energy = MeasureEnergy(qubits, clauses, violations);
|
|
|
| set scrambleCount += 1;
|
| if (scrambleCount >= scrambleInterval and energy < 2.0 * delta) {
|
| HaydenPreskillScrambler(qubits, scrambleTime, couplings, fields);
|
| set scrambleCount = 0;
|
| set energy = MeasureEnergy(qubits, clauses, violations);
|
| }
|
|
|
| set step += 1;
|
| }
|
|
|
| let result = MultiM(qubits);
|
| let bits = ResultArrayAsBoolArray(result);
|
|
|
| ResetAll(qubits);
|
| Reset(ancilla);
|
|
|
| return (bits, energy);
|
| }
|
|
|
| function GenerateCouplings(n : Int) : Double[][] {
|
| let J = 1.0 / IntAsDouble(n);
|
| mutable matrix = new Double[n][n];
|
| for i in 0..n-1 {
|
| for j in 0..n-1 {
|
| set matrix[i][j] = if i < j then J else 0.0;
|
| }
|
| }
|
| return matrix;
|
| }
|
|
|
| function GenerateFields(n : Int) : Double[] {
|
| mutable fields = new Double[n];
|
| for i in 0..n-1 {
|
| set fields[i] = 0.5;
|
| }
|
| return fields;
|
| }
|
| }
|
|
|