|
14 | 14 | # See the License for the specific language governing permissions and |
15 | 15 | # limitations under the License. |
16 | 16 | # |
17 | | -from braket.aws import AwsDevice |
| 17 | +import boto3 |
| 18 | +from braket.aws import AwsDevice, AwsSession |
18 | 19 | from braket.devices import LocalSimulator |
19 | 20 | from braket.circuits import Circuit, FreeParameter |
20 | 21 |
|
21 | 22 |
|
22 | 23 | def initialize_backend(backend_config): |
23 | 24 | backend_options = backend_config["backend_options"] |
24 | 25 | 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 | + |
25 | 34 | if simulator_type == "local": |
26 | 35 | return LocalSimulator() |
27 | 36 | 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 | + ) |
29 | 41 | else: |
30 | 42 | print( |
31 | 43 | f"Simulator type '{simulator_type}' is not supported in Amazon Braket. Using default." |
32 | 44 | ) |
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 | + ) |
34 | 49 |
|
35 | 50 |
|
36 | 51 | def create_empty_circuit(num_qubits: int | None = None): |
|
0 commit comments