Welcome to QuLab’s documentation!¶
Installation¶
We encourage installing QuLab via the pip tool (a python package manager):
$ python -m pip install QuLab
To install from the latest source, you need to clone the GitHub repository on your machine:
$ git clone https://github.com/feihoo87/QuLab.git
Then dependencies and QuLab can be installed in this way:
$ cd QuLab
$ python -m pip install -r requirements.txt
$ python -m pip install -e .
Usage¶
QuLab API¶
The best place to start is the examples folder before diving into the API.
qulab package¶
The best place to start is the examples folder before diving into the API.
qulab.dht package¶
This package is developed base on [kademlia](https://github.com/bmuller/kademlia)
Kademlia is a Python implementation of the Kademlia protocol which utilizes the asyncio library.
qulab.math package¶
qulab.storage module¶
qulab.exceptions module¶
-
exception
qulab.exceptions.
QuLabDHTMalformedMessage
[source]¶ Bases:
qulab.exceptions.QuLabException
Message does not contain what is expected.
-
exception
qulab.exceptions.
QuLabRPCError
[source]¶ Bases:
qulab.exceptions.QuLabException
RPC base exception.
-
exception
qulab.exceptions.
QuLabRPCServerError
[source]¶ Bases:
qulab.exceptions.QuLabRPCError
Server side error.
-
exception
qulab.exceptions.
QuLabRPCTimeout
[source]¶ Bases:
qulab.exceptions.QuLabRPCError
Timeout.
qulab.log module¶
-
class
qulab.log.
RedisHandler
(conn, channel='log')[source]¶ Bases:
qulab.log.BaseHandler
Publish log by redis
-
class
qulab.log.
ZMQHandler
(socket: zmq.sugar.socket.Socket)[source]¶ Bases:
qulab.log.BaseHandler
Publish log by zmq socket
qulab.rpc module¶
-
class
qulab.rpc.
RPCClientMixin
[source]¶ Bases:
qulab.rpc.RPCMixin
-
class
qulab.rpc.
RPCMixin
[source]¶ Bases:
abc.ABC
-
cancelPending
(addr, msgID, cancelRemote)[source]¶ Give up when request timeout and try to cancel remote task.
-
createPending
(addr, msgID, timeout=1, cancelRemote=True)[source]¶ Create a future for request, wait response before timeout.
-
handle
(source, data)[source]¶ Handle received data.
Should be called whenever received data from outside.
-
abstract property
loop
¶ Event loop.
-
property
pending
¶
-
property
tasks
¶
-
-
class
qulab.rpc.
RPCServerMixin
[source]¶ Bases:
qulab.rpc.RPCMixin
-
property
executor
¶
-
property
-
class
qulab.rpc.
ZMQClient
(addr, timeout=10, loop=None)[source]¶ Bases:
qulab.rpc.RPCClientMixin
-
property
loop
¶ Event loop.
-
property
qulab.serialize module¶
-
qulab.serialize.
register
(cls: type, encode: Callable[[cls], bytes] = <built-in function dumps>, decode: Callable[[bytes], cls] = <built-in function loads>) → None[source]¶ Register a serializable type
- Parameters
cls – type
encode – Callable translate an object of type cls into bytes default: pickle.dumps
decode – Callable translate bytes to an object of type cls default: pickle.loads
qulab.utils module¶
-
qulab.utils.
IEEE_488_2_BinBlock
(datalist, dtype='int16', is_big_endian=True)[source]¶ 将一组数据打包成 IEEE 488.2 标准二进制块
- Parameters
datalist – 要打包的数字列表
dtype – 数据类型
endian – 字节序
- Returns
binblock, header 二进制块, 以及其 ‘header’
-
qulab.utils.
ShutdownBlocker
(*args, **kwds)¶
-
qulab.utils.
acceptArg
(f, name, keyword=True)[source]¶ Test if argument is acceptable by function.
- Parameters
f – callable function
name – str argument name
-
qulab.utils.
retry
(exception_to_check, tries=4, delay=0.5, backoff=2, logger=None)[source]¶ Retry calling the decorated function using an exponential backoff. :param exception_to_check: the exception to check.
may be a tuple of exceptions to check
- Parameters
tries (int) – number of times to try (not retry) before giving up
delay (float, int) – initial delay between retries in seconds
backoff (int) – backoff multiplier e.g. value of 2 will double the delay each retry
logger (logging.Logger) – logger to use. If None, print