
Hi Yosef,
On 5/18/23 15:51, Yosef Meller wrote:
I'm trying to solve two problems consecutively in the same program. Each problem defines its own field and variables. Specifically, I do this for testing (same problem creation and operation code run consecutively with different parameters), just for the context.
You are using the imperative API, right? (*)
How do you construct the problems - is copying involved?
It fails when the second problem defines its field:
ValueError: order 0 already used!
which means that somewhere, there's a global mapping of numbers to variables which I need to clean.
Yes, each Variable checks class attributes _orders and _count.
I don't know how to do it, and if there are other such global states that need to be cleaned. So my question is whether there's some "nuke everything" function, or a checklist of things to clean, or some other way to do it?
The global ordering can be cleared by calling Variable.reset(), see sfepy/discrete/variables.py.
(*) BTW. Variables.from_conf() calls Variable.reset(), so constructing the problems in a declarative way should work.
My current workaround is to stick each run under a different process using the multiprocessing module. This works but I hope there's a less cumbersome way.
You can copy the variables, loop over them with .iter_state() and call .reset() manually - a bit less cumbersome, but not ideal. Let us know if that helps.
I will think how to get rid of the class attributes, although I am not sure how much code depends on that. I cannot recall why the ordering information is not in the Variables class, but there must have been a reason... Probably early checking, prior to putting the variables into Variables.
r.