ivoryos 1.3.9__py3-none-any.whl → 1.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ivoryos might be problematic. Click here for more details.

Files changed (35) hide show
  1. ivoryos/optimizer/ax_optimizer.py +47 -25
  2. ivoryos/optimizer/base_optimizer.py +19 -1
  3. ivoryos/optimizer/baybe_optimizer.py +27 -17
  4. ivoryos/optimizer/nimo_optimizer.py +25 -16
  5. ivoryos/routes/data/data.py +27 -9
  6. ivoryos/routes/data/templates/components/step_card.html +47 -11
  7. ivoryos/routes/data/templates/workflow_view.html +14 -5
  8. ivoryos/routes/design/design.py +31 -1
  9. ivoryos/routes/design/design_step.py +2 -1
  10. ivoryos/routes/design/templates/components/edit_action_form.html +16 -3
  11. ivoryos/routes/design/templates/components/python_code_overlay.html +27 -10
  12. ivoryos/routes/design/templates/experiment_builder.html +1 -0
  13. ivoryos/routes/execute/execute.py +71 -13
  14. ivoryos/routes/execute/templates/components/logging_panel.html +50 -25
  15. ivoryos/routes/execute/templates/components/run_tabs.html +45 -2
  16. ivoryos/routes/execute/templates/components/tab_bayesian.html +447 -325
  17. ivoryos/routes/execute/templates/components/tab_configuration.html +303 -18
  18. ivoryos/routes/execute/templates/components/tab_repeat.html +6 -2
  19. ivoryos/routes/execute/templates/experiment_run.html +0 -264
  20. ivoryos/socket_handlers.py +1 -1
  21. ivoryos/static/js/action_handlers.js +252 -118
  22. ivoryos/static/js/sortable_design.js +1 -0
  23. ivoryos/utils/bo_campaign.py +17 -16
  24. ivoryos/utils/db_models.py +122 -18
  25. ivoryos/utils/decorators.py +1 -0
  26. ivoryos/utils/form.py +32 -12
  27. ivoryos/utils/nest_script.py +314 -0
  28. ivoryos/utils/script_runner.py +436 -143
  29. ivoryos/utils/utils.py +11 -1
  30. ivoryos/version.py +1 -1
  31. {ivoryos-1.3.9.dist-info → ivoryos-1.4.1.dist-info}/METADATA +6 -4
  32. {ivoryos-1.3.9.dist-info → ivoryos-1.4.1.dist-info}/RECORD +35 -34
  33. {ivoryos-1.3.9.dist-info → ivoryos-1.4.1.dist-info}/WHEEL +0 -0
  34. {ivoryos-1.3.9.dist-info → ivoryos-1.4.1.dist-info}/licenses/LICENSE +0 -0
  35. {ivoryos-1.3.9.dist-info → ivoryos-1.4.1.dist-info}/top_level.txt +0 -0
@@ -23,11 +23,24 @@
23
23
  {% else %}
24
24
  {{ forms.hidden_tag() }}
25
25
  {% for field in forms %}
26
+
26
27
  {% if field.type not in ['CSRFTokenField'] %}
27
28
  <div class="input-group mb-3">
28
- <label class="input-group-text">{{ field.label.text }}</label>
29
- {{ field(class="form-control") }}
30
- <div class="form-text">{{ field.description }} </div>
29
+ <label class="input-group-text">{{ field.label.text | format_name }}</label>
30
+ {% if field.type == "BooleanField" %}
31
+ {{ field(class="form-check-input") }}
32
+ {% elif field.type == "FlexibleEnumField" %}
33
+ <input type="text" id="{{ field.id }}" name="{{ field.name }}" value="{{ field.data }}"
34
+ list="{{ field.id }}_options" placeholder="{{ field.render_kw.placeholder if field.render_kw and field.render_kw.placeholder }}"
35
+ class="form-control">
36
+ <datalist id="{{ field.id }}_options">
37
+ {% for key in field.choices %}
38
+ <option value="{{ key }}">{{ key }}</option>
39
+ {% endfor %}
40
+ </datalist>
41
+ {% else %}
42
+ {{ field(class="form-control") }}
43
+ {% endif %}
31
44
  </div>
32
45
  {% endif %}
33
46
  {% endfor %}
@@ -1,5 +1,4 @@
1
- {# Python code overlay component #}
2
- {#{% if session.get('show_code') %}#}
1
+ {# Python code overlay component - Pure HTML #}
3
2
  <style>
4
3
  .code-overlay {
5
4
  position: fixed;
@@ -16,7 +15,7 @@
16
15
  transform: translateX(0);
17
16
  }
18
17
  </style>
19
- <script>hljs.highlightAll();</script>
18
+
20
19
  {% if session.get('show_code') %}
21
20
  <div id="pythonCodeOverlay" class="code-overlay bg-light border-start show">
22
21
  {% else %}
@@ -29,11 +28,29 @@
29
28
  </button>
30
29
  </div>
31
30
  <div class="overlay-content p-3">
32
- {% for stype, script in session.get('python_code', {}).items() %}
33
- <pre><code class="language-python">{{ script }}</code></pre>
34
- {% endfor %}
35
- <a href="{{ url_for('design.design_files.download_python', filetype='python') }}">
36
- Download <i class="bi bi-download"></i>
37
- </a>
31
+ <!-- Top toggles (Single / Batch) -->
32
+ <div class="btn-group mb-3">
33
+ <button type="button" class="btn btn-outline-primary mode-toggle active" data-mode="single">Single</button>
34
+ <button type="button" class="btn btn-outline-primary mode-toggle" data-mode="batch">Batch</button>
35
+ </div>
36
+
37
+ {# <!-- Secondary toggles (By Sample / By Step) TODO -->#}
38
+ {# <div class="btn-group mb-3" id="batch-options" style="display: none;">#}
39
+ {# <button type="button" class="btn btn-outline-secondary batch-toggle active" data-batch="sample">By Sample</button>#}
40
+ {# <button type="button" class="btn btn-outline-secondary batch-toggle" data-batch="step">By Step</button>#}
41
+ {# </div>#}
42
+
43
+ <!-- Code display -->
44
+ <pre><code id="python-code" class="language-python">Loading...</code></pre>
45
+
46
+ <!-- Action buttons -->
47
+ <div class="mt-2">
48
+ <button type="button" id="copy-code" class="btn btn-sm btn-outline-success">
49
+ <i class="bi bi-clipboard"></i> Copy
50
+ </button>
51
+ <button type="button" id="download-code" class="btn btn-sm btn-outline-primary">
52
+ <i class="bi bi-download"></i> Download
53
+ </button>
54
+ </div>
38
55
  </div>
39
- </div>
56
+ </div>
@@ -32,6 +32,7 @@
32
32
  const scriptStepUrl = `{{ url_for('design.design_steps.get_step', uuid=0) }}`;
33
33
  const scriptStepDupUrl = `{{ url_for('design.design_steps.duplicate_action', uuid=0) }}`;
34
34
  const scriptDeleteUrl = "{{ url_for('design.clear_draft') }}";
35
+ const scriptCompileUrl = "{{ url_for('design.compile_preview') }}";
35
36
  </script>
36
37
  <script src="{{ url_for('static', filename='js/sortable_design.js') }}"></script>
37
38
  <script src="{{ url_for('static', filename='js/action_handlers.js') }}"></script>
@@ -3,7 +3,7 @@ import os
3
3
  import time
4
4
 
5
5
  from flask import Blueprint, redirect, url_for, flash, jsonify, request, render_template, session, \
6
- current_app, g
6
+ current_app, g, send_file
7
7
  from flask_login import login_required
8
8
 
9
9
  from ivoryos.routes.execute.execute_file import files
@@ -76,14 +76,17 @@ def experiment_run():
76
76
  if isinstance(exec_string, dict):
77
77
  for key, func_str in exec_string.items():
78
78
  exec(func_str)
79
- line_collection = script.convert_to_lines(exec_string)
79
+
80
80
  else:
81
81
  # Handle string case - you might need to adjust this based on your needs
82
- line_collection = []
82
+ line_collection = {}
83
83
  except Exception:
84
84
  flash(f"Please check syntax!!")
85
85
  return redirect(url_for("design.experiment_builder"))
86
86
 
87
+
88
+ line_collection = script.render_script_lines(script.script_dict)
89
+
87
90
  run_name = script.name if script.name else "untitled"
88
91
 
89
92
  dismiss = session.get("dismiss", None)
@@ -92,8 +95,13 @@ def experiment_run():
92
95
 
93
96
  _, return_list = script.config_return()
94
97
  config_list, config_type_list = script.config("script")
95
- data_list = os.listdir(current_app.config['DATA_FOLDER'])
96
- data_list.remove(".gitkeep") if ".gitkeep" in data_list else data_list
98
+ data_list = [f for f in os.listdir(current_app.config['DATA_FOLDER']) if f.endswith('.csv')]
99
+ # Remove .gitkeep if present
100
+ if ".gitkeep" in data_list:
101
+ data_list.remove(".gitkeep")
102
+
103
+ # Sort by creation time, newest first
104
+ data_list.sort(key=lambda f: os.path.getctime(os.path.join(current_app.config['DATA_FOLDER'], f)), reverse=True)
97
105
 
98
106
  if deck is None:
99
107
  no_deck_warning = True
@@ -115,21 +123,26 @@ def experiment_run():
115
123
  elif "parameters" in payload_json:
116
124
  bo_args = payload_json
117
125
  repeat = payload_json.pop("repeat", None)
126
+ batch_size = payload_json.pop('batch_size', 1)
118
127
  else:
119
128
  if "bo" in request.form:
120
129
  bo_args = request.form.to_dict()
121
130
  existing_data = bo_args.pop("existing_data")
122
131
  if "online-config" in request.form:
123
- config = utils.web_config_entry_wrapper(request.form.to_dict(), config_list)
132
+ config_args = request.form.to_dict()
133
+ config_args.pop("batch_size", None)
134
+ config = utils.web_config_entry_wrapper(config_args, config_list)
135
+ batch_size = int(request.form.get('batch_size', 1))
124
136
  repeat = request.form.get('repeat', None)
125
137
 
126
138
  try:
139
+ # if True:
127
140
  datapath = current_app.config["DATA_FOLDER"]
128
141
  run_name = script.validate_function_name(run_name)
129
142
  runner.run_script(script=script, run_name=run_name, config=config, bo_args=bo_args,
130
143
  logger=g.logger, socketio=g.socketio, repeat_count=repeat,
131
144
  output_path=datapath, compiled=compiled, history=existing_data,
132
- current_app=current_app._get_current_object()
145
+ current_app=current_app._get_current_object(), batch_size=batch_size
133
146
  )
134
147
  if utils.check_config_duplicate(config):
135
148
  flash(f"WARNING: Duplicate in config entries.")
@@ -172,11 +185,38 @@ def run_bo():
172
185
  """
173
186
  script = utils.get_script_file()
174
187
  run_name = script.name if script.name else "untitled"
175
- payload = request.form.to_dict()
176
- repeat = payload.pop("repeat", None)
177
- optimizer_type = payload.pop("optimizer_type", None)
178
- existing_data = payload.pop("existing_data", None)
179
- parameters, objectives, steps = parse_optimization_form(payload)
188
+
189
+ if request.accept_mimetypes.best_match(['application/json', 'text/html']) == 'application/json':
190
+ payload_json = request.get_json()
191
+ objectives = payload_json.pop("objectives", None)
192
+ parameters = payload_json.pop("parameters", None)
193
+ steps = payload_json.pop("steps", None)
194
+ constraints = payload_json.pop("parameter_constraints", None)
195
+ repeat = payload_json.pop("repeat", None)
196
+ batch_size = payload_json.pop("batch_size", None)
197
+ optimizer_type = payload_json.pop("optimizer_type", None)
198
+ existing_data = payload_json.pop("existing_data", None)
199
+
200
+ else:
201
+ payload = request.form.to_dict()
202
+ repeat = payload.pop("repeat", None)
203
+ optimizer_type = payload.pop("optimizer_type", None)
204
+ existing_data = payload.pop("existing_data", None)
205
+ batch_mode = payload.pop("batch_mode", None)
206
+ batch_size = payload.pop("batch_size", 1)
207
+
208
+ # Get constraint expressions (new single-line input)
209
+ constraint_exprs = request.form.getlist("constraint_expr")
210
+ constraints = [expr.strip() for expr in constraint_exprs if expr.strip()]
211
+
212
+ # Remove constraint_expr entries from payload before parsing parameters
213
+ for key in list(payload.keys()):
214
+ if key.startswith("constraint_expr"):
215
+ payload.pop(key, None)
216
+
217
+ parameters, objectives, steps = parse_optimization_form(payload)
218
+
219
+ # if True:
180
220
  try:
181
221
  datapath = current_app.config["DATA_FOLDER"]
182
222
  run_name = script.validate_function_name(run_name)
@@ -184,11 +224,14 @@ def run_bo():
184
224
  if not Optimizer:
185
225
  raise ValueError(f"Optimizer {optimizer_type} is not supported or not found.")
186
226
  optimizer = Optimizer(experiment_name=run_name, parameter_space=parameters, objective_config=objectives,
227
+ parameter_constraints = constraints,
187
228
  optimizer_config=steps, datapath=datapath)
229
+ current_app.config["LAST_OPTIMIZER"] = optimizer
188
230
  runner.run_script(script=script, run_name=run_name, optimizer=optimizer,
189
231
  logger=g.logger, socketio=g.socketio, repeat_count=repeat,
190
232
  output_path=datapath, compiled=False, history=existing_data,
191
- current_app=current_app._get_current_object()
233
+ current_app=current_app._get_current_object(), batch_size=int(batch_size),
234
+ objectives=objectives
192
235
  )
193
236
 
194
237
  except Exception as e:
@@ -198,6 +241,21 @@ def run_bo():
198
241
  flash(e.__str__())
199
242
  return redirect(url_for("execute.experiment_run"))
200
243
 
244
+ @execute.route("/executions/latest_plot")
245
+ @login_required
246
+ def get_optimizer_plot():
247
+
248
+ optimizer = current_app.config.get("LAST_OPTIMIZER")
249
+ if optimizer is not None:
250
+ # the placeholder is for showing different plots
251
+ latest_file = optimizer.get_plots('placeholder')
252
+ # print(latest_file)
253
+ if files:
254
+ return send_file(latest_file, mimetype="image/png")
255
+ # print("No plots found")
256
+ return jsonify({"error": "No plots found"}), 404
257
+
258
+
201
259
 
202
260
 
203
261
  @execute.route("/executions/status", methods=["GET"])
@@ -1,31 +1,56 @@
1
1
  {# Logging panel component for experiment run #}
2
2
  <div class="col-lg-6 col-sm-12 logging-panel">
3
- <p>
4
- <div class="p d-flex justify-content-between align-items-center">
5
- <h5>Progress:</h5>
6
- <div class="d-flex gap-2 ms-auto">
7
- <button id="pause-resume" class="btn btn-info text-white" data-bs-toggle="tooltip" title="Pause execution">
8
- {% if pause_status %}
9
- <i class="bi bi-play-circle"></i>
10
- {% else %}
11
- <i class="bi bi-pause-circle"></i>
12
- {% endif %}
13
- </button>
14
- <button id="abort-current" class="btn btn-danger text-white" data-bs-toggle="tooltip" title="Stop execution after current step">
15
- <i class="bi bi-stop-circle"></i>
16
- </button>
17
- <button id="abort-pending" class="btn btn-warning text-white" data-bs-toggle="tooltip" title="Stop execution after current iteration">
18
- <i class="bi bi-hourglass-split"></i>
19
- </button>
20
- </div>
3
+ <div class="d-flex justify-content-between align-items-center">
4
+ <h5>Progress:</h5>
5
+ <div class="d-flex gap-2 ms-auto">
6
+ <button id="pause-resume" class="btn btn-info text-white">
7
+ {% if pause_status %}
8
+ <i class="bi bi-play-circle"></i>
9
+ {% else %}
10
+ <i class="bi bi-pause-circle"></i>
11
+ {% endif %}
12
+ </button>
13
+ <button id="abort-current" class="btn btn-danger text-white">
14
+ <i class="bi bi-stop-circle"></i>
15
+ </button>
16
+ <button id="abort-pending" class="btn btn-warning text-white">
17
+ <i class="bi bi-hourglass-split"></i>
18
+ </button>
21
19
  </div>
22
- <div class="text-muted mt-2">
23
- <small><strong>Note:</strong> The current step cannot be paused or stopped until it completes. </small>
20
+ </div>
21
+ <small class="text-muted mt-2">
22
+ <strong>Note:</strong> The current step cannot be paused or stopped until it completes.
23
+ </small>
24
+ <div class="progress my-3">
25
+ <div id="progress-bar-inner" class="progress-bar progress-bar-striped progress-bar-animated"></div>
26
+ </div>
27
+ <!-- Tabs -->
28
+ <ul class="nav nav-tabs" id="logPlotTabs" role="tablist">
29
+ <li class="nav-item" role="presentation">
30
+ <button class="nav-link active" id="log-tab" data-bs-toggle="tab" data-bs-target="#log" type="button" role="tab">Log</button>
31
+ </li>
32
+ <li class="nav-item" role="presentation">
33
+ <button class="nav-link" id="plot-tab" data-bs-toggle="tab" data-bs-target="#plot" type="button" role="tab">Optimizer Plot</button>
34
+ </li>
35
+ </ul>
36
+ <div class="tab-content mt-3" id="logPlotTabsContent">
37
+ <div class="tab-pane fade show active" id="log" role="tabpanel">
38
+ <div id="logging-panel" class="border p-2 bg-light" style="max-height: 400px; overflow-y: auto;"></div>
39
+ </div>
40
+ <div class="tab-pane fade" id="plot" role="tabpanel">
41
+ <button class="btn btn-success mb-2" onclick="showPlot()">Refresh Plot</button>
42
+ <small class="text-muted d-block mt-1" id="plot-info">This function is only available for NIMO optimizers.</small>
43
+ <br>
44
+ <img id="optimizerPlot" src="" class="img-fluid rounded shadow-sm d-block mx-auto" style="max-width:100%; display:none;">
24
45
  </div>
25
46
 
26
- <div class="progress" role="progressbar" aria-label="Animated striped example" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
27
- <div id="progress-bar-inner" class="progress-bar progress-bar-striped progress-bar-animated"></div>
28
47
  </div>
29
- <p><h5>Log:</h5></p>
30
- <div id="logging-panel"></div>
31
- </div>
48
+
49
+ </div>
50
+ <script>
51
+ function showPlot() {
52
+ const img = document.getElementById('optimizerPlot');
53
+ img.src = "{{ url_for('execute.get_optimizer_plot') }}";
54
+ img.style.display = 'block';
55
+ }
56
+ </script>
@@ -1,4 +1,4 @@
1
- {# Run tabs component for experiment run #}
1
+ <!-- Main template structure -->
2
2
  <ul class="nav nav-tabs" id="myTabs" role="tablist">
3
3
  <li class="nav-item" role="presentation">
4
4
  <a class="nav-link {{ 'disabled' if config_list else '' }} {{ 'active' if not config_list else '' }}" id="tab1-tab" data-bs-toggle="tab" href="#tab1" role="tab" aria-controls="tab1" aria-selected="false">Repeat</a>
@@ -14,4 +14,47 @@
14
14
  {% include 'components/tab_repeat.html' %}
15
15
  {% include 'components/tab_configuration.html' %}
16
16
  {% include 'components/tab_bayesian.html' %}
17
- </div>
17
+ </div>
18
+
19
+ <!-- ============================================ -->
20
+ <!-- SWITCH TO THE LAST ACTIVE TAB ON PAGE LOAD -->
21
+ <!-- ============================================ -->
22
+ <script>
23
+ (function() {
24
+ 'use strict';
25
+
26
+ // Store active tab when changed
27
+ document.addEventListener('shown.bs.tab', function(e) {
28
+ const tabId = e.target.id.replace('-tab', '');
29
+ if (tabId === 'tab2' || tabId === 'tab3') {
30
+ localStorage.setItem('ivoryosLastTab', tabId);
31
+ console.log('Saved last active tab:', tabId);
32
+ }
33
+
34
+ // Optional: run specific load logic per tab
35
+ if (tabId === 'tab2' && typeof window.loadConfigData === 'function') {
36
+ window.loadConfigData();
37
+ } else if (tabId === 'tab3' && typeof window.saveBO === 'function') {
38
+ window.saveBO();
39
+ }
40
+ });
41
+
42
+ // Restore tab from last session
43
+ document.addEventListener('DOMContentLoaded', function() {
44
+ const lastTab = localStorage.getItem('ivoryosLastTab');
45
+ const tabElement = lastTab ? document.getElementById(lastTab + '-tab') : null;
46
+
47
+ if (tabElement && !tabElement.classList.contains('disabled')) {
48
+ new bootstrap.Tab(tabElement).show();
49
+ console.log('Restored last active tab:', lastTab);
50
+ } else {
51
+ // Default to first non-disabled tab
52
+ const firstTab = document.querySelector('#myTabs .nav-link:not(.disabled)');
53
+ if (firstTab) {
54
+ new bootstrap.Tab(firstTab).show();
55
+ console.log('Defaulted to first available tab.');
56
+ }
57
+ }
58
+ });
59
+ })();
60
+ </script>