DataPersistence
- braket.jobs.data_persistence.save_job_checkpoint(checkpoint_data, checkpoint_file_suffix='', data_format=PersistedJobDataFormat.PLAINTEXT)[source]
Saves the specified
checkpoint_datato the local output directory, specified by the container environment variableCHECKPOINT_DIR, with the filenamef"{job_name}(_{checkpoint_file_suffix}).json". Thejob_namerefers to the name of the current job and is retrieved from the container environment variableJOB_NAME. Thecheckpoint_datavalues are serialized to the specifieddata_format.- Note: This function for storing the checkpoints is only for use inside the job container
as it writes data to directories and references env variables set in the containers.
- Parameters:
checkpoint_data (
dict[str,Any]) – Dict that specifies the checkpoint data to be persisted.checkpoint_file_suffix (
str) – str that specifies the file suffix to be used for the checkpoint filename. The resulting filenamef"{job_name}(_{checkpoint_file_suffix}).json"is used to save the checkpoints. Default: “”data_format (
PersistedJobDataFormat) – The data format used to serialize the values. Note that forPICKLEDdata formats, the values are base64 encoded after serialization. Default: PersistedJobDataFormat.PLAINTEXT
- Raises:
ValueError – If the supplied
checkpoint_dataisNoneor empty.- Return type:
None
- braket.jobs.data_persistence.load_job_checkpoint(job_name=None, checkpoint_file_suffix='', allow_pickle=False)[source]
Loads the job checkpoint data stored for the job named ‘job_name’, with the checkpoint file that ends with the
checkpoint_file_suffix. Thejob_namecan refer to any job whose checkpoint data you expect to be available in the file path specified by theCHECKPOINT_DIRcontainer environment variable. If not provided, this function will use the currently running job’s name.- Note: This function for loading hybrid job checkpoints is only for use inside the job container
as it writes data to directories and references env variables set in the containers.
- Parameters:
job_name (
str|None) – str that specifies the name of the job whose checkpoints are to be loaded. Default: current job name.checkpoint_file_suffix (
str) – str specifying the file suffix that is used to locate the checkpoint file to load. The resulting file namef"{job_name}(_{checkpoint_file_suffix}).json"is used to locate the checkpoint file. Default: “”allow_pickle (
bool) – Whether to allow deserialization of pickled data. Pickle deserialization can execute arbitrary code and is unsafe on untrusted data. Default: False.
- Return type:
dict[str,Any]- Returns:
dict[str, Any] – Dict that contains the checkpoint data persisted in the checkpoint file.
- Raises:
FileNotFoundError – If the file
f"{job_name}(_{checkpoint_file_suffix})"could not be found in the directory specified by the container environment variableCHECKPOINT_DIR.ValueError – If the data stored in the checkpoint file can’t be deserialized (possibly due to corruption).
RuntimeError – If data is in PICKLED_V4 format and allow_pickle is False.
- braket.jobs.data_persistence.load_job_result(filename=None, allow_pickle=False)[source]
Loads job result of currently running job.
- Parameters:
filename (
str|Path|None) – Location of job results. Defaultresults.jsonin job results directory in a job instance or in working directory locally. This file must be in the format used bysave_job_result.allow_pickle (
bool) – Whether to allow deserialization of pickled data. Pickle deserialization can execute arbitrary code and is unsafe on untrusted data. Default: False.
- Return type:
dict[str,Any]- Returns:
dict[str, Any] – Job result data of current job
- Raises:
RuntimeError – If data is in PICKLED_V4 format and allow_pickle is False.
- braket.jobs.data_persistence.save_job_result(result_data, data_format=None)[source]
Saves the
result_datato the local output directory that is specified by the container environment variableAMZN_BRAKET_JOB_RESULTS_DIR, with the filename ‘results.json’. Theresult_datavalues are serialized to the specifieddata_format.- Note: This function for storing the results is only for use inside the job container
as it writes data to directories and references env variables set in the containers.
- Parameters:
result_data (
dict[str,Any] |Any) – Dict that specifies the result data to be persisted. If result data is not a dict, then it will be wrapped as{"result": result_data}.data_format (
PersistedJobDataFormat|None) – The data format used to serialize the values. Note that forPICKLEDdata formats, the values are base64 encoded after serialization. Default: PersistedJobDataFormat.PLAINTEXT.
- Raises:
TypeError – Unsupported data format.
- Return type:
None