How to use the qiskit.BasicAer.get_backend function in qiskit

To help you get started, we’ve selected a few qiskit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Qiskit / qiskit-terra / test / python / compiler / test_transpiler.py View on Github external
def test_transpile_two(self):
        """Test transpile to circuits.

        If all correct some should exists.
        """
        backend = BasicAer.get_backend('qasm_simulator')

        qubit_reg = QuantumRegister(2)
        clbit_reg = ClassicalRegister(2)
        qubit_reg2 = QuantumRegister(2)
        clbit_reg2 = ClassicalRegister(2)
        qc = QuantumCircuit(qubit_reg, clbit_reg, name="bell")
        qc.h(qubit_reg[0])
        qc.cx(qubit_reg[0], qubit_reg[1])
        qc.measure(qubit_reg, clbit_reg)
        qc_extra = QuantumCircuit(qubit_reg, qubit_reg2, clbit_reg, clbit_reg2, name="extra")
        qc_extra.measure(qubit_reg, clbit_reg)
        circuits = transpile([qc, qc_extra], backend)
        self.assertIsInstance(circuits[0], QuantumCircuit)
        self.assertIsInstance(circuits[1], QuantumCircuit)
github Qiskit / qiskit-terra / test / python / quantum_info / test_states.py View on Github external
def test_random_state_circuit(self):
        state = random_state(2**3, seed=40)
        q = QuantumRegister(3)
        qc = QuantumCircuit(q)
        qc.initialize(state, [q[0], q[1], q[2]])
        backend = BasicAer.get_backend('statevector_simulator')
        qc_state = execute(qc, backend).result().get_statevector(qc)
        self.assertAlmostEqual(state_fidelity(qc_state, state), 1.0, places=7)
github Qiskit / qiskit-ibmq-provider / test / ibmq / test_ibmq_backends.py View on Github external
def setUp(self):
        super().setUp()
        self._local_backend = BasicAer.get_backend('qasm_simulator')
        self._remote_backends = self.get_backends()
github Qiskit / qiskit-aqua / test / aqua / test_qsvm.py View on Github external
def test_qsvm_binary_directly_statevector(self):
        """ QSVM Binary Directly Statevector test """
        ref_kernel_testing = np. array([[0.1443953, 0.18170069, 0.47479649, 0.14691763],
                                        [0.33041779, 0.37663733, 0.02115561, 0.16106199]])

        ref_support_vectors = np.array([[2.95309709, 2.51327412], [3.14159265, 4.08407045],
                                        [4.08407045, 2.26194671], [4.46106157, 2.38761042]])

        backend = BasicAer.get_backend('statevector_simulator')
        num_qubits = 2
        feature_map = SecondOrderExpansion(feature_dimension=num_qubits,
                                           depth=2,
                                           entangler_map=[[0, 1]])
        svm = QSVM(feature_map, self.training_data, self.testing_data, None)

        quantum_instance = QuantumInstance(backend, seed_transpiler=self.random_seed,
                                           seed_simulator=self.random_seed)
        result = svm.run(quantum_instance)

        ori_alphas = result['svm']['alphas']

        np.testing.assert_array_almost_equal(
            result['kernel_matrix_testing'], ref_kernel_testing, decimal=4)

        self.assertEqual(len(result['svm']['support_vectors']), 4)
github Qiskit / qiskit-aqua / test / aqua / test_vqe.py View on Github external
def test_vqe_optimizers(self, optimizer_cls, places, max_evals_grouped):
        """ VQE Optimizers test """
        result = VQE(self.qubit_op,
                     RYRZ(self.qubit_op.num_qubits),
                     optimizer_cls(),
                     max_evals_grouped=max_evals_grouped).run(
                         QuantumInstance(BasicAer.get_backend('statevector_simulator'), shots=1,
                                         seed_simulator=aqua_globals.random_seed,
                                         seed_transpiler=aqua_globals.random_seed))

        self.assertAlmostEqual(result['energy'], -1.85727503, places=places)
github Qiskit / qiskit-terra / examples / python / ibmq / using_qiskit_terra_level_0.py View on Github external
qc1 = QuantumCircuit(2, 2)
qc1.h(0)
qc1.cx(0, 1)
qc1.measure([0,1], [0,1])

# making another circuit: superpositions
qc2 = QuantumCircuit(2, 2)
qc2.h([0,1])
qc2.measure([0,1], [0,1])

# setting up the backend
print("(BasicAER Backends)")
print(BasicAer.backends())

# running the job
job_sim = execute([qc1, qc2], BasicAer.get_backend('qasm_simulator'))
sim_result = job_sim.result()

# Show the results
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.providers()[0].backends())

# Compile and run on a real device backend
try:
    # select least busy available device and execute.
    least_busy_device = least_busy(provider.backends(simulator=False))
except:
    print("All devices are currently unavailable.")
github Qiskit / qiskit-terra / examples / python / ghz.py View on Github external
# Make a quantum circuit for the GHZ state.
###############################################################
num_qubits = 5
qc = QuantumCircuit(num_qubits, num_qubits, name='ghz')

# Create a GHZ state
qc.h(0)
for i in range(num_qubits-1):
    qc.cx(i, i+1)
# Insert a barrier before measurement
qc.barrier()
# Measure all of the qubits in the standard basis
for i in range(num_qubits):
    qc.measure(i, i)

sim_backend = BasicAer.get_backend('qasm_simulator')
job = execute(qc, sim_backend, shots=1024)
result = job.result()
print('Qasm simulator : ')
print(result.get_counts(qc))
github HuangJunye / QPong / viz / statevector_grid_1.py View on Github external
def set_circuit(self, circuit):
        backend_sv_sim = BasicAer.get_backend('statevector_simulator')
        job_sim = execute(circuit, backend_sv_sim)
        result_sim = job_sim.result()

        quantum_state = result_sim.get_statevector(circuit, decimals=3)

        self.image = pygame.Surface([(circuit.width() + 1) * 50, 100 + len(quantum_state) * 50])
        self.image.convert()
        self.image.fill(BLACK)
        self.rect = self.image.get_rect()

        block_size = 50
        x_offset = 50
        y_offset = 50
        for y in range(len(quantum_state)):
            #text_surface = ARIAL_30.render(self.basis_states[y], False, (0, 0, 0))
            #self.image.blit(text_surface,(x_offset, (y + 1) * block_size + y_offset))