|
7 | 7 | from netqasm.lang.parsing import parse_text_subroutine |
8 | 8 | from netsquid.components import QuantumProcessor |
9 | 9 | from netsquid.qubits import ketstates, qubitapi |
| 10 | +from netsquid_netbuilder.modules.qdevices.generic import GenericQDeviceConfig |
10 | 11 | from netsquid_netbuilder.modules.qdevices.nv import NVQDeviceConfig |
11 | 12 | from netsquid_netbuilder.util.network_generation import create_single_node_network |
12 | 13 |
|
|
16 | 17 | from squidasm.sim.stack.host import Host |
17 | 18 |
|
18 | 19 |
|
19 | | -class TestSingleNode(unittest.TestCase): |
| 20 | +class TestSingleNodeNV(unittest.TestCase): |
20 | 21 | def setUp(self) -> None: |
21 | 22 | ns.sim_reset() |
22 | 23 | config = NVQDeviceConfig.perfect_config() |
@@ -155,5 +156,57 @@ def check_qmem(qdevice: QuantumProcessor) -> None: |
155 | 156 | self._check_qmem = check_qmem |
156 | 157 |
|
157 | 158 |
|
| 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 | + |
158 | 211 | if __name__ == "__main__": |
159 | 212 | unittest.main() |
0 commit comments