in google_cloud_automlops/utils/utils.py [0:0]
def stringify_job_spec_list(job_spec_list: list) -> list:
"""Takes in a list of job spec dictionaries and turns them into strings.
Args:
job_spec (list): Dictionary with job spec info. e.g.
custom_training_job_specs = [{
'component_spec': 'train_model',
'display_name': 'train-model-accelerated',
'machine_type': 'a2-highgpu-1g',
'accelerator_type': 'NVIDIA_TESLA_A100',
'accelerator_count': 1
}]
Returns:
list[str]: Python formatted dictionary code.
"""
if not job_spec_list:
return None
output = []
for spec in job_spec_list:
mapping = {}
if isinstance(spec['component_spec'], str):
mapping['component_spec'] = spec['component_spec']
else:
raise ValueError('component_spec must be a string.')
# Remove string quotes from component spec line
mapping['spec_string'] = json.dumps(spec, sort_keys=True, indent=8).replace(f'''"{spec['component_spec']}"''', f'''{spec['component_spec']}''')
mapping['spec_string'] = mapping['spec_string'].replace('}', ' }') # align closing bracket
output.append(mapping)
return output