-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnative_gates_examples.py
47 lines (40 loc) · 1.3 KB
/
native_gates_examples.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
"""Example 3: Using native gates"""
from mpqp import QCircuit, Language
from mpqp.core.instruction.measurement import BasisMeasure
from mpqp.execution import run
from mpqp.execution.devices import ATOSDevice, AWSDevice, GOOGLEDevice, IBMDevice
from mpqp.gates import *
# Declaration of the circuit with the right size
circuit = QCircuit(3, label="Test native gates")
# Constructing the circuit by adding gates and measurements
circuit.add([H(0), X(1), Y(2), Z(0), S(0), S_dagger(1), T(0)])
circuit.add([Rx(1.2324, 2), Ry(-2.43, 0), Rz(1.04, 1), Rk(-1, 1), P(-323, 2)])
circuit.add(U(1.2, 2.3, 3.4, 2))
circuit.add(SWAP(2, 0))
circuit.add([CNOT(0, 1), CRk(4, 2, 1), CZ(1, 2)])
circuit.add(TOF([0, 1], 2))
# no measure, we want the state vector
print(circuit)
print(circuit.to_other_language(Language.QASM2))
print(circuit.to_other_language(Language.QASM3))
result = run(
circuit,
[
ATOSDevice.MYQLM_PYLINALG,
IBMDevice.AER_SIMULATOR_STATEVECTOR,
AWSDevice.BRAKET_LOCAL_SIMULATOR,
GOOGLEDevice.CIRQ_LOCAL_SIMULATOR,
],
)
print(result)
circuit.add(BasisMeasure())
result = run(
circuit,
[
ATOSDevice.MYQLM_PYLINALG,
IBMDevice.AER_SIMULATOR_STATEVECTOR,
AWSDevice.BRAKET_LOCAL_SIMULATOR,
GOOGLEDevice.CIRQ_LOCAL_SIMULATOR,
],
)
print(result)