Skip to content

Commit

Permalink
Added additional logging and changed update condition for x and y axi…
Browse files Browse the repository at this point in the history
…s dropdown selection
  • Loading branch information
MitchellAV committed Dec 4, 2024
1 parent ecc6efa commit b3ff01e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 24 deletions.
11 changes: 6 additions & 5 deletions src/badger/gui/default/components/analysis_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class AnalysisExtension(QDialog):
Expand Down Expand Up @@ -72,7 +71,7 @@ def __init__(self, parent: Optional[AnalysisExtension] = None):
self.setWindowTitle("BO Visualizer")
self.bo_plot_widget: Optional[BOPlotWidget] = None

def requires_update(self, routine: Routine):
def requires_reinitialization(self, routine: Routine):
if routine.data is None:
logger.debug("Reset - No data available")
return True
Expand All @@ -91,7 +90,9 @@ def requires_update(self, routine: Routine):
def update_window(self, routine: Routine):
# Update the BOPlotWidget with the new routine
logger.debug("Updating BOVisualizer window with new routine")
self.df_length = len(routine.data)
if routine.data is not None:
logger.debug("No data available")
self.df_length = len(routine.data)
# logger.debug(f"Routine {routine.data}")

# Initialize the BOPlotWidget if it is not already initialized
Expand All @@ -112,12 +113,12 @@ def update_window(self, routine: Routine):
# If there is no data available, then initialize the plot
# This needs to happen when starting a new optimization run

if self.requires_update(routine):
if self.requires_reinitialization(routine):
self.bo_plot_widget.initialize_plot(routine)
logger.debug(f"Data: {self.bo_plot_widget.model_logic.xopt_obj.data}")
else:
logger.debug("BOPlotWidget already has data")

# Update the plot with every call to update_window
# This is necessary when continuing an optimization run
self.bo_plot_widget.update_plot(100)
self.bo_plot_widget.update_plot(500)
48 changes: 46 additions & 2 deletions src/badger/gui/default/components/bo_visualizer/bo_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class BOPlotWidget(QWidget):
Expand Down Expand Up @@ -105,14 +104,46 @@ def setup_connections(self):

# If you have variable checkboxes
for checkbox in self.ui_components.variable_checkboxes.values():
logger.debug(f"Setting up connection for checkbox: {checkbox.text()}")
try:
checkbox.stateChanged.disconnect()
except TypeError:
pass
checkbox.stateChanged.connect(self.on_axis_selection_changed)

# Plot options
plot_options_checkboxes = [
self.ui_components.acq_func_checkbox,
self.ui_components.show_samples_checkbox,
self.ui_components.show_prior_mean_checkbox,
self.ui_components.show_feasibility_checkbox,
]

for checkbox in plot_options_checkboxes:
logger.debug(f"Setting up connection for checkbox: {checkbox.text()}")
try:
checkbox.stateChanged.disconnect()
except TypeError:
pass
checkbox.stateChanged.connect(self.update_plot)

# No. of Grid Points
try:
self.ui_components.n_grid.valueChanged.disconnect()
except TypeError:
pass
self.ui_components.n_grid.valueChanged.connect(self.update_plot)

# # Reference inputs
# try:
# self.ui_components.reference_table.itemChanged.disconnect()
# except TypeError:
# pass
# self.ui_components.reference_table.itemChanged.connect(self.update_plot)

def on_axis_selection_changed(self):
if not self.model_logic.vocs or not self.ui_components.ref_inputs:
# vocs or ref_inputs is not yet set; skip processing
return

logger.debug("Axis selection changed")
Expand All @@ -124,7 +155,6 @@ def on_axis_selection_changed(self):

# Always include X-axis variable
x_var = self.ui_components.x_axis_combo.currentText()
logger.debug(f"x_var: {x_var}")
if x_var:
self.selected_variables.append(x_var)

Expand All @@ -139,6 +169,12 @@ def on_axis_selection_changed(self):

logger.debug(f"previous_selected_variables: {previous_selected_variables}")
logger.debug(f"self.selected_variables: {self.selected_variables}")

if len(self.selected_variables) == 0:
# No variables selected; do not proceed with updating the plot
logger.debug("No variables selected; skipping plot update")
return

if previous_selected_variables != self.selected_variables:
print("Selected variables for plotting:", self.selected_variables)
# Update the reference point table based on the selected variables
Expand Down Expand Up @@ -176,6 +212,9 @@ def update_plot(self, interval: Optional[float] = None):
# Disable and gray out the reference points for selected variables
self.update_reference_point_table(selected_variables)

logger.debug(f"ref_inputs: {self.ui_components.ref_inputs}")
logger.debug(f"selected_variables: {selected_variables}")

# Get reference points for non-selected variables
reference_point = self.model_logic.get_reference_points(
self.ui_components.ref_inputs, selected_variables
Expand Down Expand Up @@ -210,6 +249,11 @@ def update_plot(self, interval: Optional[float] = None):

self.parent().resize(width, height)

logger.debug("Updating plot with selected variables and reference points")
# logger.debug(f"xopt_obj: {self.model_logic.xopt_obj}")
logger.debug(f"selected_variables: {selected_variables}")
logger.debug(f"reference_point: {reference_point}")

# Update the plot with the selected variables and reference points
self.plotting_area.update_plot(
self.model_logic.xopt_obj,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class PlottingArea(QWidget):
Expand Down Expand Up @@ -50,8 +49,6 @@ def update_plot(
logger.debug("Skipping update")
return

logger.debug(f"layouts: {self.layout.count()}")

# Clear the existing layout (remove previous plot if any)
for i in reversed(range(self.layout.count())):
widget_to_remove = self.layout.itemAt(i).widget()
Expand All @@ -63,12 +60,14 @@ def update_plot(
return

generator = xopt_obj.generator
logger.debug(f"Generator: {generator}")

# Ensure use_cuda is a boolean
generator.use_cuda = False # or True, depending on your setup

# Set generator data
generator.data = xopt_obj.data
logger.debug(f"Generator data: {generator.data}")

# Check if the model exists
if not hasattr(generator, "model") or generator.model is None:
Expand All @@ -78,6 +77,7 @@ def update_plot(
generator.train_model()
except Exception as e:
print(f"Failed to train model: {e}")
logger.error(f"Failed to train model: {e}")
QMessageBox.warning(
self, "Model Training Error", f"Failed to train model: {e}"
)
Expand Down
37 changes: 23 additions & 14 deletions src/badger/gui/default/components/bo_visualizer/ui_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class UIComponents:
Expand Down Expand Up @@ -122,6 +121,8 @@ def create_reference_inputs(self):

def populate_reference_table(self):
"""Populate the reference table based on the current vocs variable names."""

logger.debug("Populating reference table")
self.reference_table.setRowCount(len(self.vocs.variable_names))
self.ref_inputs = []

Expand All @@ -137,6 +138,9 @@ def populate_reference_table(self):
reference_point_item = QTableWidgetItem(str(default_value))
self.ref_inputs.append(reference_point_item)
self.reference_table.setItem(i, 1, reference_point_item)
logger.debug(
f"Added reference point: {variable_item.text()}: {reference_point_item.text()}"
)

def create_options_section(self):
group_box = QGroupBox("Plot Options")
Expand Down Expand Up @@ -172,24 +176,29 @@ def update_vocs(
state_changed_callback: Optional[Callable[[QWidget], None]] = None,
):
self.vocs = vocs
logger.debug(f"Updating UI components with new vocs: {vocs}")
logger.debug(f"type(vocs): {type(vocs)}")
logger.debug(f"x_axis_combo: {self.x_axis_combo.currentText()}")
logger.debug(f"y_axis_combo: {self.y_axis_combo.currentText()}")
# Update axis combos after vocs is set
# FIX: Clearing the combo boxes triggers a signal that calls the state_changed_callback
self.x_axis_combo.clear()
self.y_axis_combo.clear()
logger.debug(f"x_axis_combo cleared: {self.x_axis_combo.currentText()}")
logger.debug(f"y_axis_combo cleared: {self.y_axis_combo.currentText()}")
if self.vocs:
logger.debug(f"vocs: {vocs}")
# List all items in the x_axis_combo QComboBox
x_axis_items = [
self.x_axis_combo.itemText(i) for i in range(self.x_axis_combo.count())
]
logger.debug(f"x_axis_combo items: {x_axis_items}")

y_axis_items = [
self.y_axis_combo.itemText(i) for i in range(self.y_axis_combo.count())
]
logger.debug(f"y_axis_combo items: {y_axis_items}")

combined_set = set(x_axis_items + y_axis_items)

if self.vocs.variable_names != list(combined_set):
logger.debug(
f"Populating axis combos with variable names: {self.vocs.variable_names}"
)
self.x_axis_combo.clear()
self.y_axis_combo.clear()

self.x_axis_combo.addItems(self.vocs.variable_names)
self.y_axis_combo.addItems(self.vocs.variable_names)
logger.debug(f"x_axis_combo: {self.x_axis_combo.currentText()}")
logger.debug(f"y_axis_combo: {self.y_axis_combo.currentText()}")

# Re-initialize variable checkboxes if needed

Expand Down

0 comments on commit b3ff01e

Please sign in to comment.