|
1 | 1 | import unittest
|
2 | 2 | import logging
|
| 3 | +from util.config_paths import ConfigPathStorage |
3 | 4 | from easysquid.easyfibre import ClassicalFibreConnection
|
4 |
| -from easysquid.easynetwork import EasyNetwork |
| 5 | +from easysquid.easynetwork import EasyNetwork, setup_physical_network |
5 | 6 | from easysquid.qnode import QuantumNode
|
6 | 7 | from easysquid.quantumMemoryDevice import NVCommunicationDevice
|
7 | 8 | from easysquid.easyprotocol import TimedProtocol
|
8 | 9 | from easysquid.toolbox import logger
|
| 10 | +from easysquid.quantumMemoryDevice import NVCommunicationDevice |
9 | 11 | from netsquid.simutil import sim_run, sim_reset
|
10 | 12 | from qlinklayer.distQueue import EGPDistributedQueue, WFQDistributedQueue
|
11 | 13 | from qlinklayer.scheduler import StrictPriorityRequestScheduler, WFQRequestScheduler
|
@@ -155,24 +157,75 @@ def test_priority(self):
|
155 | 157 |
|
156 | 158 | class TestWFQRequestScheduler(unittest.TestCase):
|
157 | 159 | def setUp(self):
|
158 |
| - alice = QuantumNode("alice", 0) |
159 |
| - bob = QuantumNode("bob", 0) |
160 |
| - conn = ClassicalFibreConnection(alice, bob, length=0.001) |
| 160 | + sim_reset() |
| 161 | + |
| 162 | + network = setup_physical_network(ConfigPathStorage.NETWORK_NV_LAB_NOCAV_NOCONV) |
| 163 | + alice, bob = network.all_nodes() |
| 164 | + dqp_conn = network.get_connection(alice, bob, "dqp_conn") |
| 165 | + mhp_conn = network.get_connection(alice, bob, "mhp_conn") |
161 | 166 |
|
162 |
| - distQueueA = WFQDistributedQueue(alice, numQueues=3, accept_all=True) |
163 |
| - distQueueB = WFQDistributedQueue(bob, numQueues=3, accept_all=True) |
164 |
| - distQueueA.connect_to_peer_protocol(distQueueB, conn=conn) |
| 167 | + self.num_queues = 3 |
165 | 168 |
|
166 |
| - qmmA = QuantumMemoryManagement(alice) |
| 169 | + self.distQueueA = WFQDistributedQueue(alice, numQueues=self.num_queues, accept_all=True) |
| 170 | + distQueueB = WFQDistributedQueue(bob, numQueues=self.num_queues, accept_all=True) |
| 171 | + self.distQueueA.connect_to_peer_protocol(distQueueB, conn=dqp_conn) |
| 172 | + |
| 173 | + self.qmmA = QuantumMemoryManagement(alice) |
167 | 174 | qmmB = QuantumMemoryManagement(bob)
|
168 | 175 |
|
169 |
| - # mhp_service = SimulatedNodeCentricMHPService("mhp_service", alice, bob) |
170 |
| - # |
171 |
| - # feuA = SingleClickFidelityEstimationUnit(alice, ) |
172 |
| - # self.schedulerA = WFQRequestScheduler(distQueueA, qmmA, feuA) |
| 176 | + mhp_service = SimulatedNodeCentricMHPService("mhp_service", alice, bob, conn=mhp_conn) |
| 177 | + |
| 178 | + self.feuA = SingleClickFidelityEstimationUnit(alice, mhp_service) |
| 179 | + feuB = SingleClickFidelityEstimationUnit(bob, mhp_service) |
| 180 | + |
| 181 | + self.schedulerA = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA) |
| 182 | + |
173 | 183 | def test_init(self):
|
| 184 | + # Test default |
| 185 | + scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA) |
| 186 | + self.assertEqual(scheduler.relative_weights, [0] * self.num_queues) |
| 187 | + |
| 188 | + # Test wrong type |
| 189 | + with self.assertRaises(TypeError): |
| 190 | + WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA, 0) |
| 191 | + with self.assertRaises(TypeError): |
| 192 | + WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA, {}) |
| 193 | + |
| 194 | + # Test wrong length |
| 195 | + with self.assertRaises(ValueError): |
| 196 | + WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA, [0] * (self.num_queues + 1)) |
| 197 | + |
| 198 | + # Test negative weights |
| 199 | + with self.assertRaises(ValueError): |
| 200 | + WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA, [0, 0, -1]) |
| 201 | + |
| 202 | + # Test non-comparable weights |
| 203 | + with self.assertRaises(ValueError): |
| 204 | + WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA, [0, [], False]) |
| 205 | + |
| 206 | + # Test non-trivial weights |
| 207 | + scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA, [0, 5, 15]) |
| 208 | + self.assertEqual(scheduler.relative_weights, [0, 0.25, 0.75]) |
| 209 | + |
| 210 | + def test_compare_cycle_odd(self): |
| 211 | + scheduler = WFQRequestScheduler(self.distQueueA, self.qmmA, self.feuA) |
| 212 | + scheduler.max_mhp_cycle_number = 5 |
| 213 | + scheduler.mhp_cycle_number = 0 |
| 214 | + |
| 215 | + cycle1 = 0 |
| 216 | + cycle2 = 1 |
| 217 | + |
| 218 | + for _ in range(scheduler.max_mhp_cycle_number): |
| 219 | + print(scheduler._compare_mhp_cycle(cycle1, cycle2)) |
| 220 | + scheduler.mhp_cycle_number += 1 |
| 221 | + |
| 222 | + def test_set_virtual_finish(self): |
174 | 223 | pass
|
175 | 224 |
|
| 225 | + def test_scheduling(self): |
| 226 | + pass |
| 227 | + |
| 228 | + |
176 | 229 |
|
177 | 230 | class TestTimings(unittest.TestCase):
|
178 | 231 | def setUp(self):
|
|
0 commit comments