BasePwCpInputGenerator: Improve parameters input validation#676
BasePwCpInputGenerator: Improve parameters input validation#676mbercx wants to merge 2 commits intoaiidateam:mainfrom
BasePwCpInputGenerator: Improve parameters input validation#676Conversation
First working example of how we can add validation of the input
parameters of the Quantum ESPRESSO calculation jobs by converting the
INPUT-{}.XML files that are generated for the QE documentation into JSON
schemas that are then used in the validator of the `parameters` input.
The `convert_to_json_schema()` function in the `calculations.schemas.utils.py`
module is used to generate the `calculations.schemas.pw.parameters.yaml`
file, based on the `calculations.helpers.INPUT_PW-6.4.xml` file. This
yaml file is then loaded in the validator for the `parameters` input and
used to check if the parameters adhere to the prescriptions of the JSON
schema.
|
@sphuber this is a first working example of converting an import xml, yaml
from aiida_quantumespresso.calculations.schemas.utils import convert_to_json_schema
xml_path = 'INPUT_PW-6.4.xml'
with open(xml_path, 'r') as file:
json_schema = convert_to_json_schema(xml.dom.minidom.parse(file))
with open('parameters.yaml', 'w') as file:
file.write(yaml.safe_dump(json_schema, default_flow_style=False))Currently the validation checks:
Example [1] from #675, where: builder.pw.parameters['CONTROL']['calculation'] = 'GME stock'Now gives: ValidationError: 'GME stock' is not one of ['scf', 'nscf', 'bands', 'relax', 'md', 'vc-relax', 'vc-md']
Failed validating 'enum' in schema['properties']['CONTROL']['properties']['calculation']:
{'enum': ['scf', 'nscf', 'bands', 'relax', 'md', 'vc-relax', 'vc-md'],
'type': 'string'}
On instance['CONTROL']['calculation']:
'GME stock'Example [2] from #675, where: builder.pw.parameters['CONTROL']['wf_collect'] = 'at the moon'Now gives: ValidationError: 'at the moon' is not of type 'boolean'
Failed validating 'type' in schema['properties']['CONTROL']['properties']['wf_collect']:
{'type': 'boolean'}
On instance['CONTROL']['wf_collect']:
'at the moon' |
|
And deeper down the validation rabbit hole I go... To do some basic testing of which schema accepts which parameters, I've added the Unfortunately, it turned out that e.g. taking the schema that corresponds to the latest version (6.7) doesn't validate the generated parameters by previous schemas (since inputs/options were removed) or vice versa (since inputs/options were added). So, I wanted to look into merging the JSON schemas into one that has all the inputs/options, that can be used as a default. This lead me to the Merging the So far I've just added a few schemas, and chosen the all-encompassing schema for A couple more points to hash out/work on:
|
Fixes #675
First working example of how we can add validation of the input
parameters of the Quantum ESPRESSO calculation jobs by converting the
INPUT-{}.XML files that are generated for the QE documentation into JSON
schemas that are then used in the validator of the
parametersinput.The
convert_to_json_schema()function in thecalculations.schemas.utils.pymodule is used to generate the
calculations.schemas.pw.parameters.yamlfile, based on the
calculations.helpers.INPUT_PW-6.4.xmlfile. Thisyaml file is then loaded in the validator for the
parametersinput andused to check if the parameters adhere to the prescriptions of the JSON
schema.