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
    def define(cls, spec):
        """Specify imputs and outputs"""
        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.',
        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.',
        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/ 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

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

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