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)
Пример #4
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