---
# System prepended metadata

title: Some key issue to be discussed related to WorkGraph (previous WorkTree)

---

# Some key issue to be discussed related to WorkGraph (previous WorkTree)



## Checking point



### Make sure it save the checkpoint every time a node is finished
How do I read/list the histroy checkpoints?
How do I debug the checkpoint?


```python
from aiida.engine.persistence import AiiDAPersister
bundle = AiiDAPersister().load_checkpoint(157938)
p = bundle.unbundle()
```


```python
def _do_step(self) -> t.Any:
        """Execute the next step in the workgraph and return the result.

        If any awaitables were created, the process will enter in the Wait state,
        otherwise it will go to Continue.
        """
        # we will not remove the awaitables here,
        # we resume the workgraph in the callback function even
        # there are some awaitables left
        # self._awaitables = []
        from aiida.orm.utils.serialize import deserialize_unsafe
        result: t.Any = None
        self.report("do_step.")
        

        try:
            self.continue_workgraph()
        except _PropagateReturn as exception:
            finished, result = True, exception.exit_code
        else:
            finished, result = self.is_workgraph_finished()

        self.report("state: {}".format(self.node.process_state))
        checkpoints = deserialize_unsafe(self.node.base.attributes.get("checkpoints"))
        print("checkpoints: ", checkpoints.keys())
        node_states = {key: ndata["state"] for key, ndata in checkpoints["CONTEXT"].get("nodes", {}).items()}
        print("node_states: ", node_states)
        print("!!meta: ", checkpoints["!!meta"].keys())
        # If the workgraph is finished or the result is an ExitCode, we exit by returning
        if finished:
            if isinstance(result, ExitCode):
                return result
            else:
                return self.finalize()

        if self._awaitables:
            return Wait(self._do_step, "Waiting before next step")

        return Continue(self._do_step)
```


### What's data is allowed in the ctx

Is binary data (from pickle) can be serialized and deserialized?

Yes

Note: I saved pickle data to `base.extras`. When I read it back from `base.extras`, it became a list of integer, so I need run
`byte(data)` to get the binary data back? Can this be automaticly handled in the checkpoint? How do I debug?



## Calcfunction dynamic namespace (input and output)
WorkChain supports multiple dynamic namespaces, which is very convenient. How calcfunction only support one dynamic input port, and one dynamic output port.

```python=
from aiida.engine import calcfunction

@calcfunction
def add(x, **data, **kwargs):
    return {"sum": x + y, "minus": x-y}

@node(outputs = [["sum", "minus"]])
def add(x, y):
    return x+y, x-y

spec = add.spec()
spec.inputs.ports

# output ports is not defined before
spec.outputs.ports
```


## Pause a node





