Simulates HHL with matrix input, and outputs Pauli observables of the resulting qubit state |x>. Expected observables are calculated from the expected solution |x>.
()
| 98 | print('{} = {}'.format(label, expectation)) |
| 99 | |
| 100 | def main(): |
| 101 | """ |
| 102 | Simulates HHL with matrix input, and outputs Pauli observables of the |
| 103 | resulting qubit state |x>. |
| 104 | Expected observables are calculated from the expected solution |x>. |
| 105 | """ |
| 106 | |
| 107 | # Eigendecomposition: |
| 108 | # (4.537, [-0.971555, -0.0578339+0.229643j]) |
| 109 | # (0.349, [-0.236813, 0.237270-0.942137j]) |
| 110 | # |b> = (0.64510-0.47848j, 0.35490-0.47848j) |
| 111 | # |x> = (-0.0662724-0.214548j, 0.784392-0.578192j) |
| 112 | A = np.array([[4.30213466 - 6.01593490e-08j, |
| 113 | 0.23531802 + 9.34386156e-01j], |
| 114 | [0.23531882 - 9.34388383e-01j, |
| 115 | 0.58386534 + 6.01593489e-08j]]) |
| 116 | t = 0.358166 * math.pi |
| 117 | register_size = 4 |
| 118 | input_prep_gates = [cirq.rx(1.276359), cirq.rz(1.276359)] |
| 119 | expected = (0.144130, 0.413217, -0.899154) |
| 120 | |
| 121 | # Set C to be the smallest eigenvalue that can be represented by the |
| 122 | # circuit. |
| 123 | C = 2 * math.pi / (2 ** register_size * t) |
| 124 | |
| 125 | # Simulate circuit |
| 126 | print("Expected observable outputs:") |
| 127 | print("X =", expected[0]) |
| 128 | print("Y =", expected[1]) |
| 129 | print("Z =", expected[2]) |
| 130 | print("Actual: ") |
| 131 | simulate(hhl_circuit(A, C, t, register_size, *input_prep_gates)) |
| 132 | |
| 133 | |
| 134 | if __name__ == '__main__': |
nothing calls this directly
no outgoing calls
no test coverage detected