Skip to content

Commit

Permalink
Support constraints plot in run page if available
Browse files Browse the repository at this point in the history
  • Loading branch information
zhe-slac committed Dec 9, 2021
1 parent 4576672 commit 8fbf8f4
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/badger/gui/pages/run_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def init_ui(self):
leg_obj = plot_obj.addLegend()
leg_obj.setBrush((50, 50, 100, 200))

run_view.nextRow()
run_view.nextRow()

self.plot_var = plot_var = run_view.addPlot(
Expand Down Expand Up @@ -175,12 +176,23 @@ def load_run(self, current, previous):
def plot_run(self):
run = self.run
self.plot_obj.clear()
try:
self.plot_con.clear()
except:
pass
self.plot_var.clear()

if not run:
self.btn_del.setDisabled(True)
self.btn_run.setDisabled(True)
self.btn_load.setDisabled(True)

try:
self.run_view.removeItem(self.plot_con)
del self.plot_con
except:
pass

return

self.btn_del.setDisabled(False)
Expand All @@ -191,6 +203,11 @@ def plot_run(self):
for d in run['routine']['config']['variables']]
obj_names = [next(iter(d))
for d in run['routine']['config']['objectives']]
try:
con_names = [next(iter(d))
for d in run['routine']['config']['constraints']]
except:
con_names = []
data = run['data']

for i, obj_name in enumerate(obj_names):
Expand All @@ -200,6 +217,36 @@ def plot_run(self):
# symbol=symbol,
name=obj_name)

if con_names:
try:
self.plot_con
except:
self.plot_con = plot_con = self.run_view.addPlot(
row=1, col=0, title='Evaluation History (C)')
plot_con.setLabel('left', 'constraints')
plot_con.setLabel('bottom', 'iterations')
plot_con.showGrid(x=True, y=True)
leg_con = plot_con.addLegend()
leg_con.setBrush((50, 50, 100, 200))

plot_con.setXLink(self.plot_obj)

for i, con_name in enumerate(con_names):
color = self.colors[i % len(self.colors)]
symbol = self.symbols[i % len(self.colors)]
try:
self.plot_con.plot(np.array(data[con_name]), pen=pg.mkPen(color, width=3),
# symbol=symbol,
name=con_name)
except: # Mal-format data
pass
else:
try:
self.run_view.removeItem(self.plot_con)
del self.plot_con
except:
pass

for i, var_name in enumerate(var_names):
color = self.colors[i % len(self.colors)]
symbol = self.symbols[i % len(self.colors)]
Expand Down

0 comments on commit 8fbf8f4

Please sign in to comment.