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? (*)
Right. I know I'm a minority but at least it gets some testing, right?
How do you construct the problems - is copying involved?
No, just construction from scratch.
> 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.
[snip]
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.
using reset() on each variable through a class destructor was ok, although it would be preferable not to have to do it.
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.
Looks to me like the attempt to assign order automatically is what necessitates the static attributes. I'd put it in the Field instance so that at least it goes away with the field, but a general Variable doesn't get a Field like FieldVariable.