vary statement to extend values of existing variables causes crash
The vary
statement is not working when used to extend the values of a variable already existing in a model.
This problem affects the master branch, and occurs in both session and script CLI tools.
Interactive session
For the interactive session, the use of evaluated and non-evaluated variables seems to have no effect (whether the -r
flag or %start
magic have been used before or after vary
is irrelevant as the error always occurs).
If vary
is attempted, a series of error messages (see below) is printed, the session crashes, and obviously no additional models are added to the group.
In contrast, the use of vary
statement for new variables works without problems, and all corresponding models are added to the group.
The error can be reproduced by evaluating the following model (vary_test.vm) in a session:
vara = 1.0
varb = 0.5
varc = 0.25
eq1 = varb / vara
Then the model should be executed and loaded into an interactive session:
~>$ texts script -m workflow -f vary_test.vm
program UUID: some_sample_UUID
program output: >>>
n.c.
<<<
~>$ texts session -w -u some_sample_UUID
Input >
Input > vary ((vara: 2.0, 3.0))
Traceback (most recent call last):
[...]
File "/hkfs/home/project/hk-project-consulting/an9294/python_VirtEnvs/vrel-br220/lib64/python3.9/site-packages/pandas/core/reshape/merge.py", line 1508, in _maybe_coerce_merge_keys
raise ValueError(msg)
ValueError: You are trying to merge on pint[dimensionless] and object columns for key 'varc'. If you wish to proceed you should use pd.concat
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
[...]
File "/hkfs/home/project/hk-project-consulting/an9294/python_VirtEnvs/vrel-br220/lib/python3.9/site-packages/virtmat/language/utilities/errors.py", line 337, in wrapper
raise RuntimeError('non-handled exception') from err
RuntimeError: non-handled exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
[...]
File "/hkfs/home/project/hk-project-consulting/an9294/python_VirtEnvs/vrel-br220/lib/python3.9/site-packages/virtmat/language/utilities/errors.py", line 337, in wrapper
raise RuntimeError('non-handled exception') from err
RuntimeError: non-handled exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
[...]
File "/hkfs/home/project/hk-project-consulting/an9294/python_VirtEnvs/vrel-br220/lib/python3.9/site-packages/virtmat/language/utilities/errors.py", line 337, in wrapper
raise RuntimeError('non-handled exception') from err
RuntimeError: non-handled exception
~> $
A similar message is printed when vary
is used for any of the existing variables in the model.
Using the same model (and UUID) as starting point, the following example
vary` of a new variable works:
~>$ texts session -w -u some_sample_UUID
Input > vary ((vard: 'a', 'b'))
Input > %uuid
uuids: '0402dcfa6dd748e2a83f8378f9607ba2' ('0402dcfa6dd748e2a83f8378f9607ba2', '7c3e91c8234e424ca4e8ddf3d6a135e7')
Input > %hist
WAITING 2024-08-07T17:34:12+02:00 eq1 = varb / vara
WAITING 2024-08-07T17:34:12+02:00 varc = 0.25
WAITING 2024-08-07T17:34:12+02:00 varb = 0.5
WAITING 2024-08-07T17:34:12+02:00 vara = 1.0
WAITING 2024-08-07T17:37:27+02:00 vard = 'a'
Input > %vary
vary: ((vard: 'a', 'b'), ('%uuid': '0402dcfa6dd748e2a83f8378f9607ba2', '7c3e91c8234e424ca4e8ddf3d6a135e7'))
Input > %bye
Script tool
The issue can be reproduced using thie following variant of the previous script, which includes the vary
statement:
vara = 1.0
varb = 0.5
varc = 0.25
vary ((vara: 2.0, 3.0))
#vary ((vard: 'a', 'b'))
eq1 = varb / vara
If the model is executed as provided above, the following message is printed and the program crashes:
~>$ texts script -m workflow -f vary_test2.vm
Initialization error: None:1:64 --> vara = 2.0 <--
Repeated initialization of "vara"
However, if the new variable vard
is used as parameter for vary
, then the program works as expected:
~>$ texts script -m workflow -f vary_tst2.vm
program UUID: some_other_UUID
program output: >>>
n.c.
<<<
~>$ texts session -w -u some_other_UUID
Input > %uuid
uuids: '723bbcea62ca4c3dbc96870e4c062b2c' ('723bbcea62ca4c3dbc96870e4c062b2c', '066a6f3460a94086b013cdf081abb39b')
Input > %vary
vary: ((vard: 'a', 'b'), ('%uuid': '723bbcea62ca4c3dbc96870e4c062b2c', '066a6f3460a94086b013cdf081abb39b'))
Input > %hist
WAITING 2024-08-07T18:08:57+02:00 vard = 'a'
WAITING 2024-08-07T18:08:57+02:00 eq1 = varb / vara
WAITING 2024-08-07T18:08:57+02:00 varc = 0.25
WAITING 2024-08-07T18:08:57+02:00 varb = 0.5
WAITING 2024-08-07T18:08:57+02:00 vara = 1.0
Input >%bye
Strangely, the error in the session and script seem to originate from different things:
- session:
ValueError: You are trying to merge on pint[dimensionless] and object columns for key 'varc'
- script:
Repeated initialization of "vara"