-
Notifications
You must be signed in to change notification settings - Fork 3
/
projectq_backends.py
42 lines (31 loc) · 1.11 KB
/
projectq_backends.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
# -*- 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 use of the ProjectQ based simulators
"""
import os
from qiskit_addon_projectq import ProjectQProvider
from qiskit import execute, QuantumCircuit, QuantumRegister, ClassicalRegister
def use_projectq_backends():
ProjectQ = ProjectQProvider()
qasm_sim = ProjectQ.get_backend('projectq_qasm_simulator')
sv_sim = ProjectQ.get_backend('projectq_statevector_simulator')
qr = QuantumRegister(2, 'qr')
cr = ClassicalRegister(2, 'cr')
qc = QuantumCircuit(qr, cr)
qc.h(qr[0])
qc.cx(qr[0], qr[1])
# ProjectQ statevector simulator
result = execute(qc, backend=sv_sim).result()
print("final quantum amplitude vector: ")
print(result.get_statevector(qc))
qc.measure(qr, cr)
# ProjectQ simulator
result = execute(qc, backend=qasm_sim, shots=100).result()
print("counts: ")
print(result.get_counts(qc))
if __name__ == "__main__":
use_projectq_backends()