pyiron / pyironFlow

react xyflow for pyiron
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Issues with the conda package #17

Closed jan-janssen closed 3 weeks ago

jan-janssen commented 3 weeks ago

I use the following example code to test pyironflow:

import sys
from pathlib import Path

sys.path.insert(0, str(Path.cwd() / Path('pyiron_nodes')))

from pyiron_workflow import Workflow   
import pyiron_nodes as pn

wf = Workflow('compute_elastic_constants')
wf.engine = pn.atomistic.engine.ase.M3GNet()
wf.bulk = pn.atomistic.structure.build.Bulk('Pb', cubic=True)
wf.input_elastic = pn.atomistic.property.elastic.InputElasticTensor()
wf.elastic = pn.atomistic.property.elastic.ElasticConstants(structure=wf.bulk, engine=wf.engine, parameters=wf.input_elastic)

from pyironflow.pyironflow import PyironFlow

pf = PyironFlow(wf_list=[], root_path=str(Path.cwd() / Path('pyiron_nodes/pyiron_nodes')))
pf.gui

But I get the following error message

RuntimeError                              Traceback (most recent call last)
Cell In[8], line 1
----> 1 pf = PyironFlow(wf_list=[wf], root_path=str(Path.cwd() [/](http://localhost:8888/) Path('pyiron_nodes[/pyiron_nodes](http://localhost:8888/pyiron_nodes)')))
      2 pf.gui

File [~/mambaforge/lib/python3.12/site-packages/pyironflow/pyironflow.py:31](http://localhost:8888/~/mambaforge/lib/python3.12/site-packages/pyironflow/pyironflow.py#line=30), in PyironFlow.__init__(self, wf_list, root_path)
     29 self.out_log = widgets.Output(layout={'border': '1px solid black', 'width': '800px'})
     30 self.out_widget = widgets.Output(layout={'border': '1px solid black', 'min_width': '400px'})
---> 31 self.wf_widgets = [PyironFlowWidget(wf, log=self.out_log, out_widget=self.out_widget)
     32                    for wf in self.workflows]
     33 self.view_flows = self.view_flows()
     34 self.tree_view = TreeView(root_path=root_path, flow_widget=self.wf_widgets[0], log=self.out_log)

File [~/mambaforge/lib/python3.12/site-packages/pyironflow/reactflow.py:205](http://localhost:8888/~/mambaforge/lib/python3.12/site-packages/pyironflow/reactflow.py#line=204), in PyironFlowWidget.__init__(self, wf, log, out_widget)
    201 self.wf = wf
    203 self.gui.observe(self.on_value_change, names='commands')
--> 205 self.update()

File [~/mambaforge/lib/python3.12/site-packages/pyironflow/reactflow.py:259](http://localhost:8888/~/mambaforge/lib/python3.12/site-packages/pyironflow/reactflow.py#line=258), in PyironFlowWidget.update(self)
    258 def update(self):
--> 259     nodes = get_nodes(self.wf)
    260     edges = get_edges(self.wf)
    261     self.gui.nodes = json.dumps(nodes)

File [~/mambaforge/lib/python3.12/site-packages/pyironflow/reactflow.py:158](http://localhost:8888/~/mambaforge/lib/python3.12/site-packages/pyironflow/reactflow.py#line=157), in get_nodes(wf)
    156 def get_nodes(wf):
    157     nodes = []
--> 158     for i, (k, v) in enumerate(wf.children.items()):
    159         nodes.append(get_node_dict(v, id_num=i, key=k))
    160     return nodes

RuntimeError: dictionary changed size during iteration

In the same way, while I see the nodes in the tree view they do not appear when clicking on them.

Tara-Lakshmipathy commented 3 weeks ago

I was using 0.11 with the xyflow scripts and everything was working fine

jan-janssen commented 3 weeks ago

I was using 0.11 with the xyflow scripts and everything was working fine

Ok, good to know. Then it might be an issue related to the import path. I get the error message when I try to use the conda package which places the xyflow scripts in the python site-packages directory, so I assume there is something wrong with the way the nodes are loaded.

jan-janssen commented 3 weeks ago

I assume it is related to https://github.com/pyiron/pyironFlow/blob/main/pyironflow/treeview.py#L108C9-L108C97

 path = get_rel_path_for_last_occurrence(node.path.path, 'pyiron_nodes') / node.path.name
jan-janssen commented 3 weeks ago

@Tara-Lakshmipathy I was able to fix my issue by reverting the background color you added, as it requires your modified version of pyiron_workflow. https://github.com/pyiron/pyironFlow/pull/23