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

Multiple steps in if_ WorkChain block will lead to corrupted stepper in pickle #902

Closed
sphuber opened this issue Nov 8, 2017 · 2 comments
Assignees
Labels
Milestone

Comments

@sphuber
Copy link
Contributor

sphuber commented Nov 8, 2017

When pickling a WorkChain which contains an if_ block with more than one line in the block body, the stepper will be written incorrectly, leading to the pickle being corrupt. When trying to recreate the Process with create_from() the method will fail.
A minimal example to demonstrate this problem is the following:

class ParentWorkChain(WorkChain):

    @classmethod
    def define(cls, spec):
        super(ParentWorkChain, cls).define(spec)
        spec.outline(
            cls.step,
            cls.resulta
        )

    def step(self):
        running = submit(SubWorkChain)
        self.report('Submitted {}<{}>'.format(SubWorkChain.__name__, running.pid))
        return ToContext(sub=running)

    def resulta(self):
        self.report('ParentWorkChain finished')

class SubWorkChain(WorkChain):

    @classmethod
    def define(cls, spec):
        super(SubWorkChain, cls).define(spec)
        spec.outline(
            if_(cls.conditional)(
                cls.do_print,
                cls.do_print,
            ),
            cls.step
        )

    def conditional(self):
        return True

    def do_print(self):
        self.report('testing')

    def step(self):
        self.report('BaseWorkChain running')

run(ParentWorkChain)

The ParentWorkChain will submit the SubWorkChain causing it to be pickled. Since the SubWorkChain has two steps in the block body of the conditional, the saved state in the pickle will contain a corrupted or incomplete stepper. If you remove one of the two cls.do_print calls from the outline of the SubWorkChain everything works expected. The same goes for simply running the SubWorkChain directly in which case of course there is no pickling going on.

@sphuber sphuber added topic/workflows type/bug priority/critical-blocking must be resolved before next release labels Nov 8, 2017
@sphuber sphuber added this to the v0.10.0 milestone Nov 8, 2017
@sphuber
Copy link
Contributor Author

sphuber commented Nov 8, 2017

I loaded up one of the corrupted pickles produced by the example workchains above and printed the stepper_state which prints the following:

with open('2348.pickle', 'r') as handle:
    cp = pickle.load(handle)
print cp['stepper_state']

<Bundle {'stepper_pos': <Bundle {'stepper_pos': <Bundle {'pos': 1}>, 'pos': 1}>, 'pos': 3}>

I think the problem is that the logic for saving the stepper state of _If instructions or the loading thereof is incomplete or broken.

@sphuber
Copy link
Contributor Author

sphuber commented Nov 9, 2017

Fixed in #904

@sphuber sphuber closed this as completed Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants