def test_qobj_sympy_unitary_simulator(self): SyQ = SympyProvider() backend = SyQ.get_backend('unitary_simulator') qobj = wrapper.compile(self.circuits, backend) cc = qobj.experiments[0].as_dict() ccq = qobj.experiments[0].header.compiled_circuit_qasm self.assertIn(self.qr_name, map(lambda x: x[0], cc['header']['qubit_labels'])) self.assertIn(self.qr_name, ccq) self.assertIn(self.cr_name, map(lambda x: x[0], cc['header']['clbit_labels'])) self.assertIn(self.cr_name, ccq)
def test_sympy_statevector_simulator(self): """Test final state vector for single circuit run.""" SyQ = SympyProvider() backend = SyQ.get_backend('statevector_simulator') result = execute(self.q_circuit, backend).result() actual = result.get_statevector(self.q_circuit) self.assertEqual(result.get_status(), 'COMPLETED') self.assertEqual(actual[0], sqrt(2) / 2) self.assertEqual(actual[1], 0) self.assertEqual(actual[2], 0) self.assertEqual(actual[3], sqrt(2) / 2)
def test_unitary_simulator(self): """test generation of circuit unitary""" SyQ = SympyProvider() backend = SyQ.get_backend('unitary_simulator') result = execute(self.q_circuit, backend).result() actual = result.get_unitary(self.q_circuit) self.assertEqual(actual[0][0], sqrt(2)/2) self.assertEqual(actual[0][1], sqrt(2)/2) self.assertEqual(actual[0][2], 0) self.assertEqual(actual[0][3], 0) self.assertEqual(actual[1][0], 0) self.assertEqual(actual[1][1], 0) self.assertEqual(actual[1][2], sqrt(2)/2) self.assertEqual(actual[1][3], -sqrt(2)/2) self.assertEqual(actual[2][0], 0) self.assertEqual(actual[2][1], 0) self.assertEqual(actual[2][2], sqrt(2)/2) self.assertEqual(actual[2][3], sqrt(2)/2) self.assertEqual(actual[3][0], sqrt(2)/2) self.assertEqual(actual[3][1], -sqrt(2)/2) self.assertEqual(actual[3][2], 0) self.assertEqual(actual[3][3], 0)
# # This source code is licensed under the Apache License, Version 2.0 found in # the LICENSE.txt file in the root directory of this source tree. """ Example showing how to use the Sympy Provider at level 0 (novice). This example shows the most basic way to user the Sympy Provider. It builds some circuits and runs them on both the statevector and unitary simulators. """ # Import the Qiskit modules from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister from qiskit import execute from qiskit_addon_sympy import SympyProvider SyQ = SympyProvider() # Create a Quantum and Classical Register. qubit_reg = QuantumRegister(2) 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]) # making another circuit: superpositions qc2 = QuantumCircuit(qubit_reg, clbit_reg) qc2.h(qubit_reg) # setting up the backend
This example shows how an intermediate user interacts with the Sympy Provider. It builds some circuits and compiles them. It makes a qobj object which is just a container to be run on a backend. The same qobj can run on many backends (as shown). It is the user responsibility to make sure it can be run. This is useful when you want to compare the same circuits on different backends or change the compile parameters. """ import time # Import the Qiskit modules from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister from qiskit import compile from qiskit_addon_sympy import SympyProvider SyQ = SympyProvider() # Create a quantum and classical register. qubit_reg = QuantumRegister(2, name='q') 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]) # Making another circuit: superpositions qc2 = QuantumCircuit(qubit_reg, clbit_reg, name="superposition") qc2.h(qubit_reg) # Setting up the backend
# -*- coding: utf-8 -*- # Copyright 2018, IBM. # # This source code is licensed under the Apache License, Version 2.0 found in # the LICENSE.txt file in the root directory of this source tree. """ Usage examples for the Sympy Provider """ from qiskit_addon_sympy import SympyProvider SyQ = SympyProvider() # prints the symp print(SyQ.backends()) print(SyQ.backends(name='statevector_simulator')) backend = SyQ.get_backend('statevector_simulator') print(backend) # gets the name of the backend. print(backend.name()) # gets the status of the backend. print(backend.status()) # returns the provider of the backend print(backend.provider) # gets the configuration of the backend. print(backend.configuration())