Agent
– Alice and Bob in code¶
-
class
squanch.agent.
Agent
(qstream, out=None, name=None, data=None)[source]¶ Bases:
multiprocessing.context.Process
Represents an entity (Alice, Bob, etc.) that can send messages over classical and quantum communication channels. Agents have the following properties:
- Incoming and outgoing classical and quantum channels connecting them to other agents
- Classical memory, implemented simply as a Python dictionary
- Quantum memory, implemented as a Python dictionary of qubits stored in keys of agent names
- Runtime logic in the form of an Agent.run() method
-
__init__
(qstream, out=None, name=None, data=None)[source]¶ Instantiate an Agent from a unique identifier and a shared memory pool
Parameters: - qstream (QStream) – the QStream object that the agent operates on
- out (dict) – shared output dictionary to pass to Agent processes to allow for “returns”. Default: {}
- name (str) – the unique identifier for the Agent. Default: class name
- data (any) – data to pass to the Agent’s process, stored in
self.data
. Default: None
-
cconnect
(other, channel=<class 'squanch.channels.CChannel'>, **kwargs)[source]¶ Connect Alice and Bob bidirectionally with a specified classical channel model
Parameters:
-
crecv
(origin)[source]¶ Receive a serializable object from another connected agent.
self.time
is updated upon calling this method.Parameters: origin (Agent) – The agent that previously sent the qubit Returns: the retrieved object, which is also stored in self.cmem
-
csend
(target, thing)[source]¶ Send a serializable object to another agent. The transmission time is updated by (number of bits) pulse lengths.
Parameters: - target (Agent) – the agent to send the transmission to
- thing (any) – the object to send
-
output
(thing)[source]¶ Output something to
self.out[self.name]
Parameters: thing (any) – the thing to put in the dictionary
-
qconnect
(other, channel=<class 'squanch.channels.QChannel'>, **kwargs)[source]¶ Connect Alice and Bob bidirectionally with a specified quantum channel model
Parameters:
-
qrecv
(origin)[source]¶ Receive a qubit from another connected agent.
self.time
is updated upon calling this method.Parameters: origin (Agent) – The agent that previously sent the qubit Returns: the retrieved qubit, which is also stored in self.qmem
-
qsend
(target, qubit)[source]¶ Send a qubit to another agent. The qubit is serialized and passed through a QChannel to the targeted agent, which can retrieve the qubit with Agent.qrecv().
self.time
is updated upon calling this method.Parameters:
-
qstore
(qubit)[source]¶ Store a qubit in quantum memory. Equivalent to
self.qmem[self].append(qubit)
.Parameters: qubit (Qubit) – the qubit to store
Generate a output dictionary stored in a shared memory pool to distribute among agents in separate processes
Returns: an empty multiprocessed Manager.dict()