Commit a5997c22 authored by Daniel Brown's avatar Daniel Brown
Browse files

Fixing detectors using sims instead of expecting sim now

parent 7aecf063
......@@ -90,5 +90,5 @@ class AmplitudeDetector(Detector):
"""
return self.__m
def _get_workspace(self, sims):
return ADWorkspace(self, sims)
def _get_workspace(self, sim):
return ADWorkspace(self, sim)
......@@ -25,5 +25,5 @@ class AstigmatismDetector(Detector):
def needs_fields(self):
return False
def _get_workspace(self, sims):
return AstigmatismDetectorWorkspace(self, sims)
def _get_workspace(self, sim):
return AstigmatismDetectorWorkspace(self, sim)
......@@ -78,8 +78,8 @@ class Camera(Detector, ABC):
# TODO (sjr) Need to re-implement a method for re-constructing CameraWorkspace.frequencies
# if any frequency in DC.frequencies is changing
def _common_workspace_params(self, DC):
node_q_map = DC.model.last_trace
def _common_workspace_params(self, sim):
node_q_map = sim.model.last_trace
qx, qy = node_q_map[self._node]
if self.is_waist_scaled:
......@@ -365,12 +365,10 @@ class CCD(CCDCamera, Image):
Image.__init__(self, xlim, ylim, npts, dtype=np.float64)
CCDCamera.__init__(self, name, node, w0_scaled)
def _get_workspace(self, sims):
DC = sims[0]
def _get_workspace(self, sim):
x, y, qx, qy = self._common_workspace_params(sim)
x, y, qx, qy = self._common_workspace_params(DC)
ws = CCDWorkspace(self, sims, x, y, self._out)
ws = CCDWorkspace(self, sim, x, y, self._out)
ws.pre_compute_geometries(qx, qy)
ws.cache()
......@@ -421,12 +419,10 @@ class CCDScanLine(CCDCamera, ScanLine):
ScanLine.__init__(self, x, y, npts, direction, dtype=np.float64)
CCDCamera.__init__(self, name, node, w0_scaled, label=label, unit=unit)
def _get_workspace(self, sims):
DC = sims[0]
x, y, qx, qy = self._common_workspace_params(DC)
def _get_workspace(self, sim):
x, y, qx, qy = self._common_workspace_params(sim)
ws = CCDLineWorkspace(self, sims, x, y, self._out)
ws = CCDLineWorkspace(self, sim, x, y, self._out)
ws.pre_compute_geometries(qx, qy)
ws.cache()
......@@ -464,12 +460,10 @@ class CCDPixel(CCDCamera, Pixel):
Pixel.__init__(self, x, y, dtype=np.float64)
CCDCamera.__init__(self, name, node, w0_scaled, label=label, unit=unit)
def _get_workspace(self, sims):
DC = sims[0]
x, y, qx, qy = self._common_workspace_params(DC)
def _get_workspace(self, sim):
x, y, qx, qy = self._common_workspace_params(sim)
ws = CameraWorkspace(self, sims, x, y)
ws = CameraWorkspace(self, sim, x, y)
ws.pre_compute_geometries(qx, qy)
ws.cache()
......@@ -557,12 +551,10 @@ class FieldCamera(ComplexCamera, Image):
Image.__init__(self, xlim, ylim, npts, dtype=np.complex128)
ComplexCamera.__init__(self, name, node, f=f, w0_scaled=w0_scaled)
def _get_workspace(self, sims):
DC = sims[0]
def _get_workspace(self, sim):
x, y, qx, qy = self._common_workspace_params(sim)
x, y, qx, qy = self._common_workspace_params(DC)
ws = FieldCameraWorkspace(self, sims, x, y, self._out)
ws = FieldCameraWorkspace(self, sim, x, y, self._out)
ws.pre_compute_geometries(qx, qy)
ws.cache()
......@@ -616,12 +608,10 @@ class FieldScanLine(ComplexCamera, ScanLine):
ScanLine.__init__(self, x, y, npts, direction, dtype=np.complex128)
ComplexCamera.__init__(self, name, node, f=f, w0_scaled=w0_scaled)
def _get_workspace(self, sims):
DC = sims[0]
x, y, qx, qy = self._common_workspace_params(DC)
def _get_workspace(self, sim):
x, y, qx, qy = self._common_workspace_params(sim)
ws = FieldLineWorkspace(self, sims, x, y, self._out)
ws = FieldLineWorkspace(self, sim, x, y, self._out)
ws.pre_compute_geometries(qx, qy)
ws.cache()
......@@ -661,12 +651,10 @@ class FieldPixel(ComplexCamera, Pixel):
Pixel.__init__(self, x, y, dtype=np.complex128)
ComplexCamera.__init__(self, name, node, f=f, w0_scaled=w0_scaled)
def _get_workspace(self, sims):
DC = sims[0]
x, y, qx, qy = self._common_workspace_params(DC)
def _get_workspace(self, sim):
x, y, qx, qy = self._common_workspace_params(sim)
ws = FieldPixelWorkspace(self, sims, x, y)
ws = FieldPixelWorkspace(self, sim, x, y)
ws.pre_compute_geometries(qx, qy)
ws.cache()
......
......@@ -145,8 +145,8 @@ class CavityPropertyDetector(Detector):
self.__cavity = cavity
def _get_workspace(self, sims):
ws = CPDetectorWorkspace(self, sims)
def _get_workspace(self, sim):
ws = CPDetectorWorkspace(self, sim)
ws.nr = refractive_index(self.cavity.source) or 1.0
ws.q_as_bp = self.q_as_bp
return ws
......@@ -208,8 +208,8 @@ cdef class KnmDetectorWorkspace(DetectorWorkspace):
int n1, m1, n2, m2
KnmMatrix knm_matrix
def __init__(self, owner, sims):
super().__init__(owner, sims)
def __init__(self, owner, sim):
super().__init__(owner, sim)
knm_detector_output = OutputFuncWrapper.make_from_ptr(c_knm_detector_output)
cdef c_knm_detector_output(DetectorWorkspace dws):
......
......@@ -165,15 +165,15 @@ cdef class CameraWorkspace(MaskedDetectorWorkspace):
### CCD type camera workspaces ###
cdef class CCDWorkspace(CameraWorkspace):
def __init__(self, owner, sims, x, y, out):
super().__init__(owner, sims, x, y)
def __init__(self, owner, sim, x, y, out):
super().__init__(owner, sim, x, y)
self.out = out
cdef class CCDLineWorkspace(CameraWorkspace):
def __init__(self, owner, sims, x, y, out):
super().__init__(owner, sims, x, y)
def __init__(self, owner, sim, x, y, out):
super().__init__(owner, sim, x, y)
self.out = out
......@@ -186,19 +186,19 @@ cdef class ComplexCameraValues(BaseCValues):
self.setup(params, sizeof(ptr), <double**>&ptr)
cdef class ComplexCameraWorkspace(CameraWorkspace):
def __init__(self, owner, sims, x, y):
super().__init__(owner, sims, x, y, ComplexCameraValues())
def __init__(self, owner, sim, x, y):
super().__init__(owner, sim, x, y, ComplexCameraValues())
self.v = <ComplexCameraValues>self.values
cdef class FieldCameraWorkspace(ComplexCameraWorkspace):
def __init__(self, owner, sims, x, y, out):
super().__init__(owner, sims, x, y)
def __init__(self, owner, sim, x, y, out):
super().__init__(owner, sim, x, y)
self.out = out
cdef class FieldLineWorkspace(ComplexCameraWorkspace):
def __init__(self, owner, sims, x, y, out):
super().__init__(owner, sims, x, y)
def __init__(self, owner, sim, x, y, out):
super().__init__(owner, sim, x, y)
self.out = out
......
......@@ -51,9 +51,6 @@ cdef class PD0Workspace(MaskedDetectorWorkspace):
Py_ssize_t rhs_index
Py_ssize_t size
def __init__(self, owner, sims):
super().__init__(owner, sims)
pd0_DC_output = OutputFuncWrapper.make_from_ptr(c_pd0_DC_output)
cdef c_pd0_DC_output(DetectorWorkspace dws):
......@@ -120,8 +117,8 @@ cdef class PD1Workspace(MaskedDetectorWorkspace):
self.pre_set_beats[0] = NULL
self.pre_set_beats[1] = NULL
def __init__(self, owner, sims):
super().__init__(owner, sims, PD1Values())
def __init__(self, owner, sim):
super().__init__(owner, sim, PD1Values())
self.v = <PD1Values>self.values
cpdef update_beats(self):
......@@ -294,8 +291,8 @@ cdef class PD2Workspace(MaskedDetectorWorkspace):
complex_t z2
PD2Values v
def __init__(self, owner, sims):
super().__init__(owner, sims, PD2Values())
def __init__(self, owner, sim):
super().__init__(owner, sim, PD2Values())
self.v = <PD2Values>self.values
pd2_DC_output = OutputFuncWrapper.make_from_ptr(c_pd2_DC_output)
......
......@@ -111,6 +111,6 @@ class Gouy(Detector):
path = self._model.path(self.__from_node, self.__to_node, self.__via_node)
self.__spaces = list(path.spaces)
def _get_workspace(self, sims):
ws = GouyDetectorWorkspace(self, sims)
def _get_workspace(self, sim):
ws = GouyDetectorWorkspace(self, sim)
return ws
......@@ -45,14 +45,14 @@ class KnmDetector(Detector):
if any(k < 0 for k in (self.n1, self.m1, self.n2, self.m2)):
raise ValueError("Mode indices cannot be negative.")
def _get_workspace(self, sims):
ws = KnmDetectorWorkspace(self, sims)
def _get_workspace(self, sim):
ws = KnmDetectorWorkspace(self, sim)
ws.n1 = self.n1
ws.m1 = self.m1
ws.n2 = self.n2
ws.m2 = self.m2
comp_ws = list(filter(lambda x: x.owner == self.__comp, sims[0].workspaces))
comp_ws = list(filter(lambda x: x.owner == self.__comp, sim.workspaces))
if not comp_ws:
raise RuntimeError(
f"Could not find {self.__comp.name} in simulation workspace"
......
......@@ -13,8 +13,8 @@ LOGGER = logging.getLogger(__name__)
class MotionDetectorWorkspace(DetectorWorkspace):
def __init__(self, owner, sims):
super().__init__(owner, sims)
def __init__(self, owner, sim):
super().__init__(owner, sim)
class MotionDetector(Detector):
......
......@@ -36,13 +36,8 @@ class KLUStatsDetector(Detector):
if stat.lower() not in ('rcond', 'growth', 'condest'):
raise Exception("Matrix setting must be either 'rcond', 'growth', or 'condest'")
def _get_workspace(self, sims):
ws = KLUStatWorkspace(self, sims)
for sim in sims:
if self.matrix == sim.name:
ws.sim = sim
break
def _get_workspace(self, sim):
ws = KLUStatWorkspace(self, sim)
ws.fn = getattr(sim, self.stat)
ws.set_output_fn(self.fill)
return ws
......
......@@ -770,10 +770,10 @@ cdef class CarrierSignalMatrixSimulation:
self.setup_detector_workspaces()
def unbuild(self):
pass
#self._unbuild()
#self._clear_workspace()
self._submatrices = None
# Code below can be used in debug mode to determine if anyone is keeping any
# references to this matrix object, meaning its memory can't be freed.
# This takes ~20ms to do so makes a difference for quick models. Maybe we need
......
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