Skip to content

Commit

Permalink
Added file IO for options
Browse files Browse the repository at this point in the history
  • Loading branch information
d-wortmann committed Jul 4, 2024
1 parent 03bcc99 commit 6fb307e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aiida_fleur/cmdline/launch/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def launch_ssdisp(structure, inpgen, calc_parameters, fleur, wf_parameters, scf_
import json
with open("ssdisp_conv.json","w") as file:
json.dump(ssdisp_output,file,indent=2)

#TODO plotting would be nice here

@click.command('dmi')
@options.STRUCTURE_OR_FILE(default=defaults.get_fept_film_structure, show_default=True)
Expand Down
4 changes: 2 additions & 2 deletions aiida_fleur/cmdline/util/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from aiida.cmdline.params import types
from aiida.cmdline.params.options import OverridableOption
from .defaults import get_inpgen, get_fleur, get_si_bulk_structure
from .types import StructureNodeOrFileParamType,WFParameterType,RemoteType,FleurinpType
from .types import StructureNodeOrFileParamType,WFParameterType,RemoteType,FleurinpType,OptionsType

STRUCTURE_OR_FILE = OverridableOption(
'-s',
Expand Down Expand Up @@ -91,7 +91,7 @@

OPTION_NODE = OverridableOption('-opt',
'--option-node',
type=types.DataParamType(sub_classes=('aiida.data:core.dict',)),
type=OptionsType(),
help='Dict, an option node for the workchain.')

MAX_NUM_MACHINES = OverridableOption('-N',
Expand Down
49 changes: 49 additions & 0 deletions aiida_fleur/cmdline/util/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,55 @@

}

class OptionsType(click.ParamType):
"""
Type to construct options for the computational resources to use
"""
name= "options for Computational resources"
def convert(self,value,param,ctx):

wf_options_template='''{
"resources": {
"num_machines": 1, //Number of computing nodes
"num_mpiprocs_per_machine": 1, //Number of MPI processes per node
"num_cpus_per_mpiproc": 2 //Number of OMP threads per MPI process
},
"withmpi": true, //This flag makes sure that the process is submitted using MPI
"max_wallclock_seconds": 3600 //Maximum wallclock time in seconds
}'''


try:
#Perhaps a pk or uuid was given?
return types.DataParamType(sub_classes=('aiida.data:core.dict',)).convert(value, param, ctx)
except:
pass #Ok this failed, then we examine the argument as a filename

if value=="template.json":
print("Writing template to wf_options.json")
with open(f"wf_options.json","w") as f:
f.write(wf_options_template)
quit()

import os
if (os.path.isfile(value)):
# a file was given. Create a dict from the file and use it
try:
with open(value,"r") as f:
import json
from json_minify import json_minify

wf_options=json.loads(json_minify(f.read()))
except RuntimeError as error:
print(error)
print(f"{value} could not be converted into a dict")
os.abort()
aiida_dict=DataFactory("dict")
wf_dict=aiida_dict(wf_options)

return wf_dict

return None

class FleurinpType(click.ParamType):
"""
Expand Down

0 comments on commit 6fb307e

Please sign in to comment.