def main(): global shots shots = 1024 provider = IBMQ.load_account() num_qubits = 5 def backendFilter(x): nonlocal num_qubits a = x.configuration().n_qubits >= num_qubits b = x.configuration().simulator c = x.status().operational == True return a and not b and c qc = least_busy(provider.backends(filters=backendFilter)) simulator = Aer.get_backend('qasm_simulator') noisy = QasmSimulator.from_backend(qc) circuits = [] for i in range(1, 3): for _ in range(10 * num_qubits): circuits.append(random_gated_circuit(qc, i, 0)) random.shuffle(circuits) training = circuits[:math.ceil(.8 * len(circuits))] holdout = circuits[math.ceil(.8 * len(circuits)):] calibration_circuits = generate_calibration_circuits( noisy, simulator, 3, 5, 3)
def SimW(cir): simulator_qasm = BasicAer.get_backend('qasm_simulator') noise_simulator = QasmSimulator.from_backend(device_backend) if intro_noise == 0: simulator = simulator_qasm else: simulator = noise_simulator result = execute(cir, simulator, shots=num_shot).result() counts = result.get_counts(cir) #plot_histogram(counts, title='Bell-State counts') return counts
def startIBMQ(): global Q, backend # Written to work with versions of IBMQ-Provider both before and after 0.3 sQPV = IBMQVersion['qiskit-ibmq-provider'] pd = '.' dot1 = [pos for pos, char in enumerate(sQPV) if char == pd][0] dot2 = [pos for pos, char in enumerate(sQPV) if char == pd][1] IBMQP_Vers = float(sQPV[dot1 + 1:dot2]) print('IBMQ Provider v', IBMQP_Vers) if not UseLocal: print('Pinging IBM Quantum Experience before start') p = ping('https://api.quantum-computing.ibm.com', 1, 0.5, True) #p=ping('https://quantum-computing.ibm.com/',1,0.5,True) try: print("requested backend: ", backendparm) except: sleep(0) # specify the simulator as the backend backend = 'ibmq_qasm_simulator' if p == 200: if ( IBMQP_Vers > 2 ): # The new authentication technique with provider as the object provider0 = IBMQ.load_account() try: Q = provider0.get_backend(backendparm) except: Q = provider0.get_backend(backend) else: interval = 300 else: # The older IBMQ authentication technique IBMQ.load_accounts() try: Q = IBMQ.get_backend(backendparm) except: Q = IBMQ.get_backend(backend) else: interval = 300 else: exit() else: # THIS IS THE CASE FOR USING LOCAL SIMULATOR backend = 'local aer qasm_simulator' print("Building ", backend, "with requested attributes...") if not AddNoise: Q = Aer.get_backend('qasm_simulator') else: fake_backend = fake_qc() Q = QasmSimulator.from_backend(fake_backend)
def __init__( self, backend_name: str, hub: Optional[str] = None, group: Optional[str] = None, project: Optional[str] = None, ): """Construct an IBMQEmulatorBackend. Identical to :py:class:`IBMQBackend` constructor, except there is no `monitor` parameter. See :py:class:`IBMQBackend` docs for more details. """ self._ibmq = IBMQBackend(backend_name, hub, group, project) qasm_sim = QasmSimulator.from_backend(self._ibmq._backend) super().__init__(noise_model=NoiseModel.from_backend(qasm_sim)) self._backend = qasm_sim
def set_vqe_circuit(self, backend = None): #Check https://qiskit.org/documentation/tutorials/algorithms/03_vqe_simulation_with_noise.html #seed = 170 iterations = self.vqe_options['maxiter'] #aqua_globals.random_seed = seed if backend is None: backend = 'statevector_simulator' backend = Aer.get_backend(backend) counts = [] values = [] stds = [] def store_intermediate_result(eval_count, parameters, mean, std): counts.append(eval_count) values.append(mean) stds.append(std) var_form = TwoLocal(reps = self.vqe_options['n_steps'], rotation_blocks = 'ry', entanglement_blocks = 'cx', entanglement = 'linear', insert_barriers = True) spsa = SPSA(maxiter=iterations) if self.vqe_options['noise']: os.environ['QISKIT_IN_PARALLEL'] = 'TRUE' device = QasmSimulator.from_backend(device_backend) coupling_map = device.configuration().coupling_map noise_model = NoiseModel.from_backend(device) basis_gates = noise_model.basis_gates qi = QuantumInstance(backend=backend, coupling_map=coupling_map, noise_model=noise_model) else: qi = QuantumInstance(backend=backend) vqe = VQE(var_form=var_form, optimizer=spsa, callback=store_intermediate_result, quantum_instance=qi) result = vqe.compute_minimum_eigenvalue(operator=self.H) return vqe.get_optimal_circuit(), vqe.optimal_params, vqe.get_optimal_vector(), vqe.get_optimal_cost()
from qiskit import IBMQ, execute from qiskit import QuantumCircuit from qiskit.providers.aer import QasmSimulator from qiskit.tools.visualization import plot_histogram from qiskit.test.mock import FakeSantiago from qiskit.test.mock import FakeAthens if __name__ == '__main__': #device_backend = FakeVigo() device_backend = FakeAthens() vigo_simulator = QasmSimulator.from_backend(device_backend) print(isinstance(1, int)) print(tuple([1])) print(device_backend.properties().gate_error(gate="cx", qubits=(0, 1))) print(device_backend.properties().gate_error(gate="cx", qubits=(4, 3))) print(device_backend.properties().gate_error(gate="cx", qubits=(1, 2))) print(device_backend.properties().gate_error(gate="cx", qubits=(2, 3))) print(device_backend.properties().gate_error(gate="u2", qubits=2)) print(device_backend.properties().gate_error(gate="u2", qubits=1)) print(device_backend.properties().gate_error(gate="u2", qubits=0)) print(device_backend.properties().gate_error(gate="u2", qubits=3))