def test_get_backend(self): """Test get backends. If all correct should return a name the same as input. """ backend = Simulators.backends(name='qasm_simulator')[0] self.assertEqual(backend.name(), 'qasm_simulator')
def test_builtin_simulators_backend_properties(self): """Test backend properties. If all correct should pass the validation. """ simulators = Simulators.backends() for backend in simulators: properties = backend.properties() self.assertEqual(properties, None)
def test_builtin_simulators_backend_status(self): """Test backend_status. If all correct should pass the validation. """ schema_path = self._get_resource_path( 'backend_status_schema.json', path=Path.SCHEMAS) with open(schema_path, 'r') as schema_file: schema = json.load(schema_file) for backend in Simulators.backends(): status = backend.status() jsonschema.validate(status.to_dict(), schema)
def test_builtin_simulators_backend_configuration(self): """Test backend configuration. If all correct should pass the validation. """ schema_path = self._get_resource_path( 'backend_configuration_schema.json', path=Path.SCHEMAS) with open(schema_path, 'r') as schema_file: schema = json.load(schema_file) builtin_simulators = Simulators.backends() for backend in builtin_simulators: configuration = backend.configuration() jsonschema.validate(configuration.to_dict(), schema)
q = QuantumRegister(2) # Create a Classical Register with 2 bits. c = ClassicalRegister(2) # Create a Quantum Circuit qc = QuantumCircuit(q, c) # Add a H gate on qubit 0, putting this qubit in superposition. qc.h(q[0]) # Add a CX (CNOT) gate on control qubit 0 and target qubit 1, putting # the qubits in a Bell state. qc.cx(q[0], q[1]) # Add a Measure gate to see the state. qc.measure(q, c) # See a list of available local simulators print("Aer backends: ", Simulators.backends()) backend_sim = Simulators.get_backend('qasm_simulator') # Compile and run the Quantum circuit on a simulator backend job_sim = execute(qc, backend_sim) result_sim = job_sim.result() # Show the results print("simulation: ", result_sim) print(result_sim.get_counts(qc)) # see a list of available remote backends ibmq_backends = IBMQ.backends() print("Remote backends: ", ibmq_backends) # Compile and run the Quantum Program on a real device backend
clbit_reg = ClassicalRegister(2, name='c') # Making first circuit: bell state qc1 = QuantumCircuit(qubit_reg, clbit_reg, name="bell") qc1.h(qubit_reg[0]) qc1.cx(qubit_reg[0], qubit_reg[1]) qc1.measure(qubit_reg, clbit_reg) # Making another circuit: superpositions qc2 = QuantumCircuit(qubit_reg, clbit_reg, name="superposition") qc2.h(qubit_reg) qc2.measure(qubit_reg, clbit_reg) # Setting up the backend print("(Aer Backends)") for backend in Simulators.backends(): print(backend.status()) my_backend = Simulators.get_backend('local_qasm_simulator') print("(QASM Simulator configuration) ") pprint.pprint(my_backend.configuration()) print("(QASM Simulator properties) ") pprint.pprint(my_backend.properties()) print("\n(IMQ Backends)") for backend in IBMQ.backends(): print(backend.status()) # select least busy available device and execute. least_busy_device = least_busy(IBMQ.backends(simulator=False)) print("Running on current least busy device: ", least_busy_device) print("(with configuration) ")
clbit_reg = ClassicalRegister(2) # making first circuit: bell state qc1 = QuantumCircuit(qubit_reg, clbit_reg) qc1.h(qubit_reg[0]) qc1.cx(qubit_reg[0], qubit_reg[1]) qc1.measure(qubit_reg, clbit_reg) # making another circuit: superpositions qc2 = QuantumCircuit(qubit_reg, clbit_reg) qc2.h(qubit_reg) qc2.measure(qubit_reg, clbit_reg) # setting up the backend print("(AER Backends)") print(Simulators.backends()) # running the job job_sim = execute([qc1, qc2], Simulators.get_backend('qasm_simulator')) sim_result = job_sim.result() # Show the results print("simulation: ", sim_result) print(sim_result.get_counts(qc1)) print(sim_result.get_counts(qc2)) # see a list of available remote backends print("\n(IBMQ Backends)") print(IBMQ.backends()) # Compile and run on a real device backend
def test_aliases_return_empty_list(self): """Test backends() return an empty list if name is unknown.""" self.assertEqual(Simulators.backends("bad_name"), [])