outerport / paramit

Parameterize Python scripts/notebooks all from the command line and run on cloud GPUs
Apache License 2.0
94 stars 10 forks source link

Operations done to variable trigger exceptions #78

Open squidrice21 opened 2 months ago

squidrice21 commented 2 months ago

I'm running version 0.2.1. It seems that paramit can't ignore operations done to an input variable. E.g., run this:

import os

a = 'precomputed.npy'
b = 20

if not os.path.exists(a):
    a = f'precomputed_{b}' + '.npy'

triggers this:

Traceback (most recent call last):
  File "/home/envs/testenv/bin/paramit", line 8, in <module>
    sys.exit(main())
  File "/home/envs/testenv/lib/python3.9/site-packages/paramit/cli/__init__.py", line 695, in main
    modified_tree = set_global_variables_from_config(
  File "/home/envs/testenv/lib/python3.9/site-packages/paramit/cli/__init__.py", line 289, in set_global_variables_from_config
    modified_tree = wrapper.visit(transformer)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/metadata/wrapper.py", line 204, in visit
    return self.module.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/module.py", line 89, in visit
    result = super(Module, self).visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/module.py", line 74, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/statement.py", line 616, in _visit_and_replace_children
    body=visit_required(self, "body", self.body, visitor),
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 81, in visit_required
    result = node.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/statement.py", line 698, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 227, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/statement.py", line 443, in _visit_and_replace_children
    body=visit_sequence(self, "body", self.body, visitor),
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 177, in visit_sequence
    return tuple(visit_iterable(parent, fieldname, children, visitor))
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/internal.py", line 159, in visit_iterable
    new_child = child.visit(visitor)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_nodes/base.py", line 236, in visit
    leave_result = visitor.on_leave(self, with_updated_children)
  File "/home/envs/testenv/lib/python3.9/site-packages/libcst/_visitors.py", line 71, in on_leave
    updated_node = leave_func(original_node, updated_node)
  File "/home/envs/testenv/lib/python3.9/site-packages/paramit/cli/__init__.py", line 197, in leave_Assign
    raise ValueError(
ValueError: Unsupported type <class 'str'>, <class 'libcst._nodes.expression.BinaryOperation'>
squidrice21 commented 2 months ago

Similarly, local and global variables can also cause problems:

a = 10
c = 40

def a2c(a):
    c = a / 2
    return c