def run(simulator: cg.XmonSimulator, circuit: cirq.Circuit, scheduler: Optional[Callable], **kw): if scheduler is None: program = circuit else: program = scheduler(cirq.UnconstrainedDevice, circuit) return simulator.run(program, **kw)
def run(simulator: cg.XmonSimulator, circuit: cirq.Circuit, scheduler: Optional[Callable], **kw): if scheduler is None: program = circuit else: program = scheduler(cirq.UnconstrainedDevice, circuit) return simulator.run(program, **kw)
yield XmonMeasurementGate(key='q0')(q[0]) yield XmonMeasurementGate(key='q1')(q[1]) yield XmonMeasurementGate(key='q2')(q[2]) yield XmonMeasurementGate(key='q3')(q[3]) circuit.append(circuit_init()) print(" ") print(" ") print(circuit) print(" ") print(" ") simulator = XmonSimulator() result = simulator.run(circuit) measured = int(str(result)[3]) print(str(result)) print(str(result)[3]) print(str(result)[8]) print(str(result)[13]) if ((str(result)[3] + str(result)[8] + str(result)[13] + str(result)[18]) == "0000"): graphing[0] = graphing[0] + 1 if ((str(result)[3] + str(result)[8] + str(result)[13] + str(result)[18]) == "0001"): graphing[1] = graphing[1] + 1 if ((str(result)[3] + str(result)[8] + str(result)[13] +
def _run_sim_stage2(a, b, x, z, alpha, exact=False, print_circuit=False, noisy=False): """Executes circuit a single time. Outputs 1 for a success (i.e. reference qubits are |000>) and 0 for a failure. Args: ===== a, b, x, z : numeric Circuit parameters for encoding circuit alpha : numeric Parameter for state preparation circuit exact : bool If True, works with wavefunction print_circuit : bool If True, prints circuit noisy : bool If True, runs noisy version of circuit Returns: ======== total : int Value of 1 if reference qubits are all 0's. Value of 0 else. """ simulator = XmonSimulator() if noisy: circuit_run, resolvers = noisy_job(a, b, x, z, alpha, exact) else: circuit_run = compression_circuit(a, b, x, z, alpha, exact) if exact: if noisy: for resolver in resolvers: result = simulator.simulate(circuit=circuit_run, param_resolver=resolver) else: result = simulator.simulate(circuit=circuit_run) avg = 0 for j in range(2): avg += np.abs(result.final_state[j])**2 return avg else: if noisy: for resolver in resolvers: result = simulator.run(circuit=circuit_run, param_resolver=resolver, repetitions=1) else: result = simulator.run(circuit=circuit_run, repetitions=1) reference_measurements = [] reference_labels = ['r00', 'r01', 'r10'] for j in reference_labels: reference_measurements.append(int(result.measurements[j][0])) total = 0 res = [] for y in range(3): res.append(reference_measurements[y]) if res == [0, 0, 0]: total = 1 if print_circuit == True: print(circuit_run.to_text_diagram(use_unicode_characters=False)) return total
def apply_h(): yield cirq.CCX.on(target[0], target[1], final) yield cirq.CCX.on(target[0], target[2], final) yield cirq.CCX.on(target[1], target[2], final) yield cirq.CNOT.on(target[0], final) yield cirq.CNOT.on(target[1], final) yield cirq.CNOT.on(target[2], final) #yield cirq.H.on(final) circuit.append(apply_h()) def circuit_init_again(meas=True): if meas: yield XmonMeasurementGate(key='qubit')(final) #circuit.append() circuit.append(circuit_init_again()) print(" ") print(" ") print(circuit) print(" ") print(" ") simulator = XmonSimulator() result = simulator.run(circuit, repetitions=20) print(result)