How to validate two process inputs using validator?

My workchain has inputs defined as:

class GeneticAlgorithmWorkChain(WorkChain):
    """WorkChain to run GA """

    # the maximum number of the best individuals not updated
    _MAX_THEBEST_COUNT = 10
    
    @classmethod
    def define(cls, spec):
        """Specify imputs and outputs"""
        super().define(spec)
        spec.input('ga_parameters', valid_type=orm.Dict, validator=validate_ga_parameters)
        spec.input('evaluate_process', help='Process which produces the result to be optimized.',
            **PROCESS_INPUT_KWARGS)
        spec.input('variable_info', valid_type=orm.Dict, validator=validate_variable_info)
        spec.input('result_key', valid_type=orm.Str)   
        spec.input_namespace('fixture_inputs', required=False, dynamic=True)

        spec.input('local_optimization_process', help='Process which produces the result to be optimized.',
            **PROCESS_INPUT_KWARGS)
        spec.input('local_optimization_parameters', valid_type=orm.Dict)

The validators are defined for ga_parameters and variable_info separately, but these two inputs may conflict with each other if not set properly, how can I validate it with validator that accept two input ports to validate?

I also find the documentation in Usage — AiiDA 2.4.0.post0 documentation is outdated, I have my validator defined as:

def validate_ga_parameters(ga_parameters):
    parameters = ga_parameters.get_dict()
    num_individuals = parameters.get('num_individuals')
    if num_individuals is None:
        return 'num_individuals is not defined'
    ....
    return None

But when I ran it, I got /home/jyu/micromamba/envs/aiida-opsp/lib/python3.9/site-packages/plumpy/ports.py:200: UserWarning: the validator validate_ga_parameters has a signature that only takes a single argument..

1 Like

Yeah, the documentation on validators is outdated, there is an open issue on this:

I can look into it next week. :+1:

@mbercx thanks!

The first part of the topic is ask about how to validate multiple input ports interact with each other. An example is the validator to spec.inputs port as https://github.com/aiidateam/aiida-quantumespresso/blob/0859d0a05c495c8a92208d118da6066f385600a7/src/aiida_quantumespresso/calculations/__init__.py#L144

The validator class method cls.validate_inputs is defined for all input ports.

    @classmethod
    def validate_inputs(cls, value, port_namespace):
        """Validate the entire inputs namespace."""