Skip to content

add state reinitialization to reset function#161

Merged
ffelten merged 1 commit into
mainfrom
fix/beams2d_reset
Aug 27, 2025
Merged

add state reinitialization to reset function#161
ffelten merged 1 commit into
mainfrom
fix/beams2d_reset

Conversation

@arthurdrake1
Copy link
Copy Markdown
Contributor

Please check and merge as needed. This simply allows for us to reset the problem state within a loop of simulating different beam designs. There was previously no way visible to the user to reset this state, leading to false simulated compliance after one loop iteration.

from engibench.utils.all_problems import BUILTIN_PROBLEMS
import numpy as np

problem_id: str = "beams2d"
seed: int = 1

problem = BUILTIN_PROBLEMS[problem_id]()

data = problem.dataset

train_ds = data["train"]
test_ds = data["test"]
val_ds = data["val"]

# Simulate all designs in the train, test, and validation datasets
dataset = test_ds
for i in range(len(dataset['optimal_design'])):
    problem.reset(seed=seed)
    result = problem.simulate(np.array(dataset['optimal_design'][i]), config = dataset.select_columns(problem.conditions_keys)[i])
    _, opt_history = problem.optimize(np.array(dataset['optimal_design'][i]), config = dataset.select_columns(problem.conditions_keys)[i])
    print("Dataset_Val: {:>10.2f}".format(dataset['c'][i]),
          "Re-Optimize_Val: {:>10.2f}".format(opt_history[-1].obj_values[0]),
          "Simulate_Val: {:>10.2f}".format(result[0]))

Comment thread engibench/problems/beams2d/v0.py
@ffelten ffelten merged commit c4877df into main Aug 27, 2025
10 checks passed
@ffelten ffelten deleted the fix/beams2d_reset branch August 27, 2025 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants