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
__eq__(other)[source]

Agents are compared for equality by their names.

__hash__()[source]

Agents are hashed by their (unique) names

__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
__ne__(other)[source]

Agents are compared for inequality by their names

cconnect(other, channel=<class 'squanch.channels.CChannel'>, **kwargs)[source]

Connect Alice and Bob bidirectionally with a specified classical channel model

Parameters:
  • other (Agent) – the other agent to connect to
  • channel (CChannel) – the classical channel model to use
  • **kwargs – optional channel arguments
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
increment_progress()[source]

Adds 1 to the current progress

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:
  • other (Agent) – the other agent to connect to
  • channel (QChannel) – the quantum channel model to use
  • **kwargs – optional channel arguments
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:
  • target (Agent) – the agent to send the qubit to
  • qubit (Qubit) – the qubit to send
qstore(qubit)[source]

Store a qubit in quantum memory. Equivalent to self.qmem[self].append(qubit).

Parameters:qubit (Qubit) – the qubit to store
run()[source]

Runtime logic for the Agent; this method should be overridden in child classes.

static shared_output()[source]

Generate a output dictionary stored in a shared memory pool to distribute among agents in separate processes

Returns:an empty multiprocessed Manager.dict()
update_progress(value)[source]

Update the progress of this agent in the shared output dictionary. Used in Simulation.progress_monitor().

Parameters:value – the value to update the progress to (out of a max of len(self.qstream))