simulaqron.settings package¶
Submodules¶
simulaqron.settings.network_config module¶
- class simulaqron.settings.network_config.NetworkConfig(name: str, topology: ~typing.Dict[str, ~typing.List[str]] | None = None, nodes: ~typing.Dict[str, ~simulaqron.settings.network_config.NodeConfig] = <factory>)[source]¶
Bases:
JSONSerializerMixinUsed by NetworksConfiguration to keep track of the config of a single network. This object holds the node configuration (as
NodeConfiginstances) of all the nodes within a network.- add_node(name: str, app_hostname: str, qnodeos_hostname: str, vnode_hostname: str, app_port: int, qnodeos_port: int, vnode_port: int, neighbors: List[str] | None = None)[source]¶
Adds a node with the given name to the network If hostnames are not given they will default to ‘localhost’. If the port numbers None, unused ones will be chosen between 8000 and 9000. If neighbors are specified a restricted topology can be constructed (default is fully connected).
- Parameters:
name – str Name of the node, e.g. Alice
app_hostname – str Hostname (e.g. localhost) or IP address (e.g. 192.168.0.1)
qnodeos_hostname – str Hostname (e.g. localhost) or IP address (e.g. 192.168.0.1)
vnode_hostname – str Hostname (e.g. localhost) or IP address (e.g. 192.168.0.1)
app_port – int Port number for the application
qnodeos_port – int Port number for the qnodeos server
vnode_port – int Port number for the virtual node
neighbors – (list of str) or None A list of neighbors, of this node. If None all current nodes in the network will be adjacent to the added node.
- add_node_config(node_cfg: NodeConfig)[source]¶
- property is_empty: bool¶
Whether this network configuration is empty or not.
- name: str¶
- nodes: Dict[str, NodeConfig]¶
- property nodes_names: List[str]¶
Gets a list of strings with the names of nodes on this network.
- remove_node(node_name: str) NodeConfig | None[source]¶
Removes the node with the given name and returns it. Returns none if the given node name was not found in this network.
- Parameters:
node_name (str) – The name of the node to remove. None if the node name does not exist.
- Returns:
The removed node. None if the given name was not found.
- Return type:
NodeConfig | None
- topology: Dict[str, List[str]] | None = None¶
- class simulaqron.settings.network_config.NetworksConfiguration(networks: ~typing.Dict[str, ~simulaqron.settings.network_config.NetworkConfig] = <factory>, used_sockets: ~typing.List[~typing.Tuple[str, int]] = <factory>)[source]¶
Bases:
JSONSerializerMixinUsed to construct the config file of networks.
- add_network(node_names: List[str], network_name: str = 'default', topology: Dict[str, List[str]] | None = None)[source]¶
Adds a new network to the config, with some specified nodes.
- Parameters:
node_names (List[str]) – Name of the nodes, e.g. [Alice, Bob]
network_name (str) – Name of the network (default: “default”).
topology (Dict[str, List[str]] | None) – The topology of the network (optional) (default is fully connected)
- add_network_config(net_cfg: NetworkConfig)[source]¶
Adds the given network config to the whole networks configuration. :param net_cfg: The network configu object to add to the specifications. :type net_cfg: NetworkConfig
- add_node(node_name: str, network_name: str = 'default', app_hostname: str = 'localhost', qnodeos_hostname: str = 'localhost', vnode_hostname: str = 'localhost', app_port: int = -1, qnodeos_port: int = -1, vnode_port: int = -1, neighbors: List[str] | None = None)[source]¶
Adds a node with the given name to a network (default: “default”). If hostnames are None they will default to ‘localhost’. If the port numbers None, unused ones will be chosen between 8000 and 9000. If neighbors are specified a restricted topology can be constructed (default is fully connected).
- Parameters:
node_name (str) – Name of the node, e.g. Alice.
network_name (str) – Name of the network (default: “default”).
app_hostname (str) – Hostname, e.g. localhost (the default if not given) or 192.168.0.1
qnodeos_hostname (str) – Hostname, e.g. localhost (the default if not given) or 192.168.0.1
vnode_hostname (str) – Hostname, e.g. localhost (the default if not given) or 192.168.0.1
app_port (int) – Port number for the application. A free port in the range 8000-9000 will be allocated if not given
qnodeos_port (int) – Port number for the application. A free port in the range 8000-9000 will be allocated if not given.
vnode_port (int) – Port number for the application. A free port in the range 8000-9000 will be allocated if not given.
neighbors (List[str] | None) – A list of neighbors, of this node. If None all current nodes in the network will be adjacent to the added node.
- get_node_names(network_name: str = 'default')[source]¶
Returns the names of the nodes in a network.
- Parameters:
network_name (str) – Name of the network (default: “default”).
- Returns:
A lit of node names in the given network.
- Return type:
List[str]
- get_nodes(network_name: str = 'default') List[NodeConfig][source]¶
Returns the node-config objects (NodeConfig) in a network that belong to the given network.
- Parameters:
network_name (str) – Name of the network (default: “default”)
- Returns:
A list of
NodeConfigclasses with the nodes configuration.- Return type:
List[NodeConfig]
- property network_names: List[str]¶
Gets the loaded network names.
- Returns:
A list of strings with the network names.
- Return type:
List[str]
- networks: Dict[str, NetworkConfig]¶
- property nodes: List[NodeConfig]¶
Access the nodes of the default network held by this configuration.
- Returns:
A list of NodeConfig objects.
- Return type:
list[NodeConfig]
- read_from_file(file_path: PathLike | str)[source]¶
Reads config from a file.
- Parameters:
file_path (PathLike | str) – If a file_path was specified upon __init__ this will be used if file_path is None.
- classmethod read_from_known_sources() Self[source]¶
Load config from the default config file.
Uses
get_default_network_config_file()to resolve the path.- Returns:
Loaded network configuration.
- Return type:
NetworkConfigBuilder
- read_from_legacy_files(app_file_path: PathLike | str, vnode_file_path: PathLike | str, qnodeos_file_path: PathLike | str | None = None)[source]¶
Constructs a network configuration from a set of legacy format (.cfg) network files.
Warning
This method is not implemented yet, and simply raises
NotImplementedException.- Parameters:
app_file_path (PathLike | str) – Path of the classical network file.
vnode_file_path (PathLike | str) – Path of the virtual network file.
qnodeos_file_path (PathLike | str) – Path of the QNodeOS network file. If this path is not give, the same hosts as vnodes_file_path will be used, assigning a new, random port in the 8000-9000 range.
- remove_network(network_name: str = 'default')[source]¶
Removes a network from the config.
- Parameters:
network_name (str) – Name of the network (default: “default”).
- remove_node(node_name: str, network_name: str = 'default')[source]¶
Removes a node from the network.
- Parameters:
node_name (str) – Name of the node to remove, e.g. Alice.
network_name (str) – Name of the network to delete the node from (default: “default”)
- used_sockets: List[Tuple[str, int]]¶
- class simulaqron.settings.network_config.NodeConfig(name: str, app_port: int, qnodeos_port: int, vnode_port: int, app_hostname: str = 'localhost', qnodeos_hostname: str = 'localhost', vnode_hostname: str = 'localhost')[source]¶
Bases:
JSONSerializerMixinUsed by NetworkConfig to keep track of the node config of a single node. This object holds the hostname and port info for the application, the SimulaQron Virtual Node and the QNodeOS server.
- app_hostname: str = 'localhost'¶
- app_port: int¶
- get_config(config_type: str | NodeConfigType) Tuple[str, int][source]¶
Gets the corresponding host and port config tuple for the given type.
- Parameters:
config_type (str | NodeConfigType) – The type of configuration to get. Can either be expressed as a string or a NodeConfigType.
- Returns:
A tuple containing the host and port config for the given configuration type.
- Return type:
Tuple[str, int]
- name: str¶
- qnodeos_hostname: str = 'localhost'¶
- qnodeos_port: int¶
- vnode_hostname: str = 'localhost'¶
- vnode_port: int¶
- class simulaqron.settings.network_config.NodeConfigType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
StrEnum- APP = 'app'¶
- QNODEOS = 'qnodeos'¶
- VNODE = 'vnode'¶
- simulaqron.settings.network_config.get_default_network_config_file(use_embedded: bool = False) Path[source]¶
Get the network config file path to use.
- Parameters:
use_embedded (bool) – If True, always use the embedded default (for tests). If False, uses priority: LOCAL > HOME > embedded.
- Returns:
Path to the network config file.
- Return type:
Path
simulaqron.settings.simulaqron_config module¶
- class simulaqron.settings.simulaqron_config.SimBackend(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
JSONSerializerMixin,EnumEnum used to list the supported SimulaQron backends.
- PROJECTQ = 'projectq'¶
- QUTIP = 'qutip'¶
- STABILIZER = 'stabilizer'¶
- class simulaqron.settings.simulaqron_config.SimulaqronConfig(max_qubits: int = 20, max_registers: int = 1000, conn_retry_time: float = 0.5, conn_max_retries: int = 10, recv_timeout: int = 100, recv_retry_time: float = 0.1, recv_max_retries: int = 10, log_level: int = 30, sim_backend: SimBackend = SimBackend.QUTIP, noisy_qubits: bool = False, max_app_waiting_time: float = -1.0, t1: float = 1.0)[source]¶
Bases:
JSONSerializerMixinHolds the general SimulaQron config.
- conn_max_retries: int = 10¶
- conn_retry_time: float = 0.5¶
- default_settings()[source]¶
Resets the current SimulaQron configuration object to its default configuration set. The default configuration is: * max_qubits = 20 * max_registers = 1000 * conn_retry_time = 0.5 * conn_max_retries = 10 * recv_timeout = 100 * recv_retry_time = 0.1 * recv_max_retries = 10 * log_level = logging.WARNING * sim_backend = SimBackend.QUTIP * noisy_qubits = False * max_app_waiting_time = -1.0 # In seconds, negative means unlimited waiting * t1: float = 1.0
- log_level: int = 30¶
- max_app_waiting_time: float = -1.0¶
- max_qubits: int = 20¶
- max_registers: int = 1000¶
- noisy_qubits: bool = False¶
- read_from_file(file_path: Path | str)[source]¶
Reads the SimulaQron configuration from the given file path. :param file_path: A pathlib.Path or str representing the file path to read the configurations from. :type file_path: Path | str
- classmethod read_from_known_sources() Self[source]¶
Reads the SimulaQron configuration from usual locations. This method will try to load the configuration files in the following order from (1) the current folder (./simulaqron_settings.json) and, (2) simulaqron settings in the user’s home folder (~/.simulaqron/simulaqron_settings.json).
If none of these files exists, this method will create a SimulaQron configuration in user’s home folder (~/.simulaqron/simulaqron_settings.json) containing the default SimulaQron configuration.
To check the default configuration, check the documentation of default_settings. See Also:
default_settings()
- recv_max_retries: int = 10¶
- recv_retry_time: float = 0.1¶
- recv_timeout: int = 100¶
- sim_backend: SimBackend = 'qutip'¶
- t1: float = 1.0¶