MCPcopy Index your code
hub / github.com/Apress/quantum-machine-learning-python / simulate

Method simulate

Chapter_5/listing5_1/HHL.py:75–98  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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 """

Callers 6

simulate_circuitMethod · 0.45
mainFunction · 0.45
HHL.pyFile · 0.45
testFunction · 0.45
simulate_circuitMethod · 0.45
simulate_circuitMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected