Skip to content

Commit

Permalink
* docs and docstring minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkvanhooft committed Mar 6, 2024
1 parent 639ede3 commit 46ab40c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/source/modules/configurations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ All configurations can all be created via two routes:
.. code-block:: python
depolarise_config = DepolariseLinkConfig(fidelity=0.9)
link = LinkConfig(node1="Alice", node2="Bob", typ="depolarise", cfg=depolarise_config)
link = LinkConfig(stack1="Alice", stack1="Bob", typ="depolarise", cfg=depolarise_config)
#. Loading from a YAML configuration file:

Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorial/section4_NetworkConfiguration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ This link object is used to replace the original links inside the configuration:

.. code-block:: python
link = LinkConfig(node1="Alice", node2="Bob", typ="depolarise", cfg=depolarise_config)
link = LinkConfig(stack1="Alice", stack2="Bob", typ="depolarise", cfg=depolarise_config)
# Replace link from YAML file with new depolarise link
cfg.links = [link]
Expand Down
2 changes: 2 additions & 0 deletions squidasm/sim/stack/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def _setup_stack_logger(cls) -> None:
@classmethod
def get_stack_logger(cls, sub_logger: Optional[str] = None) -> logging.Logger:
"""Obtain the SquidASM logger.
:param sub_logger: If used, it will return a child logger of the main SquidASM logger
:return: The SquidASM logger
"""
Expand Down Expand Up @@ -70,6 +71,7 @@ def get_log_level(cls) -> int:
@classmethod
def log_to_file(cls, path: str) -> None:
"""Sets up sending the logs to an output file. Does not affect other log output methods.
:param path: Location of output file. Overwrites existing file.
"""
fileHandler = logging.FileHandler(path, mode="w")
Expand Down
11 changes: 6 additions & 5 deletions squidasm/sim/stack/netstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,11 @@ def register_peer(self, peer_id: int):
)

def assign_egp(self, remote_node_id: int, egp: EgpProtocol) -> None:
"""Set the magic link layer protocol that this network stack uses to produce
entangled pairs with the remote node.
"""Set the EGP protocol that this network stack uses to produce
entangled pairs with a remote node.
:param egp:
:param remote_node_id: The ID of the remote node.
:param egp: The EGP protocol instance for generating EPR pairs with the remote node.
"""
self._egp[remote_node_id] = egp

Expand Down Expand Up @@ -696,7 +697,7 @@ def handle_receive_request(
def handle_breakpoint_create_request(
self,
) -> Generator[EventExpression, None, None]:
# TODO figure out how to get remote node id here
# TODO breakpoint requests do not include a reference to the remote node id that is needed
raise NotImplementedError("Breakpoints not working currently")
# Synchronize with the remote node.
self._send_peer_msg("breakpoint start")
Expand Down Expand Up @@ -724,7 +725,7 @@ def handle_breakpoint_receive_request(
self,
) -> Generator[EventExpression, None, None]:
# Synchronize with the remote node.
# TODO figure out how to get remote node id here
# TODO breakpoint requests do not include a reference to the remote node id that is needed
raise NotImplementedError("Breakpoints not working currently")

msg = yield from self._receive_peer_msg()
Expand Down
6 changes: 6 additions & 0 deletions squidasm/sim/stack/qnos.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ def get_virt_qubit_for_phys_id(self, phys_id: int) -> Tuple[int, int]:
raise RuntimeError(f"no virtual ID found for physical ID {phys_id}")

def assign_egp(self, remote_node_id: int, egp: EgpProtocol) -> None:
"""Set the EGP protocol that this network stack uses to produce
entangled pairs with a remote node.
:param remote_node_id: The ID of the remote node.
:param egp: The EGP protocol instance for generating EPR pairs with the remote node.
"""
self.netstack.assign_egp(remote_node_id, egp)

@property
Expand Down
8 changes: 5 additions & 3 deletions squidasm/sim/stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ def __init__(
self._qnos = Qnos(self.qnos_comp, qdevice_type)

def assign_egp(self, remote_node_id: int, egp: EgpProtocol) -> None:
"""Set the link layer protocol to use for entanglement generation.
"""Set the EGP protocol that this network stack uses to produce
entangled pairs with a remote node.
The same link layer protocol object is used by both nodes sharing a link in
the network."""
:param remote_node_id: The ID of the remote node.
:param egp: The EGP protocol instance for generating EPR pairs with the remote node.
"""
self.qnos.assign_egp(remote_node_id, egp)

@property
Expand Down
14 changes: 7 additions & 7 deletions squidasm/util/qkd_routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@dataclass
class PairInfo:
class _PairInfo:
"""Information that a node has about one generated pair.
The information is filled progressively during the protocol."""

Expand All @@ -34,7 +34,7 @@ class QKDRoutine:
@staticmethod
def _distribute_states(
context: ProgramContext, is_init: bool, peer_name: str, num_epr: int
) -> Generator[EventExpression, None, List[PairInfo]]:
) -> Generator[EventExpression, None, List[_PairInfo]]:
"""
Generates and measures a number of entangled qubits in a random basis.
:param context: Local program context
Expand All @@ -56,14 +56,14 @@ def _distribute_states(
q.H()
m = q.measure()
yield from conn.flush()
results.append(PairInfo(index=i, outcome=int(m), basis=basis))
results.append(_PairInfo(index=i, outcome=int(m), basis=basis))

return results

@staticmethod
def _filter_bases(
socket: ClassicalSocket, pairs_info: List[PairInfo], is_init: bool
) -> Generator[EventExpression, None, List[PairInfo]]:
socket: ClassicalSocket, pairs_info: List[_PairInfo], is_init: bool
) -> Generator[EventExpression, None, List[_PairInfo]]:
"""
Communicates the random base choices with the peer and filters out the measured entangled qubits
that where measured in a different basis.
Expand All @@ -90,10 +90,10 @@ def _filter_bases(
@staticmethod
def _estimate_error_rate(
socket: ClassicalSocket,
pairs_info: List[PairInfo],
pairs_info: List[_PairInfo],
num_test_bits: int,
is_init: bool,
) -> Generator[EventExpression, None, Tuple[List[PairInfo], float]]:
) -> Generator[EventExpression, None, Tuple[List[_PairInfo], float]]:
"""
Estimates the error rate for the raw key, by choosing a random subset of the key to exchange with the peer.
:param socket: classical socket to peer.
Expand Down
39 changes: 14 additions & 25 deletions squidasm/util/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Generator, Optional, Tuple

from netqasm.sdk import EPRSocket
from netqasm.sdk.classical_communication.socket import Socket
from netqasm.sdk.connection import BaseNetQASMConnection
from netqasm.sdk.qubit import Qubit

Expand Down Expand Up @@ -251,8 +252,8 @@ def create_ghz(
connection: BaseNetQASMConnection,
down_epr_socket: Optional[EPRSocket] = None,
up_epr_socket: Optional[EPRSocket] = None,
down_socket=None,
up_socket=None,
down_socket: Optional[Socket] = None,
up_socket: Optional[Socket] = None,
do_corrections: bool = False,
) -> Generator[None, None, Tuple[Qubit, int]]:
r"""Local protocol to create a GHZ state between multiples nodes.
Expand All @@ -278,30 +279,18 @@ def create_ghz(
creates one on the `up_epr_socket`.
* "end", which receives an EPR pair on the `down_epr_socket`.
NOTE There has to be exactly one "start" and exactly one "end" but zero or more "middle".
NOTE Both `down_epr_socket` and `up_epr_socket` cannot be `None`.
NOTE Method was copied from netqasm package and was adapted for SquidASM
Parameters
----------
connection : :class:`.sdk.connection.BaseNetQASMConnection`
The connection to the quantum node controller used for sending instructions.
down_epr_socket : :class:`.sdk.epr_socket.esck.EPRSocket`
The esck.EPRSocket to be used for receiving EPR pairs from downstream.
up_epr_socket : :class:`.sdk.epr_socket.esck.EPRSocket`
The esck.EPRSocket to be used for create EPR pairs upstream.
down_socket : :class:`.sdk.classical_communication.socket.Socket`
The classical socket to be used for sending corrections, if `do_corrections = True`.
up_socket : :class:`.sdk.classical_communication.socket.Socket`
The classical socket to be used for sending corrections, if `do_corrections = True`.
do_corrections : bool
If corrections should be applied to make the GHZ in the standard form
:math:`|0\rangle^{\otimes n} + |1\rangle^{\otimes n}` or not.
.. note::
There has to be exactly one "start" and exactly one "end" but zero or more "middle".
Both `down_epr_socket` and `up_epr_socket` cannot be `None`.
Returns
-------
tuple
Of the form `(q, m)` where `q` is the qubit part of the state and `m` is the measurement outcome.
:param connection: The connection to the quantum node controller used for sending instructions.
:param down_epr_socket: The EPRSocket to be used for receiving EPR pairs from downstream.
:param up_epr_socket: The EPRSocket to be used for create EPR pairs upstream.
:param down_socket: The classical socket to be used for sending corrections, if `do_corrections = True`.
:param up_socket: The classical socket to be used for sending corrections, if `do_corrections = True`.
:param do_corrections: If corrections should be applied to make the GHZ in the standard form
:math:`|0\rangle^{\otimes n} + |1\rangle^{\otimes n}` or not.
:return: Of the form `(q, m)` where `q` is the qubit part of the state and `m` is the measurement outcome.
"""
if down_epr_socket is None and up_epr_socket is None:
raise TypeError("Both down_epr_socket and up_epr_socket cannot be None")
Expand Down

0 comments on commit 46ab40c

Please sign in to comment.