(self)
| 73 | #print(results) |
| 74 | |
| 75 | def simulate(self): |
| 76 | simulator = cirq.Simulator() |
| 77 | |
| 78 | # Cases for measuring X, Y, and Z (respectively) on the memory qubit. |
| 79 | params = [{ |
| 80 | 'exponent': 0.5, |
| 81 | 'phase_exponent': -0.5 |
| 82 | }, { |
| 83 | 'exponent': 0.5, |
| 84 | 'phase_exponent': 0 |
| 85 | }, { |
| 86 | 'exponent': 0, |
| 87 | 'phase_exponent': 0 |
| 88 | }] |
| 89 | |
| 90 | results = simulator.run_sweep(self.circuit, params, repetitions=5000) |
| 91 | |
| 92 | for label, result in zip(('X', 'Y', 'Z'), list(results)): |
| 93 | # Only select cases where the ancilla is 1. |
| 94 | # TODO: optimize using amplitude amplification algorithm. |
| 95 | # Github issue: https://github.com/quantumlib/Cirq/issues/2216 |
| 96 | expectation = 1 - 2 * np.mean( |
| 97 | result.measurements['m'][result.measurements['a'] == 1]) |
| 98 | print('{} = {}'.format(label, expectation)) |
| 99 | |
| 100 | def main(): |
| 101 | """ |
no outgoing calls
no test coverage detected