General
This is the qosst_core module.
It contains classes and functions that are useful for both Alice and Bob.
It contains : * the configuration reader * the control protocol helpers * the modulations * some constants.
Infos
File containing the logo (motd) and two utils function to print the motd and basic information.
- qosst_core.infos.get_script_infos(configuration: Configuration | None = None, motd: bool = True) str
Get information on the current installed software for QOSST.
- Parameters:
configuration (Configuration, optional) – a configuration object that will be printed if given. Defaults to None.
motd (bool, optional) – if True, motd is included in the string, if False, it is not. Defaults to True.
- Returns:
string containing MOTD, version information and optionnally cnfiguration information.
- Return type:
str
Notifications
Module holding some utils function for notifications.
- class qosst_core.notifications.QOSSTNotifier
An abstract notifier for QOSST.
The only method that should be implemented is the send_notification method. Required variables should be passed throught the __init__ method.
- abstract send_notification(message: str) None
Send a notification whith the message passed as argument.
- Parameters:
message (str) – message to send as a notification.
- class qosst_core.notifications.FakeNotifier(**_kwargs)
A Fake Notifier to be used as a default value.
All args are ignored.
- send_notification(message: str) None
Send notification for the dummy notifier. Does nothing.
- Parameters:
message (str) – message is ignored.
- class qosst_core.notifications.TelegramNotifier(token: str, chat_id: int)
Notifier sending message to a particular chat using Telegram.
Telegram servers are not opensource, and minimal information should be sent to telegram.
This is actually a way to know when a function starts and when a function ends but should only be used this way and not sending critical information.
- Parameters:
token (str) – token of the telegram bot.
chat_id (int) – the id of the chat where the message should be sent.
- token: str
The token of the telegram bot.
- chat_id: int
The chat id where to send the message.
- send_notification(message: str) None
Send the message to the configured chat_id using the telegram bot configured with the token.
- Parameters:
message (str) – message to send.
Parameters estimation
Definition of BaseEstimator for qosst_bob.
Definition of NoneEstimator for the configuration.
- class qosst_core.parameters_estimation.BaseEstimator
Base estimator.
- abstract static estimate(alice_symbols: ndarray, bob_symbols: ndarray, alice_photon_number: float, electronic_symbols: ndarray, electronic_shot_symbols: ndarray) Tuple[float, float, float]
Estimate the transmittance and excess noise given the symbols of Alice and Bob, symbols for the shot noise and electronic noise and the avarage photon number at Alice’s output.
Transmittance should be here understood as total transmittance hence eta * T.
- Parameters:
alice_symbols (np.ndarray) – symbols sent by Alice.
bob_symbols (np.ndarray) – symbols received by Bob, after DSP.
alice_photon_number (float) – average number of photon at Alice’s output.
electronic_symbols (np.ndarray) – electronic noise data after equivalent DSP.
electronic_shot_symbols (np.ndarray) – electronic and shot noise data, after equivalent DSP.
- Returns:
tuple containing the transmittance, the excess noise at Bob side and the electronic noise.
- Return type:
Tuple[float, float, float]
- class qosst_core.parameters_estimation.NoneEstimator
Fake Estimator.
Always return 0 for the estimation.
- static estimate(_alice_symbols: ndarray, _bob_symbols: ndarray, _alice_photon_number: float, _electronic_symbols: ndarray, _electronic_shot_symbols: ndarray) Tuple[float, float, float]
Estimate with a fake estimator, and always return 0.
- Parameters:
_alice_symbols (np.ndarray) – ignored.
_bob_symbols (np.ndarray) – ignored.
_alice_photon_number (float) – ignored.
_electronic_symbols (np.ndarray) – ignored.
_electronic_shot_symbols (np.ndarray) – ignored.
- Returns:
0, 0, 0.
- Return type:
Tuple[float, float, float]
SKR computations
Definition of BaseCVQKDSKRCalculator for qosst_skr.
Definition of NoneSKRCalculator for the configuration.
- class qosst_core.skr_computations.BaseCVQKDSKRCalculator
This is a base calculator, that is not calculating anything. Every calculator should inherit from this base calculator.
No proof is provided for this calculator. No link is available for this calculator.
- abstract static skr(**kwargs) float
Static method to compute the Secret Key Rate depending on the calculator.
- Returns:
the secret key rate in bits per symbol.
- Return type:
float
Utils
Utils module for qosst-core.
- qosst_core.utils.eph(lamb: float) float
Returns the energy of a single photon of wavelength lamb.
- Parameters:
lamb (float) – wavelength in meter.
- Returns:
energy of photon.
- Return type:
float
- qosst_core.utils.decimal_to_bitarray(in_number: ndarray, bit_width: int) ndarray
Converts a positive integer or an array-like of positive integers to NumPy array of the specified size containing bits (0 and 1).
- Parameters:
in_number (int or array-like of int) – Positive integer to be converted to a bit array.
bit_width (int) – Size of the output bit array.
- Returns:
Array containing the binary representation of all the input decimal(s).
- Return type:
np.ndarray
- qosst_core.utils.bitarray_to_decimal(in_bitarray: ndarray) int
Converts an input NumPy array of bits (0 and 1) to a decimal integer.
- Parameters:
in_bitarray (np.ndarray) – Input NumPy array of bits.
- Returns:
Integer representation of input bit array.
- Return type:
int
- qosst_core.utils.generate_gray(number_bits: int) List[str]
Generate a Gray code with number_bits bits.
The result is returned as list of strings.
- Parameters:
number_bits (int) – number of bits in the code
- Returns:
Gray code as a list of strings.
- Return type:
List[str]
- qosst_core.utils.export_np(data: ndarray, export_dir: str | PathLike[str], metadata: ndarray | None = None, data_name: str = 'data', metadata_name: str = 'metadata') Tuple[str | PathLike[str] | None, str | PathLike[str] | None]
Save the data in metada in the export_dir directory with a timestamp.
- Parameters:
data (np.ndarray) – data array to save.
export_dir (QOSSTPath) – where to save the data and metadata.
metadata (np.ndarray, optional) – metadata array to save. Defaults to None.
data_name (str, optional) – the prefix of the saved data array. Defaults to “data”.
metadata_name (str, optional) – the prefix of the save metadata array. Defaults to “metadata”.
- Returns:
tuple containing the path(s) of the saved objects.
- Return type:
Tuple[Optional[QOSSTPath], Optional[QOSSTPath]]
- qosst_core.utils.get_object_by_import_path(import_path: str) Any
Get an object from it’s full import path.
For instance you get the class NoneAuthenticator with
get_object_by_import_path(“qosst_core.authentication.base.NoneAuthenticator”)
It is also possible to get functions or any other python objects.
- Parameters:
import_path (str) – the full import path.
- Raises:
ImportError – the module was not found.
ImportError – the object was not found in the module.
- Returns:
the object of the full import path.
- Return type:
object
- qosst_core.utils.round(input: float | ndarray) int | ndarray
Round the floats using the ceil(x-0.5) method, that will always round in the same direction, especially in the 0.5 case
For instance round(2.4) = 2 np.round(2.7) = 3
round(2.5) = 2 np.round(2.5) = 2
but round(3.5) = 3 np.round(3.5) = 4
(in np.round, odd int + 0.5 are rounded to int+1 where even int + 0.5 are rounded to int).
This method will always round down.
- Parameters:
x (Union[float, np.ndarray]) – the float or the array of floats to round.
- Returns:
the rounded int or the array of rounded ints.
- Return type:
Union[int, np.ndarray]
New configuration menu that uses by default configuration files.
- Parameters:
config (Any) – configuration object, instance of dataclass.
preferred_config_name (Optional[str], optional) – name, without the .toml extension, of the preferred confiugration to use. Defaults to None.
- Raises:
TypeError – if the configuration file cannot be read.
- qosst_core.utils.load_config_from_file(config: Any, configuration_path: Path | str)
Load the config dataclass from the configuration file.
- Parameters:
config (Any) – config object, instance of dataclass.
configuration_path (str) – path of the configuration file to load the fields data from.
Print a configuration menu for dynamic configuration modification.
- Parameters:
config (Any) – the configuration object to change. It as to be an instance of a dataclass.
Data
Module to handle object that should be saved and loaded in QOSST.
- class qosst_core.data.BaseQOSSTData
A basic class to create loadable and dumpable (non human-readable) object using pickle.
The class as a dump (alias save) method so an instance can be save as simple as calling this method. There is also a static method to load an object from a file that return an instance of this object.
Example:
from qosst_core.data import BaseQOSSTData class MyData(BaseQOSSTData): x: int def __init__(self, x:int): self.x = x my_object = MyData(x=3) type(my_object) # MyData my_object.x # 3 my_object.save("test") my_object2 = MyData.load("test") type(my_object2) # MyData my_object2.x # 3
- static load(path: str | PathLike[str])
Load from file and return an instance of the class.
- Parameters:
path (QOSSTPath) – the path of the file to load.
- Returns:
an instance of the current class.
- Return type:
Self
- dump(path: str | PathLike[str]) None
Dump the current object to a file.
- Parameters:
path (QOSSTPath) – the path where to save the data.
- save(path: str | PathLike[str]) None
Alias of dump. Dump the current object to a file.
- Parameters:
path (QOSSTPath) – the path where to save the data.
- get_saved_info() str
Get the information on the save (datetime of the save, path of the save and if the current object was loaded from this path).
- Returns:
string with the save info.
- Return type:
str
- set_loaded() None
Function to call when the object is loaded.