-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathusing_sympy_provider_level_0.py
55 lines (42 loc) · 1.61 KB
/
using_sympy_provider_level_0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- 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.
"""
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
print("(Sympy Backends)")
print(SyQ.backends())
# running the statevector simulator
statevector_job = execute([qc1, qc2], SyQ.get_backend('statevector_simulator'))
statevector_result = statevector_job.result()
# show the results
print("Stevector simulator: ", statevector_result)
print(statevector_result.get_statevector(qc1))
print(statevector_result.get_statevector(qc2))
# running the unitary simulator
unitary_job = execute([qc1, qc2], SyQ.get_backend('unitary_simulator'))
unitary_result = unitary_job.result()
# show the results
print("Unitary simulator: ", unitary_result)
print(unitary_result.get_unitary(qc1))
print(unitary_result.get_unitary(qc2))