qitker 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,135 @@
1
+ """Export recorded circuit operations to Qiskit."""
2
+
3
+
4
+
5
+ def export_to(name, circuit):
6
+ """
7
+ Export a circuit to the requested platform.
8
+
9
+ Only the exact name "qiskit" is supported.
10
+
11
+ Args:
12
+ name (str): Export target.
13
+ circuit (circuit): Circuit to export.
14
+
15
+ Returns:
16
+ qiskit.QuantumCircuit: A new exported circuit.
17
+
18
+ Raises:
19
+ TypeError: If name is not a string.
20
+ ValueError: If name is not ``"qiskit"``.
21
+ """
22
+
23
+ if not isinstance(name, str):
24
+ raise TypeError("export target must be a string")
25
+ if name != "qiskit":
26
+ raise ValueError(f"Unsupported export target: {name!r}. Supported target: 'qiskit'.")
27
+
28
+ return exportToQiskit(circuit)
29
+
30
+
31
+
32
+
33
+
34
+
35
+ def exportToQiskit(AnyonCircuit):
36
+ """
37
+ Convert the circuit's recorded operations to a new Qiskit circuit.
38
+
39
+ The exported circuit has one qubit per Qitker qubit and one classical
40
+ bit per qubit marked for measurement. No measurement instructions
41
+ are added.
42
+
43
+ Args:
44
+ AnyonCircuit (circuit): Circuit to export.
45
+
46
+ Returns:
47
+ qiskit.QuantumCircuit: The exported circuit.
48
+ """
49
+
50
+ from qiskit import QuantumCircuit
51
+ from qiskit.circuit.library import (
52
+ YGate,
53
+ ZGate,
54
+ SGate,
55
+ TGate,
56
+ RXGate,
57
+ RYGate,
58
+ RZGate,
59
+ )
60
+
61
+ qc = QuantumCircuit(AnyonCircuit.getQubitsNumber(), AnyonCircuit.getQubitsNumberToMeasure()) #creating qiskit circuit
62
+ vector = AnyonCircuit.getOperationVector()
63
+
64
+ controlled_gates = {
65
+ "Y": YGate,
66
+ "Z": ZGate,
67
+ "S": SGate,
68
+ "T": TGate
69
+ }
70
+
71
+ controlled_rotation_gates = {
72
+ "RX": RXGate,
73
+ "RY": RYGate,
74
+ "RZ": RZGate
75
+ }
76
+
77
+
78
+ #loop over operation vector
79
+ for op in vector:
80
+
81
+ if hasattr(op, "getControllers"):
82
+ controls = op.getControllers()
83
+ target = op.getTarget()
84
+ name = op.getName()
85
+
86
+ if name == "X":
87
+ if len(controls) == 1:
88
+ qc.cx(controls[0], target)
89
+ else:
90
+ qc.mcx(controls, target)
91
+
92
+ elif name in controlled_rotation_gates:
93
+ gate = controlled_rotation_gates[name](op.getAngle())
94
+
95
+ qc.append(
96
+ gate.control(len(controls)),
97
+ controls + [target]
98
+ )
99
+
100
+ elif name in controlled_gates:
101
+ gate = controlled_gates[name]()
102
+
103
+ if len(controls) == 1:
104
+ qc.append(
105
+ gate.control(1),
106
+ controls + [target]
107
+ )
108
+ else:
109
+ qc.append(
110
+ gate.control(len(controls)),
111
+ controls + [target]
112
+ )
113
+ else:
114
+ if(op.getName() == "H"):
115
+ qc.h(op.getTarget())
116
+ elif(op.getName() == "X"):
117
+ qc.x(op.getTarget())
118
+ elif(op.getName() == "Y"):
119
+ qc.y(op.getTarget())
120
+ elif(op.getName() == "Z"):
121
+ qc.z(op.getTarget())
122
+ elif(op.getName() == "S"):
123
+ qc.s(op.getTarget())
124
+ elif(op.getName() == "T"):
125
+ qc.t(op.getTarget())
126
+ elif(op.getName() == "RX"):
127
+ qc.rx(op.getAngle(), op.getTarget())
128
+ elif(op.getName() == "RY"):
129
+ qc.ry(op.getAngle(), op.getTarget())
130
+ elif(op.getName() == "RZ"):
131
+ qc.rz(op.getAngle(), op.getTarget())
132
+ elif(op.getName() == "barrier"):
133
+ qc.barrier()
134
+
135
+ return qc