Skip to content

Commit

Permalink
Fix cmdline in hp.settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bastonero committed Apr 25, 2023
1 parent 1adcfb9 commit d821c78
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso_hp/calculations/hp.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def prepare_for_submission(self, folder):
codeinfo = CodeInfo()
codeinfo.code_uuid = self.inputs.code.uuid
codeinfo.stdout_name = self.options.output_filename
codeinfo.cmdline_params = (list(settings.pop('cmdline', [])) + ['-in', self.options.input_filename])
codeinfo.cmdline_params = (list(settings.pop('CMDLINE', [])) + ['-in', self.options.input_filename])

calcinfo = CalcInfo()
calcinfo.codes_info = [codeinfo]
Expand Down
1 change: 0 additions & 1 deletion src/aiida_quantumespresso_hp/workflows/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ def inspect_hp(self):
self.ctx.current_hubbard_structure = workchain.outputs.hubbard_structure
self.report('meta convergence is switched off, so not checking convergence of Hubbard parameters.')
self.ctx.is_converged = True
return

def check_convergence(self):
"""Check the convergence of the Hubbard parameters."""
Expand Down
13 changes: 13 additions & 0 deletions tests/calculations/test_hp.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ def test_default(fixture_sandbox_folder, generate_calc_job, generate_inputs_hp,
file_regression.check(input_written, encoding='utf-8', extension='.in')


def test_settings(fixture_sandbox_folder, generate_calc_job, generate_inputs_hp):
"""Test a default `HpCalculation` with `settings` in inputs."""
entry_point_name = 'quantumespresso.hp'

inputs = generate_inputs_hp()
cmdline_params = ['-nk', '4', '-nband', '2', '-ntg', '3', '-ndiag', '12']
inputs['settings'] = orm.Dict({'cmdline': cmdline_params})
calc_info = generate_calc_job(fixture_sandbox_folder, entry_point_name, inputs)

# Check that the command-line parameters are as expected.
assert calc_info.codes_info[0].cmdline_params == cmdline_params + ['-in', 'aiida.in']


@pytest.mark.parametrize(('parameters', 'match'), (
({
'nq1': 1
Expand Down
1 change: 1 addition & 0 deletions tests/workflows/protocols/hp/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_settings_overrides(fixture_code):
overrides = {'hp': {'settings': {'cmdline': ['--kickass-mode']}}}
builder = HpBaseWorkChain.get_builder_from_protocol(code, overrides=overrides)
assert builder.hp.settings['cmdline'] == ['--kickass-mode'] # pylint: disable=no-member
assert builder.hp.settings['parent_folder_symlink']


def test_metadata_overrides(fixture_code):
Expand Down
49 changes: 48 additions & 1 deletion tests/workflows/test_hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,33 @@ def test_should_check_convergence(generate_workchain_hubbard, generate_inputs_hu


@pytest.mark.usefixtures('aiida_profile')
def test_outline(generate_workchain_hubbard, generate_inputs_hubbard, generate_scf_workchain_node):
def test_outline_without_metaconvergence(
generate_workchain_hubbard, generate_inputs_hubbard, generate_hp_workchain_node
):
"""Test `SelfConsistentHubbardWorkChain` outline without metaconvergece.
We want to make sure the `outputs.hubbard_structure` is the last computed.
"""
from aiida.orm import Bool
inputs = generate_inputs_hubbard()
inputs['meta_convergence'] = Bool(False)
process = generate_workchain_hubbard(inputs=inputs)

process.setup()

process.ctx.workchains_hp = [generate_hp_workchain_node()]
assert process.inspect_hp() is None
assert process.ctx.is_converged

process.run_results()
assert 'hubbard_structure' in process.outputs
assert process.outputs['hubbard_structure'] == process.ctx.workchains_hp[-1].outputs['hubbard_structure']


@pytest.mark.usefixtures('aiida_profile')
def test_outline(
generate_workchain_hubbard, generate_inputs_hubbard, generate_scf_workchain_node, generate_hp_workchain_node
):
"""Test `SelfConsistentHubbardWorkChain` outline."""
from aiida.orm import Bool
inputs = generate_inputs_hubbard()
Expand Down Expand Up @@ -242,6 +268,15 @@ def test_outline(generate_workchain_hubbard, generate_inputs_hubbard, generate_s
# assert 'workchains_hp' in process.ctx
# assert len(process.ctx.workchains_hp) == 1

process.ctx.workchains_hp = [generate_hp_workchain_node()]
assert process.inspect_hp() is None
process.check_convergence()
assert process.ctx.is_converged

process.run_results()
assert 'hubbard_structure' in process.outputs
assert process.outputs['hubbard_structure'] == process.ctx.workchains_hp[-1].outputs['hubbard_structure']


@pytest.mark.usefixtures('aiida_profile')
def test_should_run_relax(generate_workchain_hubbard, generate_inputs_hubbard):
Expand Down Expand Up @@ -324,3 +359,15 @@ def test_relabel_check_convergence(

process.check_convergence()
assert not process.ctx.is_converged


@pytest.mark.usefixtures('aiida_profile')
def test_inspect_hp(generate_workchain_hubbard, generate_inputs_hubbard, generate_hp_workchain_node):
"""Test `SelfConsistentHubbardWorkChain.inspect_hp`."""
from aiida_quantumespresso_hp.workflows.hubbard import SelfConsistentHubbardWorkChain as WorkChain
inputs = generate_inputs_hubbard()
process = generate_workchain_hubbard(inputs=inputs)
process.setup()
process.ctx.workchains_hp = [generate_hp_workchain_node(exit_status=300)]
result = process.inspect_hp()
assert result == WorkChain.exit_codes.ERROR_SUB_PROCESS_FAILED_HP.format(iteration=process.ctx.iteration)

0 comments on commit d821c78

Please sign in to comment.