def execute_example(qi, unitary, desired_bit_accuracy, minimum_chance_of_success, shots=512, topology=None, create_errors=False, mu=0.5, sigma=0.5): nancillas, p_succes = error_estimate(desired_bit_accuracy, minimum_chance_of_success) qubits, extra_empty_bits = find_qubits_from_unitary(unitary, nancillas, topology=topology) final_qasm = generate_qasm_code(nancillas, qubits, unitary, extra_empty_bits=extra_empty_bits) final_qasm = optimize(final_qasm, nancillas, qubits, extra_empty_bits) if topology is not None: final_qasm = map_to_topology(topology, final_qasm) final_qasm = optimize(final_qasm, nancillas, qubits, extra_empty_bits) if create_errors: final_qasm = introduce_error(final_qasm, mu, sigma) final_qasm = optimize(final_qasm, nancillas, qubits, extra_empty_bits) backend_type = qi.get_backend_type_by_name('QX single-node simulator') return qi.execute_qasm(final_qasm, backend_type=backend_type, number_of_shots=shots)
print(phase) unitary_qasm = f"QASM\nRz q[0], {-phase*2*np.pi}" unitary_matrix = np.array([[np.exp(phase * 1j * np.pi), 0], [0, np.exp(-phase * 1j * np.pi)]]) unitary = unitary_matrix custom_prepare = "prep_z q[0]\n X q[0]" desired_bit_accuracy = 5 minimum_chance_of_success = 0.5 mu = 0.5 sigma = 0.5 error_toggle = 0 topology = None shots = 512 # process nancillas, p_succes = error_estimate(desired_bit_accuracy, minimum_chance_of_success) qubits, extra_empty_bits = find_qubits_from_unitary(unitary, nancillas, topology=topology) final_qasm = generate_qasm_code(nancillas, qubits, unitary, extra_empty_bits=extra_empty_bits, custom_prepare=custom_prepare) final_qasm = optimize(final_qasm, nancillas, qubits, extra_empty_bits) if topology is not None: final_qasm = map_to_topology(topology, final_qasm)
val = points[i] #unitary = f"QASM\n" \ # f"Rz q[0], {-val}" unitary = np.array([[np.exp(val * 0.5j), 0], [0, np.exp(-val * 0.5j)]]) use_qi = qis[0] if use_multiple: qi_num = i % len(qis) use_qi = qis[qi_num] arguments.append([ use_qi, unitary, desired_bit_accuracy, minimum_chance_of_success, 512, topology, use_error_model, mu, sigma ]) start = time.time() data = generate_data(arguments, True, file) total = time.time() - start print('Total time: ', total, ' seconds') nancilla, p_succes = error_estimate(desired_bit_accuracy, 0.5) data = to_array(data, desired_bit_accuracy, nancilla) binary_fractions = decimal_to_binary_fracion(find_max_value_keys(data), nancilla) heatmap(data[1], name) graph(binary_fractions)