def _run_sim_stage3(aht, ht, zz, exact=False, print_circuit=False, noisy=False): """Helper routine to executes state preparation circuit a single time. Outputs a state vector. Args: ===== aht, ht, zz : numeric Parameters for decoding 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: ======== final_state : numpy.ndarray Final state vector """ exact = True # NOTE: Hard-coded for now simulator = XmonSimulator() if noisy: circuit_run, resolvers = noisy_job_stage3(aht, ht, zz, exact) for resolver in resolvers: result = simulator.simulate(circuit=circuit_run, param_resolver=resolver, qubit_order=qubit_ordering) else: circuit_run = decoder_circuit(aht, ht, zz, exact) result = simulator.simulate(circuit=circuit_run, qubit_order=qubit_ordering) if print_circuit: print(circuit_run.to_text_diagram(use_unicode_characters=False)) return result.final_state
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
circuit = cirq.Circuit() init = [] for i in range(sites // 2 + sites % 2): init.append( xmon_gates.ExpWGate(half_turns=1.0, axis_half_turns=0.0)(qubits[i])) for i in range(sites // 2, sites): init.append( xmon_gates.ExpWGate(half_turns=1.0, axis_half_turns=0.0)(qubits[i + sites])) circuit.append(init, strategy=cirq.circuits.InsertStrategy.EARLIEST) for j in range(steps): circuit.append(trotter_step(t / steps, U / steps, qubits, order=order), strategy=cirq.circuits.InsertStrategy.EARLIEST) simulator = XmonSimulator() result = simulator.simulate(circuit) h = np.sum([ FermionOperator(((i, 1), (i + 1, 0)), t) + FermionOperator( ((i + 1, 1), (i, 0)), t) + FermionOperator( ((i + sites, 1), (i + 1 + sites, 0)), t) + FermionOperator( ((i + 1 + sites, 1), (i + sites, 0)), t) for i in range(sites - 1) ]) h += FermionOperator(((sites // 2, 1), (sites // 2, 0), (sites // 2 + sites, 1), (sites // 2 + sites, 0)), U) init = FermionOperator( tuple([(i, 1) for i in range(sites // 2 + sites % 2)] + [(i + sites, 1) for i in range(sites // 2, sites)]), 1.0) init = get_sparse_operator(init, sites * 2) init = init.dot(np.array([1] + [0] * (2**(sites * 2) - 1)))