• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WISDEM / WEIS / 10927734534

18 Sep 2024 06:09PM UTC coverage: 79.235% (-0.4%) from 79.668%
10927734534

Pull #315

github

web-flow
Merge 397ba5241 into f779fa594
Pull Request #315: WEIS 1.3.1

21 of 180 new or added lines in 4 files covered. (11.67%)

8 existing lines in 4 files now uncovered.

21647 of 27320 relevant lines covered (79.23%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/weis/visualization/opt_plotting.py
1
import glob
×
2

3
import glob
×
4
import json
×
5
import multiprocessing as mp
×
6

7
import pandas as pd
×
8
import numpy as np
×
9
import matplotlib.pyplot as plt
×
10

11
import openmdao.api as om
×
12

13
from weis.visualization.utils import *
×
14

15

16
def plot_conv(
×
17
    keyset_in,
18
    map_dataOM_vars,
19
    use_casewise_feasibility=False,
20
    feas_tol=1e-5,
21
    figax=None,
22
    alpha=None,
23
):
24
    """
25
    plot a set of keys
26

27
    args:
28
        keyset_in: list[str]
29
            list of keys to plot the convergence data for
30
        map_dataOM_vars: dict[str -> dict]
31
            map from a case of interest by name to an OM data dict to plot
32
        use_casewise_feasibility: bool
33
            if plotting a constraint should we plot feasibility w.r.t. that constraint (vs. all)
34

35
    returns:
36
        fig : plt.Figure
37
        ax : plt.Axes
38
    """
39

40
    if len(keyset_in) == 0:
×
41
        return
×
42

43
    markerstyle = "x"
×
44
    markersize = 5
×
45
    linestyle = "-"
×
46

47

NEW
48
    fig, axes = figax if figax else plt.subplots(
×
49
        len(keyset_in),
50
        1,
51
        sharex=True,
52
        figsize=(6, 0.60 * 4 * len(keyset_in)),
53
        squeeze=False,
54
        dpi=150,
55
    )
56

57
    has_ref_vals = type(keyset_in) == dict
×
58

59
    if has_ref_vals:
×
60
        key_val_map = keyset_in
×
61
        keyset = keyset_in.keys()
×
62
    else:
63
        keyset = keyset_in
×
64

65
    pt_imethod = []
×
66
    for imethod, method in enumerate(map_dataOM_vars.keys()):
×
67
        if imethod == 0:
×
68
            markerstyle = "o"
×
69
        elif imethod == 1:
×
70
            markerstyle = "p"
×
71
        elif imethod == 2:
×
72
            markerstyle = "s"
×
73
        else:
74
            markerstyle = "P"
×
75

76
        pt0 = axes[0, 0].plot(
×
77
            [],
78
            [],
79
            markerstyle + linestyle,
80
            label=method,
81
            markersize=markersize,
82
            # color=(0.5,0.5,0.5),
83
            alpha=alpha,
84
        )
85
        dataOM = map_dataOM_vars[method][0]
×
86
        vars = map_dataOM_vars[method][1]
×
87
        tfeas, varfeas = get_feasible_iterations(dataOM, vars, feas_tol=feas_tol)
×
88

89
        for idx_ax, key in enumerate(keyset):
×
90
            if key in ["rank", "iter",]: continue
×
91
            if use_casewise_feasibility and key in varfeas.keys():
×
92
                feas_val = varfeas[key]
×
93
            else:
94
                feas_val = tfeas  # use total feasibility
×
95

96
            axes[idx_ax, 0].plot(
×
97
                np.squeeze(dataOM[key]),
98
                linestyle,
99
                label="".join(["_", method, "_"]),
100
                color=pt0[-1].get_color(),
101
                markersize=markersize,
102
                alpha=alpha,
103
            )
104
            axes[idx_ax, 0].plot(
×
105
                np.ma.array(
106
                    dataOM[key],
107
                    mask=~(
108
                        feas_val * np.ones(
109
                            (
110
                                1,
111
                                np.array(dataOM[key]).shape[1]
112
                                if len(np.array(dataOM[key]).shape) > 1
113
                                else 1
114
                            ),
115
                            dtype=bool,
116
                        )
117
                    )
118
                ),
119
                markerstyle,
120
                label="".join(["_", method, "_"]),
121
                color=pt0[-1].get_color(),
122
                alpha=alpha,
123
                fillstyle="full",
124
                markersize=markersize,
125
            )
126
            axes[idx_ax, 0].plot(
×
127
                np.ma.array(
128
                    dataOM[key],
129
                    mask=(
130
                        feas_val * np.ones(
131
                            (
132
                                1,
133
                                np.array(dataOM[key]).shape[1]
134
                                if len(np.array(dataOM[key]).shape) > 1
135
                                else 1
136
                            ),
137
                            dtype=bool,
138
                        )
139
                    )
140
                ),
141
                markerstyle,
142
                label="".join(["_", method, "_"]),
143
                color=pt0[-1].get_color(),
144
                alpha=alpha,
145
                fillstyle="none",
146
                markersize=markersize,
147
            )
148
            if has_ref_vals:
×
149
                cval = key_val_map[key]
×
NEW
150
                if (cval[0] is not None) and (np.log10(np.abs(cval[0])) < 18):
×
151
                    axes[idx_ax, 0].plot([0, len(dataOM[key])], [cval[0], cval[0]], "b:", label="_lower bound_")
×
NEW
152
                if (cval[1] is not None) and (np.log10(np.abs(cval[1])) < 18):
×
153
                    axes[idx_ax, 0].plot([0, len(dataOM[key])], [cval[1], cval[1]], "r:", label="_upper bound_")
×
154
            axes[idx_ax, 0].set_title(key)
×
155

156
    if has_ref_vals:
×
157
        axes[0, 0].plot([], [], "b:", label="lower bound")
×
158
        axes[0, 0].plot([], [], "r:", label="upper bound")
×
159
    axes[0, 0].legend()
×
160
    fig.tight_layout()
×
161

162
    return fig, axes
×
163

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc