Commit 11087ee3 authored by Samuel Rowlinson's avatar Samuel Rowlinson
Browse files

Minor name and comment changes for clarity

parent f22a0cc5
Pipeline #241974 passed with stages
in 20 minutes and 15 seconds
......@@ -252,9 +252,9 @@ cdef class KnmConnectorWorkspace(ConnectorWorkspace):
q_to = &self.sim.trace[no_idx]
# Mode mismatch is only changing if this node coupling is
# in the pre-determined mismatched_node_couplings of the sim
# in the pre-determined changing_mismatch_couplings of the sim
is_mm_changing = (
list(self.o2o.values())[i] in self.sim.mismatched_node_couplings
list(self.o2o.values())[i] in self.sim.changing_mismatch_couplings
# Or if the component is misaligned and we have changing beam parameters
# at this coupling then also need to recompute scatter matrix
or (
......
......@@ -340,7 +340,7 @@ cdef class ModeMismatchDetectorWorkspace(DetectorWorkspace):
self.abcd = np.eye(2)
# Determine whether the node coupling is one with changing mismatch
self.is_changing = (node1, node2) in self.sim.mismatched_node_couplings
self.is_changing = (node1, node2) in self.sim.changing_mismatch_couplings
cdef complex_t q1_matched = transform_q(self.abcd, self.q1.q, self.q1.nr, self.q2.nr)
self.initial = self.pscale * (1.0 - overlap(q1_matched, self.q2.q))
......
......@@ -143,13 +143,15 @@ cdef class CarrierSignalMatrixSimulation:
### Tracing stuff ###
public dict cavity_workspaces
NodeBeamParam* trace
# Beam parameters in initial state as a BeamTraceSolution object
readonly object initial_trace_sol
# The TraceForest of geometrically changing branches. This is an
# empty forest for any simulation in which geometric parameters
# are not changing.
readonly TraceForest trace_forest
# Node couplings which will have potential mode mismatches,
# Node couplings which will have changing mode mismatches,
# determined from trace_forest via tree intersection searching
readonly tuple mismatched_node_couplings
readonly tuple changing_mismatch_couplings
# A dict of {<tuple of newly unstable cavities> : <contingent TraceForest>}
# required for when a scan results in a geometrically changing cavity becoming
# unstable -> invalidating self.trace_forest temporarily for that data point
......
......@@ -910,8 +910,9 @@ cdef class CarrierSignalMatrixSimulation:
def __init__(self, model, unicode name, bint needs_matrix=True):
self.model = model
self.name = name
self.initial_trace_sol = None
self.trace = NULL
self.mismatched_node_couplings = ()
self.changing_mismatch_couplings = ()
self.contingent_trace_forests = {}
self.needs_reflag_changing_q = False
self.do_matrix_solving = needs_matrix
......@@ -1100,16 +1101,16 @@ cdef class CarrierSignalMatrixSimulation:
def is_component_in_mismatch_couplings(self, comp):
"""Determines whether the connector `comp` is associated with any
of the node couplings in the stored potential mismatch couplings.
of the node couplings in the stored changing mismatch couplings.
.. note::
This method can be replaced if connectors eventually use more
granular refill flags --- i.e. per coupling refill flags. Then
the check for refilling that coupling can simply include the
condition ``(from_node, to_node) in sim.mismatched_node_couplings``.
condition ``(from_node, to_node) in sim.changing_mismatch_couplings``.
"""
return any(node.component is comp for node, _ in self.mismatched_node_couplings)
return any(node.component is comp for node, _ in self.changing_mismatch_couplings)
cdef void _setup_trace_forest(self, TraceForest forest=None, bint set_tree_node_ids=True):
cdef:
......@@ -1506,7 +1507,8 @@ cdef class CarrierSignalMatrixSimulation:
"Performing initial beam trace with configuration options: %s",
self.model.sim_trace_config,
)
self.model.beam_trace(**self.model.sim_trace_config)
# Plant the model trace_forest and execute initial beam trace
self.initial_trace_sol = self.model.beam_trace(**self.model.sim_trace_config)
model_trace_forest = self.model.trace_forest
self.retrace = self.model.retrace
self.trace = <NodeBeamParam*> calloc(len(optical_nodes), sizeof(NodeBeamParam))
......@@ -1514,7 +1516,7 @@ cdef class CarrierSignalMatrixSimulation:
raise MemoryError()
for i, n in enumerate(optical_nodes):
qx, qy = self.model.last_trace[n]
qx, qy = self.initial_trace_sol[n]
nr = qx.nr
# NOTE set is_changing to True for all node beam params initially
......@@ -1539,17 +1541,17 @@ cdef class CarrierSignalMatrixSimulation:
# Get the nodes at which trees of the changing forest intersect
# with trees of the full forest which have different trace
# dependencies. These couplings will be potentially mismatched
# during the simulation.
self.mismatched_node_couplings = self.trace_forest.find_potential_mismatch_couplings(
# dependencies. These couplings will have potentially changing
# mode mismatches during the simulation.
self.changing_mismatch_couplings = self.trace_forest.find_potential_mismatch_couplings(
model_trace_forest
)
if self.mismatched_node_couplings:
if self.changing_mismatch_couplings:
LOGGER.info(
"Found changing mismatched node couplings: %s",
[f"{n1.full_name} -> {n2.full_name}"
for n1, n2 in self.mismatched_node_couplings]
for n1, n2 in self.changing_mismatch_couplings]
)
else:
self.trace_forest = TraceForest(self.model)
......
"""Testing the structure of TraceForests built from the model forest with
only changing trees and branches included. These are constructed as an
initial step when building the simulation."""
"""Testing the structure of TraceForests built from the model forest with only changing
trees and branches included.
These are constructed as an initial step when building the simulation.
"""
import pytest
from finesse import Model
......@@ -39,8 +41,8 @@ def cavity_model():
"change", ("CAV.L", "ITM.Rcx", "ETM.Rcy"),
)
def test_changing_cavity_geometry_forest(cavity_model: Model, change):
"""Check that the changing forest is the whole cavity model when setting
a geometric parameter of the cavity to tunable."""
"""Check that the changing forest is the whole cavity model when setting a geometric
parameter of the cavity to tunable."""
IFO = cavity_model
internal_cav_tree = ctracer.TraceTree.from_cavity(IFO.FP)
......@@ -73,15 +75,15 @@ def test_changing_cavity_geometry_forest(cavity_model: Model, change):
# Only a single Cavity dependency so shouldn't be any
# mismatch node couplings present
assert len(sim.mismatched_node_couplings) == 0
assert len(sim.changing_mismatch_couplings) == 0
@pytest.mark.parametrize(
"change", ("ITM.phi", "ETM.phi", "ITM.R", "ETM.T", "ITM.xbeta", "ETM.ybeta"),
)
def test_changing_non_geometric_cavity_parameter_forest(cavity_model: Model, change):
"""Check that the changing forest is empty when only a non-geometric parameter
is set to tunable."""
"""Check that the changing forest is empty when only a non-geometric parameter is
set to tunable."""
IFO = cavity_model
comp, param = change.split(".")
......@@ -91,12 +93,12 @@ def test_changing_non_geometric_cavity_parameter_forest(cavity_model: Model, cha
chng_forest = sim.trace_forest.forest
assert len(chng_forest) == 0
assert len(sim.mismatched_node_couplings) == 0
assert len(sim.changing_mismatch_couplings) == 0
def test_changing_post_cavity_space_length_forest(cavity_model: Model):
"""Check that the changing forest is just the tree from the end mirror
forwards when length of space after cavity is set to tunable."""
"""Check that the changing forest is just the tree from the end mirror forwards when
length of space after cavity is set to tunable."""
IFO = cavity_model
external_tree_out = ctracer.TraceTree.from_node(
......@@ -114,12 +116,12 @@ def test_changing_post_cavity_space_length_forest(cavity_model: Model):
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == 0
assert len(sim.changing_mismatch_couplings) == 0
def test_changing_pre_cavity_space_length_forest(cavity_model: Model):
"""Check that the changing forest is just the tree from the input mirror
backwards when length of space before cavity is set to tunable."""
"""Check that the changing forest is just the tree from the input mirror backwards
when length of space before cavity is set to tunable."""
IFO = cavity_model
external_tree_back = ctracer.TraceTree.from_node(
......@@ -143,12 +145,12 @@ def test_changing_pre_cavity_space_length_forest(cavity_model: Model):
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == 0
assert len(sim.changing_mismatch_couplings) == 0
def test_changing_pre_bs_space_length_forest(cavity_model: Model):
"""Check that the changing forest is just the tree from the BS
backwards when length of space before BS is set to tunable."""
"""Check that the changing forest is just the tree from the BS backwards when length
of space before BS is set to tunable."""
IFO = cavity_model
external_tree_back = ctracer.TraceTree.from_node(
......@@ -166,7 +168,7 @@ def test_changing_pre_bs_space_length_forest(cavity_model: Model):
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == 0
assert len(sim.changing_mismatch_couplings) == 0
##### Adding a Gauss at the laser for extra complexity #####
......@@ -217,13 +219,13 @@ def test_changing_cavity_geometry_with_laser_gauss_forest(cavity_model: Model, c
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == len(expect_mm_couplings)
assert set(sim.mismatched_node_couplings) == set(expect_mm_couplings)
assert len(sim.changing_mismatch_couplings) == len(expect_mm_couplings)
assert set(sim.changing_mismatch_couplings) == set(expect_mm_couplings)
def test_changing_pre_bs_space_length_with_laser_gauss_forest(cavity_model: Model):
"""Check that the changing forest is just the tree from the BS
forwards (from gauss node) when setting pre-BS space length tunable."""
"""Check that the changing forest is just the tree from the BS forwards (from gauss
node) when setting pre-BS space length tunable."""
IFO = cavity_model
IFO.parse("gauss gL0 L0.p1.o q=-1+1j")
......@@ -250,16 +252,16 @@ def test_changing_pre_bs_space_length_with_laser_gauss_forest(cavity_model: Mode
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == len(expect_mm_couplings)
assert set(sim.mismatched_node_couplings) == set(expect_mm_couplings)
assert len(sim.changing_mismatch_couplings) == len(expect_mm_couplings)
assert set(sim.changing_mismatch_couplings) == set(expect_mm_couplings)
@pytest.mark.parametrize(
"change", ("gL0.w0x", "gL0.w0y", "gL0.zx", "gL0.zy"),
)
def test_changing_laser_gauss_forest(cavity_model: Model, change):
"""Check that the changing forest is just the tree from the laser
forwards when setting a Gauss parameter tunable."""
"""Check that the changing forest is just the tree from the laser forwards when
setting a Gauss parameter tunable."""
IFO = cavity_model
IFO.parse("gauss gL0 L0.p1.o q=-1+1j")
......@@ -287,13 +289,13 @@ def test_changing_laser_gauss_forest(cavity_model: Model, change):
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == len(expect_mm_couplings)
assert set(sim.mismatched_node_couplings) == set(expect_mm_couplings)
assert len(sim.changing_mismatch_couplings) == len(expect_mm_couplings)
assert set(sim.changing_mismatch_couplings) == set(expect_mm_couplings)
def test_changing_bs_roc_with_cavity_priority_forest(cavity_model: Model):
"""Check that the changing forest is the trees coming from BS1 when
setting BS1.Rcx tunable and cavity has highest trace priority."""
"""Check that the changing forest is the trees coming from BS1 when setting BS1.Rcx
tunable and cavity has highest trace priority."""
IFO = cavity_model
IFO.parse("gauss gL0 L0.p1.o q=-1+1j priority=-1")
......@@ -323,13 +325,13 @@ def test_changing_bs_roc_with_cavity_priority_forest(cavity_model: Model):
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == len(expect_mm_couplings)
assert set(sim.mismatched_node_couplings) == set(expect_mm_couplings)
assert len(sim.changing_mismatch_couplings) == len(expect_mm_couplings)
assert set(sim.changing_mismatch_couplings) == set(expect_mm_couplings)
def test_changing_bs_roc_with_gauss_priority_forest(cavity_model: Model):
"""Check that the changing forest is the trees coming from BS1 when
setting BS1.Rcx tunable and gauss has highest trace priority."""
"""Check that the changing forest is the trees coming from BS1 when setting BS1.Rcx
tunable and gauss has highest trace priority."""
IFO = cavity_model
IFO.parse("gauss gL0 L0.p1.o q=-1+1j priority=1")
......@@ -362,8 +364,8 @@ def test_changing_bs_roc_with_gauss_priority_forest(cavity_model: Model):
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == len(expect_mm_couplings)
assert set(sim.mismatched_node_couplings) == set(expect_mm_couplings)
assert len(sim.changing_mismatch_couplings) == len(expect_mm_couplings)
assert set(sim.changing_mismatch_couplings) == set(expect_mm_couplings)
@pytest.mark.parametrize(
......@@ -372,8 +374,8 @@ def test_changing_bs_roc_with_gauss_priority_forest(cavity_model: Model):
def test_changing_cavity_geometry_with_laser_gauss_disabled_forest(
cavity_model: Model, change
):
"""Check that the changing forest is the whole cavity model when disabling
the laser gauss and setting a geometric parameter of cavity tunable."""
"""Check that the changing forest is the whole cavity model when disabling the laser
gauss and setting a geometric parameter of cavity tunable."""
IFO = cavity_model
IFO.parse("gauss gL0 L0.p1.o q=-1+1j")
......@@ -407,14 +409,17 @@ def test_changing_cavity_geometry_with_laser_gauss_disabled_forest(
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == 0
assert len(sim.changing_mismatch_couplings) == 0
def test_changing_itm_roc_with_laser_gauss_forest(cavity_model: Model):
"""Check that the changing forest is the cavity forwards with laser gauss
set as highest priority. Also checks that ITM.p1.i -> ITM.p1.o is in the
mismatched node couplings as a special case (as these nodes aren't in
changing forest but coupling can still change when symmetrically tracing)."""
"""Check that the changing forest is the cavity forwards with laser gauss set as
highest priority.
Also checks that ITM.p1.i -> ITM.p1.o is in the mismatched node couplings as a
special case (as these nodes aren't in changing forest but coupling can still change
when symmetrically tracing).
"""
IFO = cavity_model
IFO.parse("gauss gL0 L0.p1.o q=-1+1j priority=1")
......@@ -444,8 +449,8 @@ def test_changing_itm_roc_with_laser_gauss_forest(cavity_model: Model):
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == len(expect_mm_couplings)
assert set(sim.mismatched_node_couplings) == set(expect_mm_couplings)
assert len(sim.changing_mismatch_couplings) == len(expect_mm_couplings)
assert set(sim.changing_mismatch_couplings) == set(expect_mm_couplings)
@pytest.mark.parametrize(
......@@ -457,8 +462,8 @@ def test_changing_itm_roc_with_laser_gauss_forest(cavity_model: Model):
def test_changing_cavity_geometry_and_laser_gauss_forest(
cavity_model: Model, change_cav, change_gauss
):
"""Check that the changing forest is the whole cavity model when setting
a geometric parameter of the cavity and the laser gauss to tunable."""
"""Check that the changing forest is the whole cavity model when setting a geometric
parameter of the cavity and the laser gauss to tunable."""
IFO = cavity_model
IFO.parse("gauss gL0 L0.p1.o q=-1+1j")
......@@ -504,8 +509,8 @@ def test_changing_cavity_geometry_and_laser_gauss_forest(
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == len(expect_mm_couplings)
assert set(sim.mismatched_node_couplings) == set(expect_mm_couplings)
assert len(sim.changing_mismatch_couplings) == len(expect_mm_couplings)
assert set(sim.changing_mismatch_couplings) == set(expect_mm_couplings)
@pytest.mark.parametrize(
......@@ -514,8 +519,8 @@ def test_changing_cavity_geometry_and_laser_gauss_forest(
def test_changing_cavity_geometry_and_laser_gauss_reversed_priorities_forest(
cavity_model: Model, change
):
"""Check that the changing forest is the whole cavity model when setting
a geometric parameter of the cavity and the laser gauss to tunable."""
"""Check that the changing forest is the whole cavity model when setting a geometric
parameter of the cavity and the laser gauss to tunable."""
IFO = cavity_model
IFO.parse("gauss gL0 L0.p1.o q=-1+1j priority=1")
......@@ -557,5 +562,5 @@ def test_changing_cavity_geometry_and_laser_gauss_reversed_priorities_forest(
for tree1, tree2 in zip(expect_forest, chng_forest):
assert_trace_trees_equal(tree1, tree2)
assert len(sim.mismatched_node_couplings) == len(expect_mm_couplings)
assert set(sim.mismatched_node_couplings) == set(expect_mm_couplings)
assert len(sim.changing_mismatch_couplings) == len(expect_mm_couplings)
assert set(sim.changing_mismatch_couplings) == set(expect_mm_couplings)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment