test_solver_ADY_paper

test.ASC_SOLVER_PAPER.test_solver_ADY_paper

This is a pytest module needing documentation

pytest-html report

Functions

T_calc_H2(folder)

This is a pytest needing documentation

T_calc_HiB(folder)

This is a pytest needing documentation

T_plot_H2(folder[, dfile])

Test that runs the plotting code for H2.

T_plot_HiB(folder[, dfile])

This is a pytest needing documentation

get_systemB([folder])

This is a pytest needing documentation

Details

T_calc_H2(folder)[source]

This is a pytest needing documentation

code
 1@pytest.mark.parametrize(
 2    'folder',
 3    [
 4        'ExampleModels_paper'
 5    ]
 6)
 7def T_calc_H2(folder):
 8    sysB = get_systemB(folder = folder)
 9    io_scales = file_io.load(fjoin(folder, 'io_scales.yml')) # Saved by the normalization in the make function
10
11    if '_F3' in folder:
12        FOM_out = ["F3.out", "F2.out"]
13    else:
14        FOM_out = ["FBNS.out", "F2.out"]
15    wn_in = ["S.in", "O.in"]
16    control_in = ["U.in"]
17    meas_out = ["T.out"]
18
19    # currently NO-OP and could be removed
20    sysB.sys = ssutil.scale_io(sysB.sys, FOM_out[0], FBNS_scale)
21    sysB.sys = ssutil.scale_io(sysB.sys, FOM_out[1], FFlat_scale)
22
23    # Scale the DARM output
24    if 'DARM.out' in sysB.sys.outputs.keys():
25        print('scaling DARM')
26        DARM_scale_factor = strain2m * SNR_intg_factor
27        sysB.sys = ssutil.scale_io(sysB.sys, 'DARM.out', DARM_scale_factor)
28
29    params = {}
30    if folder == 'ExampleModels':
31        params["F1_gain"] = np.geomspace(1e-0, 1e6, 30) * 1/FBNS_scale
32    elif folder == 'ExampleModels_newFOM_F3':
33        params["F1_gain"] = np.geomspace(1e-0, 1e6, 30) * 1/FBNS_scale
34    elif folder == 'ExampleModels_paper':
35        params["F1_gain"] = np.geomspace(1e2, 1e4, 30) * 1/FBNS_scale
36    else:
37        params["F1_gain"] = np.geomspace(1e2, 1e6, 15) * 1/FBNS_scale
38        #params["F1_gain"] = np.geomspace(1e2, 5e7, 30) * 1/FBNS_scale
39
40    results_H2_bare = compute.calcOpt(
41        sysB.sys,
42        control_in,
43        wn_in,
44        meas_out,
45        FOM_out,
46        params,
47        solver="LQG",
48        plant_orig=sysB.orig_plant,
49    )
50
51    print("Length of H2 results: ", len(results_H2_bare))
52
53
54    plotting_omega = np.logspace(-3, 4, 1000) * 2 * np.pi
55    results_H2 = compute.calcFullResults(
56        results_H2_bare,
57        colormap="jet",
58        plot_omega=plotting_omega,
59        io_scales = io_scales,
60    )
61
62    ofile = "results_H2_ADY.pkl"
63    tfile = tjoin(ofile)
64    buzzutil.save_results(results_H2, tfile)
65
66    ffile = fjoin(folder, ofile)
67    buzzutil.save_results(results_H2, ffile)
68
69    # copy to the data directory if it is missing
70    dfile = fjoin(folder, ofile)
71
72    # should not copy into rootdir, especially for parametrized test
73    # should this be for ffile?
74    # if not os.path.exists(ofile):
75    #     import shutil
76    #     shutil.copy(tfile, ofile) 
77
78    print("Now running plot test")
79    T_plot_H2(folder=folder, dfile=tfile)
pytest information

This code is wrapped in a pytest function using conventions detailed in pytest_conventions. The full name of this test, as known by the documentation, is:

test.ASC_SOLVER_PAPER.test_solver_ADY_paper.T_calc_H2

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

T_calc_H2[ExampleModels_paper]
output
status: failed
duration: 0.012s
captured errors:
folder = 'ExampleModels_paper'

    @pytest.mark.parametrize(
        'folder',
        [
            'ExampleModels_paper'
        ]
    )
    def T_calc_H2(folder):
        sysB = get_systemB(folder = folder)
>       io_scales = file_io.load(fjoin(folder, 'io_scales.yml')) # Saved by the normalization in the make function

/builds/buzz/test/ASC_SOLVER_PAPER/test_solver_ADY_paper.py:76: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/wield/wield-utilities/src/wield/utilities/file_io/__init__.py:48: in load
    return load_any(
/wield/wield-utilities/src/wield/utilities/file_io/any_io.py:47: in load_any
    fdict = yaml_io.yaml_load(fname)
/wield/wield-utilities/src/wield/utilities/file_io/yaml_io.py:43: in yaml_load
    fdict = yaml.load(F, Loader=yaml_loader)
/opt/conda/lib/python3.12/site-packages/yaml/__init__.py:81: in load
    return loader.get_single_data()
/opt/conda/lib/python3.12/site-packages/yaml/constructor.py:49: in get_single_data
    node = self.get_single_node()
/opt/conda/lib/python3.12/site-packages/yaml/composer.py:36: in get_single_node
    document = self.compose_document()
/opt/conda/lib/python3.12/site-packages/yaml/composer.py:58: in compose_document
    self.get_event()
/opt/conda/lib/python3.12/site-packages/yaml/parser.py:118: in get_event
    self.current_event = self.state()
/opt/conda/lib/python3.12/site-packages/yaml/parser.py:193: in parse_document_end
    token = self.peek_token()
/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:129: in peek_token
    self.fetch_more_tokens()
/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:223: in fetch_more_tokens
    return self.fetch_value()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <yaml.loader.SafeLoader object at 0x7f49c3bd3ec0>

    def fetch_value(self):

        # Do we determine a simple key?
        if self.flow_level in self.possible_simple_keys:

            # Add KEY.
            key = self.possible_simple_keys[self.flow_level]
            del self.possible_simple_keys[self.flow_level]
            self.tokens.insert(key.token_number-self.tokens_taken,
                    KeyToken(key.mark, key.mark))

            # If this key starts a new block mapping, we need to add
            # BLOCK-MAPPING-START.
            if not self.flow_level:
                if self.add_indent(key.column):
                    self.tokens.insert(key.token_number-self.tokens_taken,
                            BlockMappingStartToken(key.mark, key.mark))

            # There cannot be two simple keys one after another.
            self.allow_simple_key = False

        # It must be a part of a complex key.
        else:

            # Block context needs additional checks.
            # (Do we really need them? They will be caught by the parser
            # anyway.)
            if not self.flow_level:

                # We are allowed to start a complex value if and only if
                # we can start a simple key.
                if not self.allow_simple_key:
>                   raise ScannerError(None, None,
                            "mapping values are not allowed here",
                            self.get_mark())
E                   yaml.scanner.ScannerError: mapping values are not allowed here
E                     in "/builds/buzz/test/ASC_SOLVER_PAPER/ExampleModels_paper/io_scales.yml", line 2, column 6

/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:577: ScannerError
T_calc_HiB(folder)[source]

This is a pytest needing documentation

code
 1@pytest.mark.parametrize(
 2    'folder',
 3    [
 4        'ExampleModels_paper'
 5    ]
 6)
 7def T_calc_HiB(folder):
 8    sysB = get_systemB(folder = folder)
 9    io_scales = file_io.load(fjoin(folder, 'io_scales.yml')) # Saved by the normalization in the make function
10
11    if '_F3' in folder:
12        FOM_out = ["F3.out", "F2.out"]
13    else:
14        FOM_out = ["FBNS.out", "F2.out"]
15    wn_in = ["S.in", "O.in"]
16    Zinf = ["Zinf.in"]
17    control_in = ["U.in"]
18    meas_out = ["T.out"]
19
20    sysB.sys = ssutil.scale_io(sysB.sys, FOM_out[0], FBNS_scale)
21    sysB.sys = ssutil.scale_io(sysB.sys, FOM_out[1], FFlat_scale)
22
23    # Scale the DARM output
24    if 'DARM.out' in sysB.sys.outputs.keys():
25        print('scaling DARM')
26        DARM_scale_factor = strain2m * SNR_intg_factor
27        sysB.sys = ssutil.scale_io(sysB.sys, 'DARM.out', DARM_scale_factor)
28
29    params = {}
30    if folder == 'ExampleModels':
31        params['F1_gain'] = np.geomspace(1e1, 1e5, 5) * 1/FBNS_scale # was 1e1 3e3
32    # elif folder == 'ExampleModels_newFOM_F3':
33    #     params['F1_gain'] = np.geomspace(1e-6, 1e-3, 5) * 1/FBNS_scale
34    else:
35        params["F1_gain"] = np.geomspace(4e1, 1e5, 6) * 1/FBNS_scale
36        #params["F1_gain"] = np.array([0.09146101038546522])
37
38    params["igsq_capture"] = [
39        1e-4,  # gain-100 limit
40        1.8e-2,  # 1 deg, around gain-10
41        1e-1,  # 6 deg
42        0.20,  # 11.5 deg
43        0.3,  # 17 deg
44        0.5,  # 30 deg
45        0.7653668647301797,  # 45 deg
46        0.85,  # 50.0 deg
47        0.90,  # 53.5 deg
48        0.95,  # 56.5 deg
49        # above this it gets very hairy
50        # these are 10 solutions
51    ]
52
53    # params["igsq_capture"] = np.geomspace(1e-6, 0.99, 40)
54    # params["igsq_capture"] = np.concatenate([np.geomspace(1e-6, 0.1, 6), np.geomspace(.1, 0.95, 6)])
55
56    plotting_omega = np.logspace(-3, 4, 1000) * 2 * np.pi
57    results_Hib_bare = compute.calcOpt(
58        sysB.sys,
59        control_in,
60        wn_in,
61        meas_out,
62        FOM_out,
63        params,
64        Zinf=Zinf,
65        solver="HB",
66        plant_orig=sysB.orig_plant,
67        BH_solver = BH1solverset,
68        debug_mode=True,
69    )
70
71    print("Calculating Full Results Now:")
72    results_Hib = compute.calcFullResults(
73        results_Hib_bare,
74        colormap="RdYlGn",
75        plot_omega=plotting_omega,
76        color_param="igsq",
77        label=False,
78        io_scales = io_scales,
79    )
80
81    ofile = "results_Hib_ADY.pkl"
82    tfile = tjoin(ofile)
83    buzzutil.save_results(results_Hib, tfile)
84
85    ffile = fjoin(folder, ofile)
86    buzzutil.save_results(results_Hib, ffile)
87
88    # TODO, should also check if the data is identical and warn that it should be copied
89    # copy to the data directory if it is missing
90    dfile = fjoin(folder, ofile)
91    # should not save into the root folder for parametrized test - Lee
92    # if not os.path.exists(ofile):
93    #     import shutil
94    #     shutil.copy(tfile, ofile) 
95
96    print("Now running plot test")
97    T_plot_HiB(folder=folder, dfile=tfile)
pytest information

This code is wrapped in a pytest function using conventions detailed in pytest_conventions. The full name of this test, as known by the documentation, is:

test.ASC_SOLVER_PAPER.test_solver_ADY_paper.T_calc_HiB

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

T_calc_HiB[ExampleModels_paper]
output
status: failed
duration: 0.005s
captured errors:
folder = 'ExampleModels_paper'

    @pytest.mark.parametrize(
        'folder',
        [
            'ExampleModels_paper'
        ]
    )
    def T_calc_HiB(folder):
        sysB = get_systemB(folder = folder)
>       io_scales = file_io.load(fjoin(folder, 'io_scales.yml')) # Saved by the normalization in the make function

/builds/buzz/test/ASC_SOLVER_PAPER/test_solver_ADY_paper.py:368: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/wield/wield-utilities/src/wield/utilities/file_io/__init__.py:48: in load
    return load_any(
/wield/wield-utilities/src/wield/utilities/file_io/any_io.py:47: in load_any
    fdict = yaml_io.yaml_load(fname)
/wield/wield-utilities/src/wield/utilities/file_io/yaml_io.py:43: in yaml_load
    fdict = yaml.load(F, Loader=yaml_loader)
/opt/conda/lib/python3.12/site-packages/yaml/__init__.py:81: in load
    return loader.get_single_data()
/opt/conda/lib/python3.12/site-packages/yaml/constructor.py:49: in get_single_data
    node = self.get_single_node()
/opt/conda/lib/python3.12/site-packages/yaml/composer.py:36: in get_single_node
    document = self.compose_document()
/opt/conda/lib/python3.12/site-packages/yaml/composer.py:58: in compose_document
    self.get_event()
/opt/conda/lib/python3.12/site-packages/yaml/parser.py:118: in get_event
    self.current_event = self.state()
/opt/conda/lib/python3.12/site-packages/yaml/parser.py:193: in parse_document_end
    token = self.peek_token()
/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:129: in peek_token
    self.fetch_more_tokens()
/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:223: in fetch_more_tokens
    return self.fetch_value()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <yaml.loader.SafeLoader object at 0x7f49bba21a30>

    def fetch_value(self):

        # Do we determine a simple key?
        if self.flow_level in self.possible_simple_keys:

            # Add KEY.
            key = self.possible_simple_keys[self.flow_level]
            del self.possible_simple_keys[self.flow_level]
            self.tokens.insert(key.token_number-self.tokens_taken,
                    KeyToken(key.mark, key.mark))

            # If this key starts a new block mapping, we need to add
            # BLOCK-MAPPING-START.
            if not self.flow_level:
                if self.add_indent(key.column):
                    self.tokens.insert(key.token_number-self.tokens_taken,
                            BlockMappingStartToken(key.mark, key.mark))

            # There cannot be two simple keys one after another.
            self.allow_simple_key = False

        # It must be a part of a complex key.
        else:

            # Block context needs additional checks.
            # (Do we really need them? They will be caught by the parser
            # anyway.)
            if not self.flow_level:

                # We are allowed to start a complex value if and only if
                # we can start a simple key.
                if not self.allow_simple_key:
>                   raise ScannerError(None, None,
                            "mapping values are not allowed here",
                            self.get_mark())
E                   yaml.scanner.ScannerError: mapping values are not allowed here
E                     in "/builds/buzz/test/ASC_SOLVER_PAPER/ExampleModels_paper/io_scales.yml", line 2, column 6

/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:577: ScannerError
T_plot_H2(folder, dfile=None)[source]

Test that runs the plotting code for H2. This test can be run from another test

code
docstring
"""
Test that runs the plotting code for H2. This test can be run from another test
"""
  1@pytest.mark.parametrize(
  2    'folder', [
  3        'ExampleModels_paper'
  4    ]
  5)
  6def T_plot_H2(folder, dfile = None):
  7
  8
  9    if folder is None:
 10        folder = "ExampleModels"
 11
 12    io_scales = file_io.load(fjoin(folder, 'io_scales.yml')) # Saved by the normalization in the make function
 13    sysB = get_systemB(folder=folder)
 14
 15    if dfile is None:
 16        ofile = "results_H2_ADY.pkl"
 17        dfile = fjoin(folder, ofile)
 18    print('dfile: ', dfile)
 19    H2_results = buzzutil.load_results(dfile)
 20
 21    print('len H2_results: ', len(H2_results))
 22
 23    # add a gamma value to the results for plotting
 24    for point in H2_results:
 25        if point["gamma"] == None:
 26            point["gamma"] = np.inf
 27
 28    # Remove the labels from the results
 29    for datadict in H2_results:
 30        datadict["label1"] = None
 31        datadict["label2"] = None
 32
 33    # Adding the current controller to the plot
 34    module_gain = -40 # this is the gain of the filter module
 35    filter_list = np.array([1, 3, 4, 5, 6]) # this is a list of the filters in the module that are on
 36
 37    zpksys, filtinfo = readFilter.readFilterSys_Scipy(
 38        fjoin("H1ASC.txt"), "ASC_DHARD_Y", np.array(filter_list)
 39    )
 40
 41    z, p, k = FilteringUtils.d2c(
 42        (zpksys.zeros, zpksys.poles, zpksys.gain), fs=1 / zpksys.dt
 43    )
 44
 45    k = k.real * module_gain
 46    K_mod = SISO.zpk(z, p, k, angular=True, fiducial_rtol=1e-5, fiducial_atol=1e-10).asSS
 47    K_iod = {"C.in": 0, "C.out": 0}
 48    K = wieldSS(K_mod, K_iod)
 49
 50    axB = ssutil.bode(ssutil.asSISO(K)*sysB.orig_plant.siso("P.out", "P.in"), label="K_hand * orig_plant Controller")
 51    axC = ssutil.bode(K, label="K_hand")
 52
 53    K = (ssutil.asSISO(K) * sysB.sys["S.out", "SA.in"]).mimo(
 54        "C.out", "C.in"
 55    ) # Add in the part of P that was moved to env. noise block
 56    K = ssutil.balance_sys_gain(K)
 57
 58    axB = ssutil.bode(-1*ssutil.asSISO(K)*H2_results[0]['plant'].siso("P.out", "P.in"), axB =axB, label="K_hand * S_anex * P")
 59    axB = ssutil.bode(H2_results[1]['K'].siso("C.out", "C.in")*H2_results[1]['plant'].siso("P.out", "P.in"), axB =axB, label="K_H2[-15] * P")
 60    axB.save(tjoin("bode_KP.pdf"))
 61    axB.save(tjoin("bode_KP.png"))
 62
 63    axC = ssutil.bode(H2_results[1]['K_usable'], axB =axC, label="K_useable")
 64    axB = ssutil.bode(ssutil.asSISO(H2_results[1]['K'])*sysB.sys.siso("S.out", "SA.in")**(-1), axB =axC, label="K / S_anex")
 65    axC.save(tjoin("bode_K.pdf"))
 66    axC.save(tjoin("bode_K.png"))
 67
 68    curdict = H2_results[0].copy()
 69    curdict["Ac"] = K.A
 70    curdict["Bc"] = K.B
 71    curdict["Cc"] = K.C
 72    curdict["Dc"] = K.D
 73    curdict["K"] = K
 74    curdict["label"] = "Hand Tuned Controller"
 75
 76    extraplots = compute.calcFullResults(
 77        [curdict], 
 78        color="dimgrey", 
 79        label="Hand Tuned Controller", 
 80        plot_omega=curdict["plot_omega"],
 81        io_scales = io_scales,
 82    )
 83    extraplots[0]["F1_gain"] = sum(buzzutil.listparams(H2_results, "F1_gain"))
 84    extraplots[0]["linecolor"] = "Black"  #'DodgerBlue'
 85    extraplots[0]["linestyle"] = "--"
 86    extraplots[0]["solver"] = "Hand Tuned"
 87    extraplots[0]["rms_marker"] = "^"
 88
 89    f_Hz_range = extraplots[0]['FOM1_wn_ASD_Hz']
 90    budget_range = gwinc.load_budget('aLIGO', freq=f_Hz_range)
 91    trace_range = budget_range.run(freq=f_Hz_range)
 92
 93    plt.loglog(f_Hz_range, extraplots[0]['FOM1_wn_ASD']*4000, label='white noise to darm out with hand tuned controller')
 94    plt.loglog(f_Hz_range, trace_range.psd**0.5*4000, label='aLIGO')
 95    plt.legend()
 96    plt.xlabel('Frequency [Hz]')
 97    plt.ylabel('ASD [m/rtHz]')
 98    plt.xlim([6, 6e2])
 99    plt.ylim([4e-21, 3e-17])
100    plt.savefig(tjoin('DARM_spec.png'), bbox_inches='tight')
101    plt.savefig(tjoin('DARM_spec.pdf'), bbox_inches='tight')
102    plt.close()
103
104    H2_results_E = H2_results + extraplots
105
106    every_nth = 1  # removes every nth element
107    H2_results_E_short = H2_results[every_nth - 1:: every_nth] + extraplots
108
109    setname_H2 = "ADY_H2"
110    fig_rms_H2 = plotting.plotRMS(
111        H2_results_E_short,
112        setname=setname_H2,
113        outlineparam="pm",
114        text="pm",
115        f1line=False,
116        h2line=False,
117        plotrange=False,
118        test=True,
119    )
120    fig_rms_H2[0].savefig(tjoin("rms_H2.pdf"), bbox_inches="tight")
121    fig_rms_H2[0].savefig(tjoin("rms_H2.png"), bbox_inches="tight")
122
123    fig_rms_H2_range_PSD = plotting.plotRMS(
124        H2_results_E_short,
125        setname=setname_H2,
126        outlineparam="pm",
127        text="pm",
128        f1line=False,
129        h2line=False,
130        plotrange='PSD',
131        test=True,
132    )
133    fig_rms_H2_range_PSD[0].savefig(tjoin("rms_H2_range_PSD.pdf"), bbox_inches="tight")
134    fig_rms_H2_range_PSD[0].savefig(tjoin("rms_H2_range_PSD.png"), bbox_inches="tight")
135
136
137    print('Plotting RMS Plot with lost range')
138    fig_rms_lost_range_H2 = plotting.plotRMS(
139        H2_results_E,
140        setname=setname_H2,
141        outlineparam='pm',
142        text='pm',
143        f1line=True,
144        h2line=True,
145        plotrange='diff',
146        test=True,
147        #xlim=xlim,
148        #ylim=ylim
149    )
150    fig_rms_lost_range_H2[0].savefig(tjoin("rms_H2_lost_range.pdf"), bbox_inches="tight")
151    fig_rms_lost_range_H2[0].savefig(tjoin("rms_H2_lost_range.png"), bbox_inches="tight")
152
153    print('Plotting RMS Plot with lost range (PSD computation)')
154    fig_rms_lost_range_H2_psd = plotting.plotRMS(
155        H2_results_E,
156        setname=setname_H2,
157        outlineparam='pm',
158        text='pm',
159        f1line=True,
160        h2line=True,
161        plotrange='diff_psd',
162        test=True,
163        #xlim=xlim,
164        #ylim=ylim
165    )
166    fig_rms_lost_range_H2_psd[0].savefig(tjoin("rms_H2_lost_range_PSD.pdf"), bbox_inches="tight")
167    fig_rms_lost_range_H2_psd[0].savefig(tjoin("rms_H2_lost_range_PSD.png"), bbox_inches="tight")
168
169
170    ylim = [1e-4, 1e8]
171    fig_ol_H2, ax = plotting.plotLoop(H2_results_E_short, "OL", setname=setname_H2, ylim=ylim, UG_line=True, test=True)
172    fig_ol_H2.savefig(tjoin("ol_H2.pdf"), bbox_inches="tight")
173    fig_ol_H2.savefig(tjoin("ol_H2.png"), bbox_inches="tight")
174
175    fig_cl_H2, ax = plotting.plotLoop(H2_results_E_short, "CL", setname=setname_H2, UG_line=True, test=True)
176    fig_cl_H2.savefig(tjoin("cl_H2.pdf"), bbox_inches="tight")
177    fig_cl_H2.savefig(tjoin("cl_H2.png"), bbox_inches="tight")
178
179    noise_plot_fig, noise_plot_axs = plotting.plot_CLnoises(H2_results_E_short[0], test=True)
180    noise_plot_fig.savefig(tjoin("noise_H2.pdf"), bbox_inches="tight")
181    noise_plot_fig.savefig(tjoin("noise_H2.png"), bbox_inches="tight")
182
183    fig_darm_H2, ax = plotting.plotDARM(H2_results_E_short, setname=setname_H2, test=True)
184    fig_darm_H2.savefig(tjoin("All_DARM_Spec.pdf"), bbox_inches="tight")
185    fig_darm_H2.savefig(tjoin("All_DARM_Spec.png"), bbox_inches="tight")
186
187    setname_vega = 'ASC_vega'
188    vega_chart = plotting.vega_plot(H2_results_E, setname=setname_vega, h2line=False, size=500, plotrange=False, test=True)
189    vega_chart.save(tjoin("vega_results_plot.html"))
190
191    if 'FBNS.DARM.out' in extraplots[0]['CL_all_io'].iod:
192        DARM_out_name = 'FBNS.DARM.out'
193        darm_in_mod = True
194    elif 'F3.DARM.out' in extraplots[0]['CL_all_io'].iod:
195        DARM_out_name = 'F3.DARM.out'
196        darm_in_mod = True
197    else:
198        DARM_out_name = None
199
200    if DARM_out_name:
201        DARM_plot_omega = np.logspace(-2, 3, 1000) * 2 * np.pi
202        DARM_noise_plot_fig, DARM_noise_plot_axs = plotting.plot_CLnoises(extraplots[0], extra_fom=DARM_out_name, extra_only=True, plot_omega=DARM_plot_omega, test=True, scale=1/io_scales.w2_rescale)
203        DARM_noise_plot_fig.savefig(tjoin("DARM_noise_H2.pdf"), bbox_inches="tight")
204        DARM_noise_plot_fig.savefig(tjoin("DARM_noise_H2.png"), bbox_inches="tight")
205    else:
206        print('DARM not in outputs. Not plotting DARM noise')
207        print(extraplots[0]['CL_all_io'].outputs)
pytest information

This code is wrapped in a pytest function using conventions detailed in pytest_conventions. The full name of this test, as known by the documentation, is:

test.ASC_SOLVER_PAPER.test_solver_ADY_paper.T_plot_H2

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

T_plot_H2[ExampleModels_paper]
output
status: failed
duration: 0.001s
captured errors:
folder = 'ExampleModels_paper', dfile = None

    @pytest.mark.parametrize(
        'folder', [
            'ExampleModels_paper'
        ]
    )
    def T_plot_H2(folder, dfile = None):
        """
        Test that runs the plotting code for H2. This test can be run from another test
        """

        if folder is None:
            folder = "ExampleModels"

>       io_scales = file_io.load(fjoin(folder, 'io_scales.yml')) # Saved by the normalization in the make function

/builds/buzz/test/ASC_SOLVER_PAPER/test_solver_ADY_paper.py:162: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/wield/wield-utilities/src/wield/utilities/file_io/__init__.py:48: in load
    return load_any(
/wield/wield-utilities/src/wield/utilities/file_io/any_io.py:47: in load_any
    fdict = yaml_io.yaml_load(fname)
/wield/wield-utilities/src/wield/utilities/file_io/yaml_io.py:43: in yaml_load
    fdict = yaml.load(F, Loader=yaml_loader)
/opt/conda/lib/python3.12/site-packages/yaml/__init__.py:81: in load
    return loader.get_single_data()
/opt/conda/lib/python3.12/site-packages/yaml/constructor.py:49: in get_single_data
    node = self.get_single_node()
/opt/conda/lib/python3.12/site-packages/yaml/composer.py:36: in get_single_node
    document = self.compose_document()
/opt/conda/lib/python3.12/site-packages/yaml/composer.py:58: in compose_document
    self.get_event()
/opt/conda/lib/python3.12/site-packages/yaml/parser.py:118: in get_event
    self.current_event = self.state()
/opt/conda/lib/python3.12/site-packages/yaml/parser.py:193: in parse_document_end
    token = self.peek_token()
/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:129: in peek_token
    self.fetch_more_tokens()
/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:223: in fetch_more_tokens
    return self.fetch_value()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <yaml.loader.SafeLoader object at 0x7f49c3bf9310>

    def fetch_value(self):

        # Do we determine a simple key?
        if self.flow_level in self.possible_simple_keys:

            # Add KEY.
            key = self.possible_simple_keys[self.flow_level]
            del self.possible_simple_keys[self.flow_level]
            self.tokens.insert(key.token_number-self.tokens_taken,
                    KeyToken(key.mark, key.mark))

            # If this key starts a new block mapping, we need to add
            # BLOCK-MAPPING-START.
            if not self.flow_level:
                if self.add_indent(key.column):
                    self.tokens.insert(key.token_number-self.tokens_taken,
                            BlockMappingStartToken(key.mark, key.mark))

            # There cannot be two simple keys one after another.
            self.allow_simple_key = False

        # It must be a part of a complex key.
        else:

            # Block context needs additional checks.
            # (Do we really need them? They will be caught by the parser
            # anyway.)
            if not self.flow_level:

                # We are allowed to start a complex value if and only if
                # we can start a simple key.
                if not self.allow_simple_key:
>                   raise ScannerError(None, None,
                            "mapping values are not allowed here",
                            self.get_mark())
E                   yaml.scanner.ScannerError: mapping values are not allowed here
E                     in "/builds/buzz/test/ASC_SOLVER_PAPER/ExampleModels_paper/io_scales.yml", line 2, column 6

/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:577: ScannerError
T_plot_HiB(folder, dfile=None)[source]

This is a pytest needing documentation

code
docstring
"""HinfBounded_results_E = HinfBounded_results + extraplots
H2_results_E = H2_results + extraplots
every_nth = 2 # removes every nth element
H2_results_E_short = H2_results[every_nth-1::every_nth]+ extraplots"""
  1@pytest.mark.parametrize(
  2    'folder',
  3    [
  4        'ExampleModels_paper'
  5    ]
  6)
  7def T_plot_HiB(folder, dfile = None):
  8    if folder is None:
  9        folder = "ExampleModels"
 10
 11    sysB = get_systemB(folder=folder)
 12    io_scales = file_io.load(fjoin(folder, 'io_scales.yml')) # Saved by the normalization in the make function
 13
 14
 15
 16    H2_results = buzzutil.load_results(fjoin(folder, "results_H2_ADY.pkl"))
 17    print('save fldr: ', fjoin(folder, "results_H2_ADY.pkl"))
 18
 19    if dfile is None:
 20        ofile = "results_Hib_ADY.pkl"
 21        dfile = fjoin(folder, ofile)
 22    results_Hib = buzzutil.load_results(dfile)
 23
 24
 25    # print('Gamma:', buzzutil.listparams(HinfBounded_results, 'gamma'))
 26    # print('igsq:', np.unique(buzzutil.listparams(HinfBounded_results, 'igsq')))
 27    # print('F1_gain', np.unique(buzzutil.listparams(HinfBounded_results, 'F1_gain')))
 28    # print('F1_gain', buzzutil.listparams(HinfBounded_results, 'F1_gain'))
 29
 30    HinfBounded_results = results_Hib
 31    # H2_results = results_H2
 32
 33    # f1_gains = np.unique(buzzutil.listparams(HinfBounded_results, 'F1_gain'))
 34
 35    # HinfBounded_results =  buzzutil.filtparam(HinfBounded_results, "F1_gain", f1_gains[3], compare="eq")
 36
 37    for point in HinfBounded_results:
 38        if point["gamma"] == None:
 39            point["gamma"] = np.inf
 40
 41    # Remove labels
 42    for datadict in HinfBounded_results:
 43        datadict["label1"] = None
 44        datadict["label2"] = None
 45
 46    # Adding the current controller to the plot
 47    module_gain = -40 # this is the gain of the filter module
 48    filter_list = np.array([1, 3, 4, 5, 6]) # this is a list of the filters in the module that are on
 49
 50    zpksys, filtinfo = readFilter.readFilterSys_Scipy(
 51        fjoin("H1ASC.txt"), "ASC_DHARD_Y", np.array(filter_list)
 52    )
 53
 54    z, p, k = FilteringUtils.d2c(
 55        (zpksys.zeros, zpksys.poles, zpksys.gain), fs=1 / zpksys.dt
 56    )
 57
 58    k = k.real * module_gain
 59    K_mod = SISO.zpk(z, p, k, angular=True, fiducial_rtol=1e-5, fiducial_atol=1e-10).asSS
 60    K_iod = {"C.in": 0, "C.out": 0}
 61    K = wieldSS(K_mod, K_iod)
 62    K = (K.siso("C.out", "C.in") * sysB.sys["S.out", "SA.in"]).mimo(
 63        "C.out", "C.in"
 64    ) # Add in the part of P that was moved to env. noise block
 65    K = ssutil.balance_sys_gain(K)
 66
 67    curdict = HinfBounded_results[0].copy()
 68    curdict["Ac"] = K.A
 69    curdict["Bc"] = K.B
 70    curdict["Cc"] = K.C
 71    curdict["Dc"] = K.D
 72    curdict["K"] = K
 73    curdict["label"] = "Hand Tuned Controller"
 74
 75    extraplots = compute.calcFullResults(
 76        [curdict], color="dimgrey", 
 77        label="Hand Tuned Controller", 
 78        plot_omega=curdict["plot_omega"],
 79        io_scales=io_scales,
 80    )
 81    extraplots[0]["F1_gain"] = sum(buzzutil.listparams(HinfBounded_results, "F1_gain"))
 82    extraplots[0]["linecolor"] = "DodgerBlue"
 83    extraplots[0]["linestyle"] = "--"
 84    extraplots[0]["solver"] = "Hand Tuned"
 85    extraplots[0]["rms_marker"] = "^"
 86
 87    HinfBounded_results_E = HinfBounded_results + extraplots
 88    H2_results_E = H2_results + extraplots
 89
 90    every_nth = 2  # removes every nth element
 91    H2_results_E_short = H2_results[every_nth - 1 :: every_nth] + extraplots
 92
 93
 94    xlim= [0.2, 0.5]
 95    ylim = [3e-14, 9e-14]
 96    # Adding the current controller to the plot
 97    setname_Hib = "ADY_Hib"
 98
 99    if len(HinfBounded_results_E + H2_results)>100:
100        plot_text=False
101    else:
102        plot_text='pm'
103
104    print('Plotting RMS Plot')
105    fig_rms_Hib = plotting.plotRMS(
106        HinfBounded_results_E + H2_results,
107        setname=setname_Hib,
108        outlineparam='pm',
109        text=plot_text,
110        f1line=True,
111        h2line=True,
112        plotrange=False,
113        #xlim=xlim,
114        #ylim=ylim
115        test=True,
116    )
117
118    fig_rms_Hib[0].savefig(tjoin("rms_HiB.pdf"), bbox_inches="tight")
119    fig_rms_Hib[0].savefig(tjoin("rms_HiB.png"), bbox_inches="tight")
120
121    print('Plotting RMS Plot with lost range')
122    fig_rms_lost_range_Hib = plotting.plotRMS(
123        HinfBounded_results_E + H2_results,
124        setname=setname_Hib,
125        outlineparam='pm',
126        text=plot_text,
127        f1line=True,
128        h2line=True,
129        plotrange='diff',
130        test=True,
131        #xlim=xlim,
132        #ylim=ylim
133    )
134
135    fig_rms_lost_range_Hib[0].savefig(tjoin("rms_HiB_lost_range.pdf"), bbox_inches="tight")
136    fig_rms_lost_range_Hib[0].savefig(tjoin("rms_HiB_lost_range.png"), bbox_inches="tight")
137
138    print('Plotting RMS Plot with lost range (PSD computation)')
139    fig_rms_lost_range_Hib_psd = plotting.plotRMS(
140        HinfBounded_results_E + H2_results,
141        setname=setname_Hib,
142        outlineparam='pm',
143        text=plot_text,
144        f1line=True,
145        h2line=True,
146        plotrange='diff_psd',
147        test=True,
148        #xlim=xlim,
149        #ylim=ylim
150    )
151
152    fig_rms_lost_range_Hib_psd[0].savefig(tjoin("rms_HiB_lost_range_PSD.pdf"), bbox_inches="tight")
153    fig_rms_lost_range_Hib_psd[0].savefig(tjoin("rms_HiB_lost_range_PSD.png"), bbox_inches="tight")
154
155
156    f1gains_Hib = np.unique(buzzutil.listparams(HinfBounded_results, "F1_gain"))
157    try:
158        HinfBounded_results_single_f1gain = buzzutil.filtparam(HinfBounded_results, "F1_gain", f1gains_Hib[-4], compare="eq")
159    except:
160        HinfBounded_results_single_f1gain = buzzutil.filtparam(HinfBounded_results, "F1_gain", f1gains_Hib[0], compare="eq")
161    HinfBounded_results_single_f1gain = (
162        compute.calcFullResults(
163            HinfBounded_results_single_f1gain,
164            colormap="RdYlGn",
165            plot_omega=HinfBounded_results[0]["plot_omega"],
166            color_param="igsq",
167            label=False,
168            io_scales=io_scales,
169        )
170        + extraplots
171    )
172
173    print('Plotting RMS Plot With Range')
174    fig_rms_range_Hib = plotting.plotRMS(
175        HinfBounded_results + H2_results,
176        setname=setname_Hib,
177        outlineparam='pm',
178        text=plot_text,
179        f1line=True,
180        h2line=True,
181        plotrange=True,
182        test=True,
183        #xlim=xlim,
184        #ylim=ylim
185    )
186
187    fig_rms_range_Hib[0].savefig(tjoin("rms_HiB_range.pdf"), bbox_inches="tight")
188    fig_rms_range_Hib[0].savefig(tjoin("rms_HiB_range.png"), bbox_inches="tight")
189
190    xlim_PSD=[4.725, 4.805]
191    print('Plotting RMS Plot With Range from PSD')
192    fig_rms_range_PSD_Hib = plotting.plotRMS(
193        HinfBounded_results + H2_results,
194        setname=setname_Hib,
195        outlineparam='pm',
196        text=plot_text,
197        f1line=True,
198        h2line=True,
199        plotrange='PSD',
200        xlim=xlim_PSD,
201        test=True,
202        #ylim=ylim
203    )
204
205    fig_rms_range_PSD_Hib[0].savefig(tjoin("rms_HiB_range_from_PSD.pdf"), bbox_inches="tight")
206    fig_rms_range_PSD_Hib[0].savefig(tjoin("rms_HiB_range_from_PSD.png"), bbox_inches="tight")
207
208    print('Plotting Heatmap')
209    fig_rmsheatmap = plotting.plotHeatmap(HinfBounded_results + H2_results, test=True)
210    fig_rmsheatmap[0].savefig(tjoin("heatmap.pdf"), bbox_inches="tight")
211    fig_rmsheatmap[0].savefig(tjoin("heatmap.png"), bbox_inches="tight")
212
213    try:
214        print('Plotting RMS Plot with Heatmap')
215        fig_rmsheatmap_Hib = plotting.plotRMS(
216            HinfBounded_results_E + H2_results,
217            setname=setname_Hib,
218            outlineparam='pm',
219            text=False,
220            f1line=True,
221            h2line=True,
222            plotrange=True,
223            heatmap=True,
224            test=True,
225        )
226
227        fig_rmsheatmap_Hib[0].savefig(tjoin("rms_heatmap_HiB.pdf"), bbox_inches="tight")
228        fig_rmsheatmap_Hib[0].savefig(tjoin("rms_heatmap_HiB.png"), bbox_inches="tight")
229    except Exception as e:
230        print("Heatmap Failed:, ", e)
231
232    print('Plotting RMS Range Plot single result')
233    fig_single_Hib = plotting.plotRMS(
234        HinfBounded_results_single_f1gain + H2_results,
235        setname=setname_Hib,
236        outlineparam='pm',
237        text=False,
238        f1line=True,
239        h2line=True,
240        plotrange=True,
241        heatmap=False,
242        test=True,
243    )
244
245    fig_single_Hib[0].savefig(tjoin("rms_HiB_singlef1gain_range.pdf"), bbox_inches="tight")
246    fig_single_Hib[0].savefig(tjoin("rms_HiB_singlef1gain_range.png"), bbox_inches="tight")
247
248
249
250
251    print('Plotting Open Loop')
252    ylim = [3e-4, 1e5]
253    fig_ol_Hib, ax_ol_Hib = plotting.plotLoop(
254        HinfBounded_results_single_f1gain, "OL", setname=setname_Hib, ylim=ylim, UG_line=True, test=True,
255    )
256    fig_ol_Hib.savefig(tjoin("ol_HiB.pdf"), bbox_inches="tight")
257    fig_ol_Hib.savefig(tjoin("ol_HiB.png"), bbox_inches="tight")
258
259    print('Plotting Closed Loop')
260    xlim = [1e-1, 1e4]
261    fig_cl_Hib, ax_cl_Hib = plotting.plotLoop(
262        HinfBounded_results_single_f1gain, "CL", setname=setname_Hib, UG_line=True, xlim=xlim, test=True,
263    )
264    fig_cl_Hib.savefig(tjoin("cl_HiB.pdf"), bbox_inches="tight")
265    fig_cl_Hib.savefig(tjoin("cl_HiB.png"), bbox_inches="tight")
266
267    print('Plotting gm pm plot')
268    ylim = None  # [0, 12]
269    plt.clf()
270    fig_gm_pm, ax_gm_pm = plotting.plot_gm_pm(
271        HinfBounded_results_E, setname="", f1line=True, text=None, ylim=[0.5,2.5], xlim=[2.5,20], io_scales=io_scales, test=True,
272    )
273    fig_gm_pm.savefig(tjoin("gm_HiB.pdf"), bbox_inches="tight")
274    fig_gm_pm.savefig(tjoin("gm_HiB.png"), bbox_inches="tight")
275
276    print('Plotting vegaplot')
277    setname_vega = 'ASC_vega'
278    vega_chart = plotting.vega_plot(HinfBounded_results_E + H2_results, setname=setname_vega, h2line=False, size=500, plotrange=False, test=True)
279    vega_chart.save(tjoin("vega_results_plot.html"))
280
281    DARM_out_name = 'DARM.out'
282    if DARM_out_name in extraplots[0]['CL_all_io'].outputs.keys():
283        print('Plotting DARM noise')
284        DARM_plot_omega = np.logspace(-2, 3, 1000) * 2 * np.pi
285        DARM_noise_plot_fig, DARM_noise_plot_axs = plotting.plot_CLnoises(extraplots[0], extra_fom=DARM_out_name, extra_only=True, plot_omega=DARM_plot_omega, test=True, scale=1/io_scales.w2_rescale)
286        DARM_noise_plot_fig.savefig(tjoin("DARM_noise_H2.pdf"), bbox_inches="tight")
287        DARM_noise_plot_fig.savefig(tjoin("DARM_noise_H2.png"), bbox_inches="tight")
pytest information

This code is wrapped in a pytest function using conventions detailed in pytest_conventions. The full name of this test, as known by the documentation, is:

test.ASC_SOLVER_PAPER.test_solver_ADY_paper.T_plot_HiB

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.

T_plot_HiB[ExampleModels_paper]
output
status: failed
duration: 0.003s
captured errors:
folder = 'ExampleModels_paper', dfile = None

    @pytest.mark.parametrize(
        'folder',
        [
            'ExampleModels_paper'
        ]
    )
    def T_plot_HiB(folder, dfile = None):
        if folder is None:
            folder = "ExampleModels"

        sysB = get_systemB(folder=folder)
>       io_scales = file_io.load(fjoin(folder, 'io_scales.yml')) # Saved by the normalization in the make function

/builds/buzz/test/ASC_SOLVER_PAPER/test_solver_ADY_paper.py:469: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/wield/wield-utilities/src/wield/utilities/file_io/__init__.py:48: in load
    return load_any(
/wield/wield-utilities/src/wield/utilities/file_io/any_io.py:47: in load_any
    fdict = yaml_io.yaml_load(fname)
/wield/wield-utilities/src/wield/utilities/file_io/yaml_io.py:43: in yaml_load
    fdict = yaml.load(F, Loader=yaml_loader)
/opt/conda/lib/python3.12/site-packages/yaml/__init__.py:81: in load
    return loader.get_single_data()
/opt/conda/lib/python3.12/site-packages/yaml/constructor.py:49: in get_single_data
    node = self.get_single_node()
/opt/conda/lib/python3.12/site-packages/yaml/composer.py:36: in get_single_node
    document = self.compose_document()
/opt/conda/lib/python3.12/site-packages/yaml/composer.py:58: in compose_document
    self.get_event()
/opt/conda/lib/python3.12/site-packages/yaml/parser.py:118: in get_event
    self.current_event = self.state()
/opt/conda/lib/python3.12/site-packages/yaml/parser.py:193: in parse_document_end
    token = self.peek_token()
/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:129: in peek_token
    self.fetch_more_tokens()
/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:223: in fetch_more_tokens
    return self.fetch_value()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <yaml.loader.SafeLoader object at 0x7f49bba22b70>

    def fetch_value(self):

        # Do we determine a simple key?
        if self.flow_level in self.possible_simple_keys:

            # Add KEY.
            key = self.possible_simple_keys[self.flow_level]
            del self.possible_simple_keys[self.flow_level]
            self.tokens.insert(key.token_number-self.tokens_taken,
                    KeyToken(key.mark, key.mark))

            # If this key starts a new block mapping, we need to add
            # BLOCK-MAPPING-START.
            if not self.flow_level:
                if self.add_indent(key.column):
                    self.tokens.insert(key.token_number-self.tokens_taken,
                            BlockMappingStartToken(key.mark, key.mark))

            # There cannot be two simple keys one after another.
            self.allow_simple_key = False

        # It must be a part of a complex key.
        else:

            # Block context needs additional checks.
            # (Do we really need them? They will be caught by the parser
            # anyway.)
            if not self.flow_level:

                # We are allowed to start a complex value if and only if
                # we can start a simple key.
                if not self.allow_simple_key:
>                   raise ScannerError(None, None,
                            "mapping values are not allowed here",
                            self.get_mark())
E                   yaml.scanner.ScannerError: mapping values are not allowed here
E                     in "/builds/buzz/test/ASC_SOLVER_PAPER/ExampleModels_paper/io_scales.yml", line 2, column 6

/opt/conda/lib/python3.12/site-packages/yaml/scanner.py:577: ScannerError
get_systemB(folder='ExampleModels')[source]

This is a pytest needing documentation

code
1def get_systemB(folder = 'ExampleModels'):
2    fname = fjoin(folder, "ADY_Sanex.mat")
3    sys = ssutil.loadSys(fname)
4
5    orig_plant_fname = fjoin(folder, "ADY_plant.mat")
6    orig_plant = ssutil.loadSys(orig_plant_fname)
7
8    return Bunch(locals())
pytest information

This code is wrapped in a pytest function using conventions detailed in pytest_conventions. The full name of this test, as known by the documentation, is:

test.ASC_SOLVER_PAPER.test_solver_ADY_paper.get_systemB

The full name is useful when building documentation, to link a reference to this page using :func:`name`, or directly include it with an autofunction directive. The collapse nodes below show every instance of the test run. There may only be one, but if the test was run multiple times through pytest parametrizations, the list can be longer.