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

🐛 working_directory does not play nicely with macros #316

Open
liamhuber opened this issue May 8, 2024 · 0 comments
Open

🐛 working_directory does not play nicely with macros #316

liamhuber opened this issue May 8, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@liamhuber
Copy link
Member

liamhuber commented May 8, 2024

If you try to leverage .working_directory inside a macro definition, it is sensitive to whether or not that macro is being intialized/used with(out) a parent. This is because the working_directory leverages the semantic path to create a file path, but once created it gets frozen. So if you create then parent, the working directory will miss out on all the path stuff from the (eventual) parent. Because of the order of setup, if you pass the parent at initialization, it works ok.

Example:

If we instantiate the macro by itself, then assign it to a workflow, we get the wrong path

from pyiron_workflow import Workflow

@Workflow.wrap.as_function_node("path")
def ResolveWorkingDirectory(wd):
    return str(wd.path.resolve())

@Workflow.wrap.as_macro_node()
def UsesItsWorkingDirectory(self):
    self.path = ResolveWorkingDirectory(self.working_directory)
    return self.path

wf = Workflow("create_then_parent")
wf.m = UsesItsWorkingDirectory(label="no_parent")
wf()
>>> {'m__path': '/Users/huber/work/pyiron/notebooks/no_parent'}

Desired(???): {'m__path': '/Users/huber/work/pyiron/notebooks/create_then_parent/no_parent'}

But by passing the workflow as a parent at initialization everything is ok

wf = Workflow("parent_inside_init")
wf.m = UsesItsWorkingDirectory(label="with_parent", parent=wf)
wf()
>>> {'m__path': '/Users/huber/work/pyiron/notebooks/parent_inside_init/with_parent'}

TBH, I'm not actually sure what behaviour I want here. The working directory/semantic path interaction is not something I have totally worked out in my head yet. But the current behaviour is definitely a nasty gotcha.

@liamhuber liamhuber added the bug Something isn't working label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants