QuLab 2.10.10__cp313-cp313-macosx_10_13_universal2.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.
Files changed (107) hide show
  1. qulab/__init__.py +33 -0
  2. qulab/__main__.py +4 -0
  3. qulab/cli/__init__.py +0 -0
  4. qulab/cli/commands.py +30 -0
  5. qulab/cli/config.py +170 -0
  6. qulab/cli/decorators.py +28 -0
  7. qulab/dicttree.py +523 -0
  8. qulab/executor/__init__.py +5 -0
  9. qulab/executor/analyze.py +188 -0
  10. qulab/executor/cli.py +434 -0
  11. qulab/executor/load.py +563 -0
  12. qulab/executor/registry.py +185 -0
  13. qulab/executor/schedule.py +543 -0
  14. qulab/executor/storage.py +615 -0
  15. qulab/executor/template.py +259 -0
  16. qulab/executor/utils.py +194 -0
  17. qulab/expression.py +827 -0
  18. qulab/fun.cpython-313-darwin.so +0 -0
  19. qulab/monitor/__init__.py +1 -0
  20. qulab/monitor/__main__.py +8 -0
  21. qulab/monitor/config.py +41 -0
  22. qulab/monitor/dataset.py +77 -0
  23. qulab/monitor/event_queue.py +54 -0
  24. qulab/monitor/mainwindow.py +234 -0
  25. qulab/monitor/monitor.py +115 -0
  26. qulab/monitor/ploter.py +123 -0
  27. qulab/monitor/qt_compat.py +16 -0
  28. qulab/monitor/toolbar.py +265 -0
  29. qulab/scan/__init__.py +2 -0
  30. qulab/scan/curd.py +221 -0
  31. qulab/scan/models.py +554 -0
  32. qulab/scan/optimize.py +76 -0
  33. qulab/scan/query.py +387 -0
  34. qulab/scan/record.py +603 -0
  35. qulab/scan/scan.py +1166 -0
  36. qulab/scan/server.py +450 -0
  37. qulab/scan/space.py +213 -0
  38. qulab/scan/utils.py +234 -0
  39. qulab/storage/__init__.py +0 -0
  40. qulab/storage/__main__.py +51 -0
  41. qulab/storage/backend/__init__.py +0 -0
  42. qulab/storage/backend/redis.py +204 -0
  43. qulab/storage/base_dataset.py +352 -0
  44. qulab/storage/chunk.py +60 -0
  45. qulab/storage/dataset.py +127 -0
  46. qulab/storage/file.py +273 -0
  47. qulab/storage/models/__init__.py +22 -0
  48. qulab/storage/models/base.py +4 -0
  49. qulab/storage/models/config.py +28 -0
  50. qulab/storage/models/file.py +89 -0
  51. qulab/storage/models/ipy.py +58 -0
  52. qulab/storage/models/models.py +88 -0
  53. qulab/storage/models/record.py +161 -0
  54. qulab/storage/models/report.py +22 -0
  55. qulab/storage/models/tag.py +93 -0
  56. qulab/storage/storage.py +95 -0
  57. qulab/sys/__init__.py +2 -0
  58. qulab/sys/chat.py +688 -0
  59. qulab/sys/device/__init__.py +3 -0
  60. qulab/sys/device/basedevice.py +255 -0
  61. qulab/sys/device/loader.py +86 -0
  62. qulab/sys/device/utils.py +79 -0
  63. qulab/sys/drivers/FakeInstrument.py +68 -0
  64. qulab/sys/drivers/__init__.py +0 -0
  65. qulab/sys/ipy_events.py +125 -0
  66. qulab/sys/net/__init__.py +0 -0
  67. qulab/sys/net/bencoder.py +205 -0
  68. qulab/sys/net/cli.py +169 -0
  69. qulab/sys/net/dhcp.py +543 -0
  70. qulab/sys/net/dhcpd.py +176 -0
  71. qulab/sys/net/kad.py +1142 -0
  72. qulab/sys/net/kcp.py +192 -0
  73. qulab/sys/net/nginx.py +194 -0
  74. qulab/sys/progress.py +190 -0
  75. qulab/sys/rpc/__init__.py +0 -0
  76. qulab/sys/rpc/client.py +0 -0
  77. qulab/sys/rpc/exceptions.py +96 -0
  78. qulab/sys/rpc/msgpack.py +1052 -0
  79. qulab/sys/rpc/msgpack.pyi +41 -0
  80. qulab/sys/rpc/router.py +35 -0
  81. qulab/sys/rpc/rpc.py +412 -0
  82. qulab/sys/rpc/serialize.py +139 -0
  83. qulab/sys/rpc/server.py +29 -0
  84. qulab/sys/rpc/socket.py +29 -0
  85. qulab/sys/rpc/utils.py +25 -0
  86. qulab/sys/rpc/worker.py +0 -0
  87. qulab/sys/rpc/zmq_socket.py +227 -0
  88. qulab/tools/__init__.py +0 -0
  89. qulab/tools/connection_helper.py +39 -0
  90. qulab/typing.py +2 -0
  91. qulab/utils.py +95 -0
  92. qulab/version.py +1 -0
  93. qulab/visualization/__init__.py +188 -0
  94. qulab/visualization/__main__.py +71 -0
  95. qulab/visualization/_autoplot.py +464 -0
  96. qulab/visualization/plot_circ.py +319 -0
  97. qulab/visualization/plot_layout.py +408 -0
  98. qulab/visualization/plot_seq.py +242 -0
  99. qulab/visualization/qdat.py +152 -0
  100. qulab/visualization/rot3d.py +23 -0
  101. qulab/visualization/widgets.py +86 -0
  102. qulab-2.10.10.dist-info/METADATA +110 -0
  103. qulab-2.10.10.dist-info/RECORD +107 -0
  104. qulab-2.10.10.dist-info/WHEEL +5 -0
  105. qulab-2.10.10.dist-info/entry_points.txt +2 -0
  106. qulab-2.10.10.dist-info/licenses/LICENSE +21 -0
  107. qulab-2.10.10.dist-info/top_level.txt +1 -0
qulab/sys/net/dhcpd.py ADDED
@@ -0,0 +1,176 @@
1
+ #
2
+ # Packet format
3
+ # -------------
4
+ #
5
+ # Offset Length Notes
6
+ # ------ ------ -----
7
+ #
8
+ # 0 1 Operation code with 1 being request and 2 being response
9
+ # 1 1 Hardware type with 1 being "Ethernet 10Mb"
10
+ # 2 1 Hardware address length with 6 for Ethernet
11
+ # 3 1 Hops - usually 0 unless DHCP relaying in operation
12
+ # 4-7 4 Transaction ID (selected randomly by client)
13
+ # 8-9 2 Seconds - might be used by a server to prioritise requests
14
+ # 10-11 2 Flags (only most significan bit used for broadcast)
15
+ # 12-15 4 Client Internet address (might be requested by client)
16
+ # 16-19 4 Your Internet address (the IP assigned by the server)
17
+ # 20-23 4 Server Internet address (the IP of the server)
18
+ # 24-27 4 Gateway Internet address (if DHCP relaying in operation)
19
+ # 28-43 16 Client hardware address - only first 6 bytes used for Ethernet
20
+ # 44-107 64 Text name of server (optional)
21
+ # 108-235 128 Boot file name (optional - used for PXE booting)
22
+ # 236-239 4 Magic cookie (decimal values 99, 130, 83, 99 )
23
+ #
24
+
25
+ #
26
+ # DHCP option codes
27
+ # -----------------
28
+ #
29
+ # 1 - Subnet mask
30
+ # 3 - Router(s)
31
+ # 6 - DNS name server(s)
32
+ # 12 - Hostname
33
+ # 15 - Domain name
34
+ # 28 - Broadcast address
35
+ # 33 - Static route
36
+ # 42 - Network time protocol servers
37
+ # 51 - IP address lease time
38
+ # 53 - DHCP Message Type (DHCPDISCOVER, DHCPOFFER, etc)
39
+ # 54 - Server identifier
40
+ # 55 - Parameter Request List
41
+ # 57 - Maximum DHCP Message Size
42
+ # 58 - Renewal (T1) time value
43
+ # 59 - Renewal (T2) time value
44
+ # 60 - Vendor Class Identifier
45
+ # 61 - Client Identifier
46
+ # 67 - Boot file name (e.g. PXE booting)
47
+ # 80 -
48
+ # 116 -
49
+ # 119 -
50
+ # 145 -
51
+ # 167 -
52
+ # 171 -
53
+ #
54
+
55
+ import asyncio
56
+ import logging
57
+ import socket
58
+ from typing import NamedTuple
59
+
60
+ from waveforms.sys.net.dhcp import (MAGIC_COOKIE, DHCPMessageType, DHCPOption,
61
+ DHCPPacket)
62
+
63
+ logger = logging.getLogger(__name__)
64
+
65
+
66
+ class DHCPServerProtocol:
67
+
68
+ def connection_made(self, transport):
69
+ self.transport = transport
70
+ address, port = self.transport.get_extra_info('sockname')
71
+ self.server_ip = '192.168.254.1'
72
+
73
+ def connection_lost(self, exc):
74
+ pass
75
+
76
+ def datagram_received(self, data, addr):
77
+ try:
78
+ received = DHCPPacket.decode(data)
79
+ except ValueError as e:
80
+ logger.error("Error decoding DHCP packet: %s", e)
81
+ return
82
+
83
+ print("\nReceived DHCP packet from %s:%d" % (addr[0], addr[1]))
84
+ print(received)
85
+
86
+ # see if there is a DHCP message type option
87
+ if 53 not in received.options:
88
+ return
89
+
90
+ messagetype = received.get_option(DHCPOption.DHCP_MSG_TYPE)
91
+ if (messagetype != DHCPMessageType.DISCOVER) and (
92
+ messagetype != DHCPMessageType.REQUEST):
93
+ logger.error(
94
+ "ignoring: DHCP message type not supported by this implementation"
95
+ )
96
+ return
97
+
98
+ try:
99
+ assigned_ip, subnet, gateway = get_ip_from_mac(received.chaddr)
100
+ except:
101
+ return
102
+
103
+ response = DHCPPacket()
104
+ response.op = 2
105
+ response.xid = received.xid
106
+ response.flags = received.flags
107
+ response.chaddr = received.chaddr
108
+ response.yiaddr = assigned_ip
109
+ response.siaddr = self.server_ip
110
+
111
+ if messagetype == DHCPMessageType.DISCOVER:
112
+ # DHCPOFFER
113
+ response.set_option(DHCPOption.DHCP_MSG_TYPE,
114
+ DHCPMessageType.OFFER)
115
+ elif messagetype == DHCPMessageType.REQUEST:
116
+ # DHCPACK
117
+ response.set_option(DHCPOption.DHCP_MSG_TYPE, DHCPMessageType.ACK)
118
+ else:
119
+ return
120
+
121
+ lease_time = 86400
122
+ response.set_option(DHCPOption.SUBNET_MASK, subnet)
123
+ response.set_option(DHCPOption.ROUTER, gateway)
124
+ response.set_option(DHCPOption.IP_LEASE_TIME, lease_time)
125
+ response.set_option(DHCPOption.SERVER_ID, self.server_ip)
126
+
127
+ response_packet = response.encode()
128
+
129
+ # send it
130
+ print("\nSending DHCP packet to %s:%d" % (addr[0], addr[1]))
131
+ print(DHCPPacket.decode(response_packet))
132
+ self.send_packet(response_packet, addr)
133
+
134
+ def send_packet(self, packet, addr):
135
+ if addr == ('0.0.0.0', 68):
136
+ send_address = ('255.255.255.255', 68)
137
+ else:
138
+ send_address = addr
139
+ self.transport.sendto(packet, send_address)
140
+
141
+
142
+ class IPConfig(NamedTuple):
143
+ ip: str
144
+ subnet: str
145
+ gateway: str
146
+
147
+
148
+ ip_table = {
149
+ '00:19:AF:04:92:C4':
150
+ IPConfig(ip='192.168.254.150', subnet='255.255.255.0', gateway='0.0.0.0')
151
+ }
152
+
153
+
154
+ def get_ip_from_mac(macaddr):
155
+ ip_config = ip_table.get(macaddr, None)
156
+ return ip_config.ip, ip_config.subnet, ip_config.gateway
157
+
158
+
159
+ async def main(server_ip='0.0.0.0'):
160
+ loop = asyncio.get_running_loop()
161
+
162
+ transport, protocol = await loop.create_datagram_endpoint(
163
+ lambda: DHCPServerProtocol(),
164
+ local_addr=(server_ip, 67),
165
+ allow_broadcast=True)
166
+
167
+ # print('start', server_ip)
168
+
169
+ try:
170
+ await asyncio.sleep(3600) # Serve for 1 hour.
171
+ finally:
172
+ transport.close()
173
+
174
+
175
+ if __name__ == '__main__':
176
+ asyncio.run(main(server_ip='0.0.0.0'))