Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imports and namespaces #47

Open
flabowski opened this issue Feb 23, 2022 · 0 comments
Open

Imports and namespaces #47

flabowski opened this issue Feb 23, 2022 · 0 comments

Comments

@flabowski
Copy link

Hei,
I just started working with oasis and i am struggeling to see where functions and variables come from.
For me (and maybe other new users?), the code would be easier to read and to work with, if some things would be more explicit.

Here is why i think i struggle:

  • I don't know where variables come from and I cant use automated tools, because of import all statements (from xyz import *) and because of hidden imports (importlib.import_module(xyz) or exec("xyz"))
  • It is impossible to keep track of which variables change (and which do not) and where variables change. This is because the global namespace (a dictionary) holds a dictionary NS_parameters as well as all variables in there. This means the problem specific variables exist twice and they are not always the same. E.g. tstep is changes in the global namespace (passed via **vars() to other functions and methods) but does not change in NS_parameters. Sometimes NS_parameters is passed to functions and methods, sometimes the whole global namespace. Some functions change NS_parameters, some functions change the global namespace and some change both.

I think it is somehwat dangerous to work with vars(). In my fork, i would like to work with a dictionary like NS_parameters only, without having these variables in the global namespace. Also I think NS_parameters should not be passed as a whole to functions that might change it without the users knowledge.

I hope it would be easier to work with the code if I change the following in my fork:

  • use explicit imports, e.g.
import oasis.common.utilities as ut
import dolfin as df
...

instead of any from xyz import *

  • replace hidden imports, e.g.
if problemname == "Channel":
   import oasis.problems.NSfracStep.Channel as problemmod
elif problemname == "Cylinder":
   import oasis.problems.NSfracStep.Cylinder as problemmod
...

instead of

problemspec = importlib.util.find_spec(".".join(("oasis.problems.NSfracStep", problemname)))
problemmod = importlib.util.module_from_spec(problemspec)
  • remove problem specific variables from the global namespace and work with 'NS_parameters' only. All lines that quietly change variables in the global namespace, e.g. vars().update(xyz) in the main executable or globals().update(xyz) in a function or method would need to be changed.

Would oasis still work if i change it like that? Or is there a reason why all the namespaces need to be available in the main executable.
Do you think that would make sense, or do you have a different suggestion?
I am happy to change my fork that way and do a PR if you think this could be usefull in this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant