Reports until 15:33, Tuesday 21 January 2025
H1 ISC (CAL, ISC)
jeffrey.kissel@LIGO.ORG - posted 15:33, Tuesday 21 January 2025 - last comment - 14:01, Thursday 30 January 2025(82387)
Creating DARM Loop Critique via pydarm on the Control Room Machines
Here're the bare-bones instructions to run the DARM loop critique -- an automated set of plots that were inspired by the presentations given over the years that compare the transfer functions of the DARM loop between the two sites, e.g. G1501372, G1700316, G2000149.

(0) Conda activate the latest pydarm environment.
    ~$ conda activate /ligo/groups/cal/conda/pydarm
This is a symbolic link to the latest tagged version of pydarm.
    () ~$ which pydarm
        /ligo/groups/cal/conda/pydarm/bin/pydarm
    () ~$ pydarm --version
        20240821.0
    () ~$ ipython
    In [1]: import pydarm
    In [2]: pydarm.__version__
    Out [2]: '20240821.0' 
Note the version of pydarm is the same on the command line and within the ipython session *because* we activated the correct pydarm conda environment. The command line pydarm internally activates this environment automatically, but any old ipython session may not have the right version of pydarm if you just import "from scratch" without making sure you're in the right environment first. So -- any time you're running script or python session pyDARM these days -- make sure that you've activated the conda environment.

Is this the right version? check https://git.ligo.org/Calibration/pydarm/-/tags see if that version is the latest, i.e. the top of the list.

It is. And this will *always* be true, by process of deploying the latest tag (see deploy script).
To compare previous versions of tags, go to https://git.ligo.org/Calibration/pydarm/-/compare?from=master&to=master and change the drop-down menu to compare one tag to the other.
If you want to activate an environment with an older version of pydarm, then head to the folder /ligo/groups/cal/conda/ and activate the environment you like.


(1) Grab the DARM loop model parameter sets that you want to plot and/or compare. If at LHO, wanting H1 parameter files, then (back out on the command line, not in yet in a python session)
Find the list of reports and tags:
   () ~$ pydarm ls -r
From that list, find the model parameters installed in the front-end:
   () ~$ pydarm ls -r | exported

Once you find what you like, go into that report directory, e.g.
   () ~$ cd /ligo/groups/cal/H1/reports/20240927T211612Z
Look for pydarm_H1.ini, and copy it somewhere you like, or at least store where it lives.

If you're at LHO, want L1 parameter files, then the easiest thing is to download it from the web. Head to the https://ldas-jobs.ligo-la.caltech.edu/~cal/ and scroll down to the list of all reports, and find the entry that's been exported most recently e.g. 20240408T200652Z, and download the pydarm_L1.ini and save it to a known location.

(2) Start critiquing:
~$ ipython
In [1]: from pydarm.darm import DARMModel

In [2]: d = DARMModel('/ligo/groups/cal/H1/reports/20240927T211612Z/pydarm_H1.ini')

# Plot a single parameter file's model:
In [3]: d.plot(filename='/ligo/home/jeffrey.kissel/2025-01-21/20240927T211612Z_pydarm_H1_critique.pdf',label=['H1'])

# Compare against another, say, previous version of the model
d_prenewdarm = DARMModel('/ligo/groups/cal/H1/reports/20231027T203619Z/pydarm_H1.ini')

from pydarm.plot import critique

critique(d,d_prenewdarm,filename='/ligo/home/jeffrey.kissel/2025-01-21/20240927T211612Z_vs_20231027T203619Z_pydarm_H1_critique.pdf',label=['H1 20240927T211612Z', 'H1 20231027T203619Z'])

# Compare two IFOs:
In [9]: d_H1 = DARMModel('/ligo/groups/cal/H1/reports/20240927T211612Z/pydarm_H1.ini')

In [10]: d_L1 = DARMModel('/ligo/home/jeffrey.kissel/2025-01-21/20240408T200652Z_pydarm_L1.ini')

critique(d_H1,d_L1,filename='/ligo/home/jeffrey.kissel/2025-01-21/20240927T211612Z_H1_vs_20240408T200652Z_L1_critique.pdf',label=['H1 20240927T211612Z','L1 20240408T200652Z'])

# Compare one IFO's parameters, while updating one of the parameters on the fly
In [9]: d_H1 = DARMModel('/ligo/groups/cal/H1/reports/20240927T211612Z/pydarm_H1.ini')
In [10]: d_H1_moreAA = DARMModel('/ligo/groups/cal/H1/reports/20240927T211612Z/pydarm_H1.ini') #Intentionally the same
# Update the parameter you want,
In [6]: d_H1_moreAA.sensing.omc_filter_noncompensating_modules
Out[6]: [[9, 10], [9, 10]]

In [7]: d_H1_moreAA.sensing.omc_filter_noncompensating_modules = [[9,10,10],[9,10,10]]

In [8]: critique(d_H1,d_H1_moreAA,filename='/ligo/home/jeffrey.kissel/2025-01-21/20240927T211612Z_H1_vs_20240927T211612Z_H1_2x16kDigitalAA_critique.pdf',label=['Nominal','1x More 16k AA'])

Non-image files attached to this report
Comments related to this report
jeffrey.kissel@LIGO.ORG - 10:35, Thursday 30 January 2025 (82550)CAL
For the record, this DARM model object, "d" mentioned above literally contains everything about the DARM loop. 

So if you want parts of the DARM loop, then you can ask for things like
    $ conda activate /ligo/groups/cal/conda/pydarm
    $ ipython

    : import pydarm
    : pydarm.__version__
         '20240821.0'
    : from pydarm.darm import DARMModel   
    : d = DARMModel('/ligo/groups/cal/H1/reports/20240927T211612Z/pydarm_H1.ini') 
    : import numpy as np
    : freq = np.logspace(1,6,2500)
    : G = d.compute_darm_olg(freq)              # Open Loop Gain == G = A*C*D
    : R = d.compute_response_function(freq)     # Response Function == (1+G)/C = (1/C) + D*[A_T + A_P + A_U]
    : C = d.sensing.compute_sensing(freq)       # Sensing Function, C
    : D = d.digital.compute_response(freq)      # DARM filter bank, D
    : A = d.actuation.compute_actuation(freq)   # Total super actuator, A

And if you need more compartmentalized transfer functions, you can explore the methods available in
darm.py (for things like the overall loop shape)
sensing.py (for detailed components of the sensing function)
actuation.py (for detailed components of the actuation function)
jameson.rollins@LIGO.ORG - 14:01, Thursday 30 January 2025 (82554)

Fwiw the "pydarm model" command on the command line will also produce frequency response plots of these DARM model transfer functions.