Skip to content

Commit

Permalink
update json format
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Fievet committed Aug 30, 2024
1 parent 564e8dc commit a2b76c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
14 changes: 1 addition & 13 deletions LIReC/jobs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@
},
'run_async': True,
'async_cores': 2
}),#,
#'poly_pslq_v2', {
# 'args': {
# 'degree': 2, 'order': 1,
# 'min_precision': 50, 'min_roi': 2,
# 'testing_precision': 15, # replaces min_precision when fed to pslq
# 'bulk': 10, # if testing lots of constants, can instead limit discovery to 'bulk' constants at a time until no relevant relation is found, then another 'bulk' constants are added
# #'filters': { # the existence of filters disables antirelation logging
# # 'PcfCanonical': { 'balanced_only': True }
# #}
# },
# 'run_async': True,
# 'iterations': 1
})
]
}
46 changes: 16 additions & 30 deletions LIReC/jobs/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,27 @@
MOD_PATH = 'LIReC.jobs.job_%s'

def validate_config(config):
if not isinstance(config, dict):
return False, "Configuration should be a dictionary."

if 'jobs_to_run' not in config:
return False, "Missing 'jobs_to_run' key in configuration."

if not isinstance(config['jobs_to_run'], list):
return False, "'jobs_to_run' should be a list."
if "jobs_to_run" not in config or not isinstance(config['jobs_to_run'], list):
return False, "Invalid configuration: Missing or incorrect 'jobs_to_run'"

for job in config['jobs_to_run']:
if not isinstance(job, tuple) or len(job) != 2:
return False, "'jobs_to_run' should contain tuples of (job_name, job_info)."
if not isinstance(job, list) or len(job) != 2:
return False, "Each job must be a list containing two elements"

job_name, job_info = job
job_name, job_details = job
if not isinstance(job_name, str):
return False, "Job name should be a string."

if not isinstance(job_info, dict):
return False, "Job info should be a dictionary."
return False, "Job name must be a string"

required_keys = {'args', 'run_async', 'async_cores'}
if not all(key in job_info for key in required_keys):
return False, "Missing required keys in job info."
if not isinstance(job_details, dict):
return False, "Job details must be a dictionary"

args = job_info['args']
if not isinstance(args, dict):
return False, "'args' should be a dictionary."
# Check required keys in job_details
required_keys = ["args", "run_async", "async_cores"]
for key in required_keys:
if key not in job_details:
return False, f"Missing key '{key}' in job details"

expected_args_keys = {'degree', 'order', 'bulk', 'filters'}
if not all(key in args for key in expected_args_keys):
return False, "Missing required keys in args."

filters = args['filters']
if not isinstance(filters, dict):
return False, "'filters' should be a dictionary."

# Further checks can be added for filters' inner structure if necessary
# Additional detailed checks can be implemented here as needed

return True, "Configuration is valid."

Expand Down Expand Up @@ -98,6 +82,8 @@ def main() -> None:
job_config = json.load(file)
logger.info("Loaded job configuration: %s", json.dumps(job_config, indent=4))
valid, message = validate_config(job_config)
job_config['jobs_to_run'] = [tuple(job) for job in job_config['jobs_to_run']]

logger.info("validate_config job configuration: %s", message)
if valid:
config_data = job_config
Expand Down

0 comments on commit a2b76c3

Please sign in to comment.