finesse.tracing.tree module
The TraceTree data structure and associated algorithms.
Details on each class, method and function in this sub-module are provided mostly for
developers. Users should refer to Tracing the beam for details on beam tracing,
Model.beam_trace() for the main method through which beam traces can be performed
on a model and tracing.tools for the various beam propagation tools which the
beam tracing library provides.
- class finesse.tracing.tree.TraceTree(node, dependency)[source]
Bases:
objectA binary tree data structure representing all the beam tracing paths from some root optical node of a model.
Each instance of this class has a left and right sub-tree (of the class type) and a parent tree. These linked tree attributes can be None. If the tree has a left / right sub-tree then the memoryviews left_abcd_x, left_abcd_y etc. will be initialised from the numerical ABCD matrix from the tree’s optical node to the next tree’s optical node.
Every sub-tree has a dependency attribute which is the object that the trace tree depends on - either a
Cavityor agaussinstance.- add_left(self, TraceTree sub_tree) TraceTree
Add a left sub-tree to the tree.
Parameters
- sub_tree
TraceTree The tree to add to the left.
Returns
- sub_tree
TraceTree The same tree that was added. This is useful for looping over a single branch of the tree as a parent tree can be set to the return of this method on each iteration.
- sub_tree
- add_right(self, TraceTree sub_tree) TraceTree
Add a right sub-tree to the tree.
Parameters
- sub_tree
TraceTree The tree to add to the right.
Returns
- sub_tree
TraceTree The same tree that was added. This is useful for looping over a single branch of the tree as a parent tree can be set to the return of this method on each iteration.
- sub_tree
- contains(self, o) bool
Whether the tree contains the specified object, determined recursively.
Parameters
- o[
TraceTree|OpticalNode|Space|Connector] The object to search for in the trace tree.
Returns
- flagbool
True if o is in the tree, False otherwise.
- o[
- dependency
- find_tree_at_node(self, node, bool include_opposite=False) TraceTree
Recursively search for the TraceTree corresponding to the optical node.
- classmethod from_cavity(cls, cavity)[source]
Construct a TraceTree from a cavity instance.
The resulting tree decays to a linked list as it just includes the internal path of the cavity.
Parameters
- cavity
Cavity The cavity object.
Returns
- tree
TraceTree The tree representing the internal cavity path.
- cavity
- classmethod from_node(cls, node, dependency, bool symmetric, pre_node=None, bool is_source=False, exclude=None)[source]
Construct a TraceTree from an optical node root.
The resulting tree includes all optical node paths traced forward from node.
Parameters
- node
OpticalNode The root node.
- dependency
CavityorGauss The dependency object - i.e. what the trace sub-trees depend on.
- symmetricbool
Flag indicating whether the tree should be constructed assuming that opposite node beam parameters will be set via the reverse of the original node beam parameter (true indicates this will be the case). In practice, this means that the resultant tree will not include any duplicate ports.
- pre_node
OpticalNode, optional; default: None An optional node to add before the root for the root sub-tree.
- is_sourcebool, optional; default: False
Whether the root node is the source node of a TraceDependency.
- excludeset, optional
Set of optical nodes to avoid branching to.
Returns
- tree
TraceTree The tree of all paths from node.
- node
- static from_path(list path)[source]
Construct a TraceTree from a list of optical nodes.
The resulting tree decays to a linked list as the path is 1D - no branches will occur.
Parameters
- pathlist
A list of optical nodes representing the node path. This can be obtained from a
OpticalPathinstance by invokingOpticalPath.nodes.
Returns
- tree
TraceTree The tree representing the node path.
- get_all_nodes(self) OrderedSet
Retrieve a set consisting of all the
OpticalNodeobjects covered by this tree.Returns
- nodesset
A set of all the optical nodes in the tree.
- get_broadest_changing_subtrees(self) list
Retrieve a list of each TraceTree, from here, which is changing.
- get_mirror_reflection_couplings(self) list
Obtain a list of all the node couplings corresponding to self-reflections.
- is_left_surf_refl
- is_source
- is_x_changing
- is_y_changing
- left
- left_abcd_x
- left_abcd_x_args
- left_abcd_x_kwargs
- left_abcd_x_target
- left_abcd_y
- left_abcd_y_args
- left_abcd_y_kwargs
- left_abcd_y_target
- node
- nr
- parent
- remove_left(self) TraceTree
Removes the left sub-tree and returns it.
Sets the
lefttrace tree attribute to None, and nullifies left ABCD memory-views and pointers.Returns
- ltree
TraceTree The removed left sub-tree.
- ltree
- remove_right(self) TraceTree
Removes the right sub-tree and returns it.
Sets the
righttrace tree attribute to None, and nullifies right ABCD memory-views and pointers.Returns
- rtree
TraceTree The removed right sub-tree.
- rtree
- right
- right_abcd_x
- right_abcd_x_args
- right_abcd_x_kwargs
- right_abcd_x_target
- right_abcd_y
- right_abcd_y_args
- right_abcd_y_kwargs
- right_abcd_y_target
- set_left_abcd_x_memory(self, target, *args, **kwargs)[source]
Set the left ABCD matrix memory-views from the target function. Stores where this ABCD matrix came from for later retrieval and recreation if copied or pickled.
- set_left_abcd_y_memory(self, target, *args, **kwargs)[source]
Set the left ABCD matrix memory-views from the target function. Stores where this ABCD matrix came from for later retrieval and recreation if copied or pickled.
- set_right_abcd_x_memory(self, target, *args, **kwargs)[source]
Set the right ABCD matrix memory-views from the target function. Stores where this ABCD matrix came from for later retrieval and recreation if copied or pickled.
- set_right_abcd_y_memory(self, target, *args, **kwargs)[source]
Set the right ABCD matrix memory-views from the target function. Stores where this ABCD matrix came from for later retrieval and recreation if copied or pickled.
- sym_left_abcd_x
- sym_left_abcd_y
- sym_right_abcd_x
- sym_right_abcd_y
- finesse.tracing.tree.get_tracing_tree(optical_network: networkx.DiGraph) networkx.DiGraph[source]
Creates a view of an optical network that removes edges that should not be ABCD traced. These are determined by checking the objects Connector._trace_through flag.