greschd / aiida-optimize

Defines AiiDA workchains that simplify running optimization workflows.
Apache License 2.0
2 stars 6 forks source link

When using CreateEvaluateWorkChain get TypeError: __reduce_ex__() takes exactly one argument (0 given) #33

Open unkcpz opened 3 years ago

unkcpz commented 3 years ago

I got an error when I using Convergence WorkChain with CreateEvaluationWorkChain to combine a WorkChain and a evaluate calcfunction process. The exception is long so I only paste part of it.

....
  File "/home/unkcpz/pyProject/aiida_core/aiida/orm/utils/serialize.py", line 118, in represent_mapping
    return dumper.represent_mapping(tag, mapping)
  File "/data/CONDA_ENV/aiida-testing38/lib/python3.8/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/home/unkcpz/pyProject/aiida_core/aiida/orm/utils/serialize.py", line 176, in represent_data
    return super().represent_data(data)
  File "/data/CONDA_ENV/aiida-testing38/lib/python3.8/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/data/CONDA_ENV/aiida-testing38/lib/python3.8/site-packages/yaml/representer.py", line 207, in represent_dict
    return self.represent_mapping('tag:yaml.org,2002:map', data)
  File "/data/CONDA_ENV/aiida-testing38/lib/python3.8/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/home/unkcpz/pyProject/aiida_core/aiida/orm/utils/serialize.py", line 176, in represent_data
    return super().represent_data(data)
  File "/data/CONDA_ENV/aiida-testing38/lib/python3.8/site-packages/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/data/CONDA_ENV/aiida-testing38/lib/python3.8/site-packages/yaml/representer.py", line 319, in represent_object
    reduce = data.__reduce_ex__(2)
TypeError: __reduce_ex__() takes exactly one argument (0 given)

I also print the data here when the exception happened. data is my WorkChain <class 'aiida_sssp_workflow.workflows.cohesive_energy.CohesiveEnergyWorkChain'> and data.__reduce__ex__(2) is <method '__reduce_ex__' of 'object' objects>.

Tagging @greschd @zooks97 for inputs. I have no idea whats going on :crying_cat_face:

unkcpz commented 3 years ago

FYI the explicit inputs of WorkChain is:

from aiida_optimize.engines._convergence import Convergence

        inputs = {
            'engine':
            Convergence,
            'engine_kwargs':
            orm.Dict(
                dict={
                    'input_values': input_values,
                    'tol': 1e-6,
                    'conv_thr': 1e-6,
                    'input_key': 'parameters.ecutwfc',
                    'result_key': 'evaluate__result.relative_diff',
                    'convergence_window': 2
                }),
            'evaluate_process':
            CreateEvaluateWorkChain,
            'evaluate':
            create_evaluate_inputs,
        }

        from aiida.engine import run
        workchain = run(OptimizationWorkChain, **inputs)
greschd commented 3 years ago

Not sure that's what's happening here, but worth a try: The inputs which are classes (e.g. Convergence, or CreateEvaluateWorkChain) are actually orm.Str inputs, and automatically serialized by aiida-optimize.

When the input is nested, this no longer works and you need to explicitly serialize it to Str, by wrapping them in aiida_tools.process_inputs.get_fullname (from https://github.com/greschd/aiida-tools/blob/master/aiida_tools/process_inputs.py#L27) .

Most probably, it's the CohesiveEnergyWorkChain inside create_evaluate_inputs that needs to be wrapped here.

unkcpz commented 3 years ago

@greschd That's true. get_fullname sove my issue. Thanks a lot!

unkcpz commented 3 years ago

BTW, maybe we can have a more explainable exception.

greschd commented 3 years ago

Yeah this is definitely too cryptic, I remember struggling for a while when I first encountered it.

Not sure if we have control over the traceback right here or if it could be improved in aiida-core.

Maybe things could also be improved w.r.t. documentation, or maybe the automatic serialization should be (slowly) deprecated to make it less surprising.

Anyway, I'll reopen for now to remind myself that this should be improved; will probably be a separate issue eventually.