# How to validate two process inputs using validator?

**URL:** <https://aiida.discourse.group/t/how-to-validate-two-process-inputs-using-validator/30>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 30, 2023, 12:48pm UTC](https://aiida.discourse.group/t/how-to-validate-two-process-inputs-using-validator/30 "2023-06-30T12:48:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jusong.yu](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/jusong.yu/32/3_2.png) [@jusong.yu](https://aiida.discourse.group/u/jusong.yu)\
**Post date:** [June 30, 2023, 12:48pm UTC](https://aiida.discourse.group/t/how-to-validate-two-process-inputs-using-validator/30/1 "2023-06-30T12:48:34Z")

</div>

My workchain has inputs defined as:

```python
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](https://aiida.readthedocs.io/projects/aiida-core/en/latest/topics/processes/usage.html?highlight=validator#validation-and-defaults) is outdated, I have my validator defined as:

```python
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.`.

---

<div class="post-metadata">

**Author:** ![mbercx](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/mbercx/32/345_2.png) [@mbercx](https://aiida.discourse.group/u/mbercx)\
**Post date:** [July 2, 2023, 10:13am UTC](https://aiida.discourse.group/t/how-to-validate-two-process-inputs-using-validator/30/2 "2023-07-02T10:13:01Z")

</div>

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

> <https://github.com/aiidateam/aiida-core/issues/4509>
>
> \### Describe the current issue
> 
> The documentation on the port input validator …has not been updated to explain the change in \[this \`plumpy\` commit\](https://github.com/aiidateam/plumpy/commit/2b1a268f8d4fbcbdc40a319fee0e2cae91278382) (also see https://github.com/aiidateam/aiida-quantumespresso/pull/569#discussion\_r511504591).
> 
> 
> \### Describe the solution you'd like
> 
> Update the documentation example to the new validator signature and include an explanation on why the second argument is passed and how it should be used.

I can look into it next week. 👍

---

<div class="post-metadata">

**Author:** ![jusong.yu](https://yyz2.discourse-cdn.com/free1/user_avatar/aiida.discourse.group/jusong.yu/32/3_2.png) [@jusong.yu](https://aiida.discourse.group/u/jusong.yu)\
**Post date:** [July 10, 2023, 8:47pm UTC](https://aiida.discourse.group/t/how-to-validate-two-process-inputs-using-validator/30/3 "2023-07-10T20:47:56Z")

</div>

@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](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.

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

```
