finesse.utilities.network_filter module

class finesse.utilities.network_filter.ComponentNetworkFilter(model: Model, root: str | ModelElement | Node | None = None, radius: int | None = None, undirected: bool = True, add_edge_info: bool = False, add_detectors: bool = False)[source]

Bases: NetworkFilterBase

network_type = 'component'
class finesse.utilities.network_filter.FullNetworkFilter(model: Model, root: str | ModelElement | Node | None = None, radius: int | None = None, undirected: bool = True, add_edge_info: bool = False, add_detectors: bool = False)[source]

Bases: NodeNetworkFilter

network_type = 'full'
class finesse.utilities.network_filter.NetworkFilterBase(model: Model, root: str | ModelElement | Node | None = None, radius: int | None = None, undirected: bool = True, add_edge_info: bool = False, add_detectors: bool = False)[source]

Bases: ABC

Abstract base class that implements distance based filtering of a model graph. Should mostly be used to directly call the run method after initialization, not guaranteed that the state makes sense if it is kept alive.

Used by finesse.model.Model.plot_graph() and finesse.model.Model.component_tree(), see also their docstrings for more clarification on the arguments.

add_detectors: bool = False
add_edge_info: bool = False
model: Model
property network: Graph[source]

Returns

nx.Graph

The relevant network for this filter

network_type: ClassVar[NetworkType]
radius: int | None = None
root: str | ModelElement | Node | None = None
property root_str: str[source]

Transforms the root argument into a string that represents a node in the relevant graph. Must implement _root_to_str and _root_options in the subclass to makes this work.

Returns

str

Root node as the string name in the graph

run() Graph[source]

Runs the filter and returns the filtered graph. Modifies self.network in place, so can not be called repeatedly.

Returns

nx.Graph

The filtered graph.

undirected: bool = True
class finesse.utilities.network_filter.NetworkType(*values)[source]

Bases: Enum

COMPONENT = 'component'
FULL = 'full'
OPTICAL = 'optical'
PORT = 'port'
property filter_class: type[NetworkFilterBase][source]

Get the relevant filter class for this network type.

Returns

type[NetworkFilterBase]

The relevant filter class

get_network(model: Model, add_edge_info: bool = False) nx.Graph[source]

Retrieve the relevant network for this network type.

Parameters

modelModel

Model to retrieve the netwrok from

add_edge_infobool, optional

Add metadata to the component network on via which ports components are connected, by default False. Ignore for any type other than NetworkType.COMPONENT

Returns

nx.Graph

The relevant model graph

Raises

NotImplementedError

If there is no implementation for newly added network types.

class finesse.utilities.network_filter.NodeNetworkFilter(model: Model, root: str | ModelElement | Node | None = None, radius: int | None = None, undirected: bool = True, add_edge_info: bool = False, add_detectors: bool = False)[source]

Bases: NetworkFilterBase

class finesse.utilities.network_filter.OpticalNetworkFilter(model: Model, root: str | ModelElement | Node | None = None, radius: int | None = None, undirected: bool = True, add_edge_info: bool = False, add_detectors: bool = False)[source]

Bases: NodeNetworkFilter

network_type = 'optical'
class finesse.utilities.network_filter.PortNetworkFilter(model: Model, root: str | ModelElement | Node | None = None, radius: int | None = None, undirected: bool = True, add_edge_info: bool = False, add_detectors: bool = False)[source]

Bases: NodeNetworkFilter

network_type = 'port'