amazon-braket / amazon-braket-sdk-python

A Python SDK for interacting with quantum devices on Amazon Braket
https://aws.amazon.com/braket/
Apache License 2.0
294 stars 118 forks source link

from_ir method for AnalogHamiltonianSimulation #971

Closed peterkomar-aws closed 1 month ago

peterkomar-aws commented 1 month ago

Describe the feature you'd like The braket.ahs.AnalogHamiltonianSimulation object has a to_ir method to export its content in the format of braket.ir.ahs.Program, but no from_ir method, which would load the content of an braket.ir.ahs.Program object into a braket.ahs.AnalogHamiltonianSimulation object. Let's create this method so AHS programs can be worked with similarly to circuits (See braket.circuits.Circuit.from_ir)

How would this feature be used? Please describe. There are two common use cases:

  1. We start from a results.json file, which is created by the Braket service after successfully running an AHS program. The metadata content of such a file contains the ahs program that was run and it can be loaded as a braket.ir.ahs.Program object, after which we can call braket.ahs.AnalogHamiltonianSimulation.from_ir() to create the AHS program in the Braket SDK's abstractions. This allows us to modify and inspect it using the utilities in the Braket SDK.

  2. We start from an ahs_program.json file, which we created previously when we serialized by braket.ahs.AnalogHamiltonianSimulation object with my_ahs_program.to_ir().json(), and written to a file. At a later point, we read the json file to a dict json_dict and recreate the AHS object with my_ahs_prgram = AnalogHamiltonianSimulation.from_ir(Program(json_dict)).

Describe alternatives you've considered The alternative is to develop utilities to edit and inspect a braket.ir.ahs.Program object, instead of the already established standard representation braket.ahs.AnalogHamiltonianSimulation.

king-p3nguin commented 1 month ago

Hi, I would like to work on this issue for unitaryhack.

peterkomar-aws commented 1 month ago

https://github.com/amazon-braket/amazon-braket-sdk-python/pull/983 resolves this issue. Thank you, @king-p3nguin