braket.jobs.data_persistence module

braket.jobs.data_persistence.save_job_checkpoint(checkpoint_data: dict[str, Any], checkpoint_file_suffix: str = '', data_format: PersistedJobDataFormat = PersistedJobDataFormat.PLAINTEXT) None[source]

Saves the specified checkpoint_data to the local output directory, specified by the container environment variable CHECKPOINT_DIR, with the filename f"{job_name}(_{checkpoint_file_suffix}).json". The job_name refers to the name of the current job and is retrieved from the container environment variable JOB_NAME. The checkpoint_data values are serialized to the specified data_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 filename f"{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 for PICKLED data formats, the values are base64 encoded after serialization. Default: PersistedJobDataFormat.PLAINTEXT

Raises:

ValueError – If the supplied checkpoint_data is None or empty.

braket.jobs.data_persistence.load_job_checkpoint(job_name: str | None = None, checkpoint_file_suffix: str = '') dict[str, Any][source]

Loads the job checkpoint data stored for the job named ‘job_name’, with the checkpoint file that ends with the checkpoint_file_suffix. The job_name can refer to any job whose checkpoint data you expect to be available in the file path specified by the CHECKPOINT_DIR container 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 name f"{job_name}(_{checkpoint_file_suffix}).json" is used to locate the checkpoint file. Default: “”

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 variable CHECKPOINT_DIR.

  • ValueError – If the data stored in the checkpoint file can’t be deserialized (possibly due to corruption).

braket.jobs.data_persistence.load_job_result(filename: str | Path | None = None) dict[str, Any][source]

Loads job result of currently running job.

Parameters:

filename (str | Path | None) – Location of job results. Default results.json in job results directory in a job instance or in working directory locally. This file must be in the format used by save_job_result.

Returns:

dict[str, Any] – Job result data of current job

braket.jobs.data_persistence.save_job_result(result_data: dict[str, Any] | Any, data_format: PersistedJobDataFormat | None = None) None[source]

Saves the result_data to the local output directory that is specified by the container environment variable AMZN_BRAKET_JOB_RESULTS_DIR, with the filename ‘results.json’. The result_data values are serialized to the specified data_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 for PICKLED data formats, the values are base64 encoded after serialization. Default: PersistedJobDataFormat.PLAINTEXT.

Raises:

TypeError – Unsupported data format.