Skip to content

Commit f8d7143

Browse files
committed
Add support for S and T gates in generic qdevice
Add test to check all single qubit gates in generic qdevice
1 parent a5b88b1 commit f8d7143

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
2024-12-16 (0.13.4)
55
------------------
66
- Bugfix for simulation time not resetting between different calls of the `squidasm.run.stack.run.run` method
7+
- Add support for S and T gates in generic qdevice
78

89
2024-11-18 (0.13.3)
910
------------------

squidasm/sim/stack/processor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
INSTR_ROT_X,
2222
INSTR_ROT_Y,
2323
INSTR_ROT_Z,
24+
INSTR_S,
25+
INSTR_T,
2426
INSTR_X,
2527
INSTR_Y,
2628
INSTR_Z,
@@ -684,6 +686,14 @@ def _interpret_single_qubit_instr(
684686
prog = QuantumProgram()
685687
prog.apply(INSTR_K, qubit_indices=[phys_id])
686688
yield self.qdevice.execute_program(prog)
689+
elif isinstance(instr, vanilla.GateSInstruction):
690+
prog = QuantumProgram()
691+
prog.apply(INSTR_S, qubit_indices=[phys_id])
692+
yield self.qdevice.execute_program(prog)
693+
elif isinstance(instr, vanilla.GateTInstruction):
694+
prog = QuantumProgram()
695+
prog.apply(INSTR_T, qubit_indices=[phys_id])
696+
yield self.qdevice.execute_program(prog)
687697
else:
688698
raise RuntimeError(f"Unsupported instruction {instr}")
689699

tests/stack/test_single_node.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from netqasm.lang.parsing import parse_text_subroutine
88
from netsquid.components import QuantumProcessor
99
from netsquid.qubits import ketstates, qubitapi
10+
from netsquid_netbuilder.modules.qdevices.generic import GenericQDeviceConfig
1011
from netsquid_netbuilder.modules.qdevices.nv import NVQDeviceConfig
1112
from netsquid_netbuilder.util.network_generation import create_single_node_network
1213

@@ -16,7 +17,7 @@
1617
from squidasm.sim.stack.host import Host
1718

1819

19-
class TestSingleNode(unittest.TestCase):
20+
class TestSingleNodeNV(unittest.TestCase):
2021
def setUp(self) -> None:
2122
ns.sim_reset()
2223
config = NVQDeviceConfig.perfect_config()
@@ -155,5 +156,57 @@ def check_qmem(qdevice: QuantumProcessor) -> None:
155156
self._check_qmem = check_qmem
156157

157158

159+
class TestSingleNodeGeneric(unittest.TestCase):
160+
def setUp(self) -> None:
161+
ns.sim_reset()
162+
config = GenericQDeviceConfig.perfect_config()
163+
network_cfg = create_single_node_network(
164+
qdevice_typ="generic", qdevice_cfg=config
165+
)
166+
self.network = _setup_network(network_cfg)
167+
self._node = self.network.stacks["Alice"]
168+
169+
self._host: Optional[Type[Host]] = None
170+
171+
def tearDown(self) -> None:
172+
self._node.subprotocols[f"{self._node.name}_host_protocol"] = self._host(
173+
self._node.host_comp
174+
)
175+
_run(self.network)
176+
177+
def test_quantum_instructions(self):
178+
SUBRT_1 = """
179+
# NETQASM 1.0
180+
# APPID 0
181+
set Q0 0
182+
qalloc Q0
183+
init Q0
184+
x Q0
185+
y Q0
186+
z Q0
187+
h Q0
188+
s Q0
189+
k Q0
190+
t Q0
191+
rot_x Q0 16 4
192+
rot_y Q0 8 1
193+
rot_z Q0 16 2
194+
"""
195+
196+
class TestHost(Host):
197+
def run(self) -> Generator[EventExpression, None, None]:
198+
self.send_qnos_msg(bytes(InitNewAppMessage(max_qubits=2)))
199+
app_id = yield from self.receive_qnos_msg()
200+
assert app_id == 0
201+
subroutine = parse_text_subroutine(SUBRT_1)
202+
subroutine.app_id = app_id
203+
self.send_qnos_msg(bytes(SubroutineMessage(subroutine)))
204+
app_mem = yield from self.receive_qnos_msg()
205+
assert isinstance(app_mem, AppMemory)
206+
assert app_mem.get_reg_value("Q0") == 0
207+
208+
self._host = TestHost
209+
210+
158211
if __name__ == "__main__":
159212
unittest.main()

0 commit comments

Comments
 (0)