@@ -40,21 +40,81 @@ def validate_global(global_config: dict) -> list:
4040 errors = []
4141 warnings = []
4242
43- # Check machine config
44- if "machine" not in global_config :
45- errors .append ("Missing 'machine' section in global.json" )
43+ # generate_config.py writes the current, top-level APEX schema. Keep
44+ # accepting the older nested-machine schema for existing user configs.
45+ is_current_schema = any (
46+ key in global_config
47+ for key in ("dflow_host" , "context_type" , "bohrium_config" , "program_id" )
48+ )
49+
50+ if is_current_schema :
51+ for key in ("batch_type" , "context_type" ):
52+ if not global_config .get (key ):
53+ errors .append (f"Missing '{ key } ' in global.json" )
54+
55+ program_id = global_config .get ("program_id" )
56+ if not isinstance (program_id , int ) or isinstance (program_id , bool ):
57+ errors .append (
58+ "'program_id' must be an unquoted JSON integer, not a string; "
59+ "generate global.json with "
60+ "generate_config.py"
61+ )
62+ elif program_id <= 0 :
63+ errors .append ("'program_id' must be a positive integer" )
64+
65+ bohrium_config = global_config .get ("bohrium_config" )
66+ if not isinstance (bohrium_config , dict ):
67+ errors .append ("Missing 'bohrium_config' section in global.json" )
68+ else :
69+ project_id = bohrium_config .get ("project_id" )
70+ if not isinstance (project_id , int ) or isinstance (project_id , bool ):
71+ errors .append (
72+ "'bohrium_config.project_id' must be a JSON integer, "
73+ "not a quoted string"
74+ )
75+ elif project_id <= 0 :
76+ errors .append (
77+ "'bohrium_config.project_id' must be a positive integer"
78+ )
79+ elif isinstance (program_id , int ) and not isinstance (program_id , bool ):
80+ if project_id != program_id :
81+ errors .append (
82+ "'program_id' and 'bohrium_config.project_id' must match"
83+ )
84+
85+ ticket = bohrium_config .get ("ticket" )
86+ if not isinstance (ticket , str ) or not ticket .strip ():
87+ errors .append (
88+ "Missing non-empty 'bohrium_config.ticket'; regenerate "
89+ "global.json with generate_config.py"
90+ )
91+
92+ if not global_config .get ("scass_type" ):
93+ errors .append ("Missing 'scass_type' in global.json" )
94+
95+ run_commands = (
96+ "lammps_run_command" , "abacus_run_command" , "vasp_run_command"
97+ )
98+ if not any (global_config .get (key ) for key in run_commands ):
99+ errors .append (
100+ "Missing calculator run command in global.json "
101+ "(expected one of lammps_run_command, abacus_run_command, "
102+ "vasp_run_command)"
103+ )
46104 else :
47- machine = global_config ["machine" ]
48- if "batch_type" not in machine :
49- errors .append ("Missing 'machine.batch_type'" )
105+ # Legacy nested-machine schema.
106+ if "machine" not in global_config :
107+ errors .append ("Missing 'machine' section in global.json" )
108+ else :
109+ machine = global_config ["machine" ]
110+ if "batch_type" not in machine :
111+ errors .append ("Missing 'machine.batch_type'" )
50112
51- # Check resources
52- if "resources" not in global_config :
53- warnings .append ("No 'resources' section - will use defaults" )
113+ if "resources" not in global_config :
114+ warnings .append ("No 'resources' section - will use defaults" )
54115
55- # Check run_command
56- if "run_command" not in global_config :
57- errors .append ("Missing 'run_command' in global.json" )
116+ if "run_command" not in global_config :
117+ errors .append ("Missing 'run_command' in global.json" )
58118
59119 return errors , warnings
60120
0 commit comments