Fix reset/init behaviors#168
Conversation
g-braeunlich
left a comment
There was a problem hiding this comment.
Do you really want to enforce that?
Seems like a downgrade of user-friendliness to me.
In e.g. numpy you also dont have to call seed when using a random number generator.
An other example would be jax, where afaik you always need a to provide a seed ("key"), but there, the key is supplied as an argument to the constructor (to prevent violating the invariant) and they also dont require you to call another method.
|
I agree with @g-braeunlich here that this is a big downgrade in userfriendliness, and I would in general prefer if the user never had to think about or worry about explicitly resetting anything. Are you sure you have investigated alternative options for addressing this behavior across problems, even if it means more complex back end checks on our side? I would only want to mandate using reset as a last resort. |
|
[I am thinking out loud on this. I do not have a super strong opinion. Just laying out why I chose to go for this solution] Hello there, So, we had For instance, in Beams2D, we had problems because the internal state was not properly reset between calls to optimize or simulate. This ultimately led to wrong results. We could do that automatically:
Now, in Airfoil, Seems like a good idea for users to have control over whether they want to clean up their filesystem or keep everything. My fears are essentially:
I honestly would love to discuss this and see if there is a way I do not see yet? For the comparison with Numpy; it used to be more "magic" and is now reverting to more control. Currently, it explicitly asks you to "create" (or reset 😉) the RNG, and then pass it around as a parameter in every method, or have every method/object have its own RNG. This way, you know where your RNG state is (it is not hidden inside a (global) object somewhere). Jax is a different story, as they propose a purely functional API and push for no internal mutable object state (for easy concurrency, among other things), so you are passing everything (i.e., the RNG key) as a parameter to every function. |
|
A couple of the problems, you mention before sound to me like the seed is coupled too much to other pieces of logic (i.e. output file name). I guess the As for the In any case: |
I agree there are separate concerns addressed in
This is not good. And I agree we should clarify what the intent of
Now you've got me thinking. There are several possible APIs I see. 1. Seed in constructor, folders named with seedproblem = Airfoil(seed=1)
design, _ = problem.random_design()
opt_design, history = problem.optimize(design) # creates `study_1/`
problem = Airfoil(seed=2)
obj = problem.simulate(design) # creates `study_2/`
# Now how do I clean my mess up?2. Seed in constructor, folders named with something else, e.g., timestampproblem = Airfoil(seed=1)
design, _ = problem.random_design()
opt_design, history = problem.optimize(design) # creates `study_1_YYYY_MM_DD_12:53/`
obj = problem.simulate(design) # creates `study_1_YYYY_MM_DD_12:54/`
# Same, how do I clean this up?3. Seed in reset (current proposal)Note that this is the same as 1, except you're calling reset instead of the constructor. problem = Airfoil()
problem.reset(seed=1)
design, _ = problem.random_design()
opt_design, history = problem.optimize(design) # creates `study_1/`
problem.reset(seed=2, cleanup=True) # deletes `study_1/`
obj = problem.simulate(design) # creates `study_2/` |
|
Just to be sure that you understand, why I really dont like 3.: |
4problem = Airfoil(seed=1)
design, _ = problem.random_design()
opt_design, history = problem.optimize(design) # creates `study_1/`
problem.reset(seed=2, cleanup=True) # deletes `study_1/`
obj = problem.simulate(design) # creates `study_2/` |
|
@ffelten API 4 looks good to me. I've tested the same loop as before and everything appears to work fine. |
Description
Fixes #158. This should fix weird behaviors, like users seeing
study_None/generated when instantiate the airfoil problem. The folders are now generated when callingsimulateoroptimizein airfoil.The API now sets the seed at initialization and provides a way to cleanup/reset whenever you want (which you should do in between simulations/optimizations). Pinging @arthurdrake1 on this because he resolved an issue in Beams with that; Arthur does the current API (API 4 in the comments below) work for you?
Type of change
Please delete options that are not relevant.
Checklist:
pre-commitchecks withpre-commit run --all-filesruff check .andruff formatmypy .