Skip to content

Commit 0c7ed0e

Browse files
authored
feat: Add AWS session support for backend initialization in Amazon Braket (#976)
1 parent 73bd367 commit 0c7ed0e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

qumat/amazon_braket_backend.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,38 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
from braket.aws import AwsDevice
17+
import boto3
18+
from braket.aws import AwsDevice, AwsSession
1819
from braket.devices import LocalSimulator
1920
from braket.circuits import Circuit, FreeParameter
2021

2122

2223
def initialize_backend(backend_config):
2324
backend_options = backend_config["backend_options"]
2425
simulator_type = backend_options.get("simulator_type", "default")
26+
region = backend_options.get("region")
27+
28+
# Create AWS session with region if specified
29+
aws_session = None
30+
if region:
31+
boto_session = boto3.Session(region_name=region)
32+
aws_session = AwsSession(boto_session=boto_session)
33+
2534
if simulator_type == "local":
2635
return LocalSimulator()
2736
elif simulator_type == "default":
28-
return AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
37+
return AwsDevice(
38+
"arn:aws:braket:::device/quantum-simulator/amazon/sv1",
39+
aws_session=aws_session,
40+
)
2941
else:
3042
print(
3143
f"Simulator type '{simulator_type}' is not supported in Amazon Braket. Using default."
3244
)
33-
return AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
45+
return AwsDevice(
46+
"arn:aws:braket:::device/quantum-simulator/amazon/sv1",
47+
aws_session=aws_session,
48+
)
3449

3550

3651
def create_empty_circuit(num_qubits: int | None = None):

0 commit comments

Comments
 (0)