Amazon Braket Boto3 클라이언트 켜기 - Amazon Braket

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon Braket Boto3 클라이언트 켜기

Amazon Braket에서 Boto3를 사용하려면 Boto3를 가져온 다음 Amazon Braket에 연결하는 데 사용하는 클라이언트를 정의해야 합니다API. 다음 예제에서 Boto3 클라이언트의 이름은 입니다braket.

import boto3 import botocore braket = boto3.client("braket")
참고

Braket은 IPv6를 지원합니다. IPv6-only 네트워크를 사용하거나 워크로드가 IPv6 트래픽을 사용하도록 하려면 듀얼 스택 및 FIPS 엔드포인트 가이드에 설명된 대로 듀얼 스택 엔드포인트를 사용합니다.

이제 braket 클라이언트를 설정했으므로 Amazon Braket 서비스에서 요청을 하고 응답을 처리할 수 있습니다. API 참조에서 요청 및 응답 데이터에 대한 자세한 내용을 확인할 수 있습니다.

다음 예제에서는 디바이스 및 양자 작업으로 작업하는 방법을 보여줍니다.

디바이스 검색

  • search_devices(**kwargs)

지정된 필터를 사용하여 디바이스를 검색합니다.

# Pass search filters and optional parameters when sending the # request and capture the response response = braket.search_devices(filters=[{ 'name': 'deviceArn', 'values': ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] }], maxResults=10) print(f"Found {len(response['devices'])} devices") for i in range(len(response['devices'])): device = response['devices'][i] print(device['deviceArn'])

디바이스 검색

  • get_device(deviceArn)

Amazon Braket에서 사용 가능한 디바이스를 검색합니다.

# Pass the device ARN when sending the request and capture the repsonse response = braket.get_device(deviceArn='arn:aws:braket:::device/quantum-simulator/amazon/sv1') print(f"Device {response['deviceName']} is {response['deviceStatus']}")

양자 작업 생성

  • create_quantum_task(**kwargs)

양자 작업을 생성합니다.

# Create parameters to pass into create_quantum_task() kwargs = { # Create a Bell pair 'action': '{"braketSchemaHeader": {"name": "braket.ir.jaqcd.program", "version": "1"}, "results": [], "basis_rotation_instructions": [], "instructions": [{"type": "h", "target": 0}, {"type": "cnot", "control": 0, "target": 1}]}', # Specify the SV1 Device ARN 'deviceArn': 'arn:aws:braket:::device/quantum-simulator/amazon/sv1', # Specify 2 qubits for the Bell pair 'deviceParameters': '{"braketSchemaHeader": {"name": "braket.device_schema.simulators.gate_model_simulator_device_parameters", "version": "1"}, "paradigmParameters": {"braketSchemaHeader": {"name": "braket.device_schema.gate_model_parameters", "version": "1"}, "qubitCount": 2}}', # Specify where results should be placed when the quantum task completes. # You must ensure the S3 Bucket exists before calling create_quantum_task() 'outputS3Bucket': 'amazon-braket-examples', 'outputS3KeyPrefix': 'boto-examples', # Specify number of shots for the quantum task 'shots': 100 } # Send the request and capture the response response = braket.create_quantum_task(**kwargs) print(f"Quantum task {response['quantumTaskArn']} created")

양자 작업 검색

  • get_quantum_task(quantumTaskArn)

지정된 양자 작업을 검색합니다.

# Pass the quantum task ARN when sending the request and capture the response response = braket.get_quantum_task(quantumTaskArn='arn:aws:braket:us-west-1:123456789012:quantum-task/ce78c429-cef5-45f2-88da-123456789012') print(response['status'])

양자 작업 검색

  • search_quantum_tasks(**kwargs)

지정된 필터 값과 일치하는 양자 작업을 검색합니다.

# Pass search filters and optional parameters when sending the # request and capture the response response = braket.search_quantum_tasks(filters=[{ 'name': 'deviceArn', 'operator': 'EQUAL', 'values': ['arn:aws:braket:::device/quantum-simulator/amazon/sv1'] }], maxResults=25) print(f"Found {len(response['quantumTasks'])} quantum tasks") for n in range(len(response['quantumTasks'])): task = response['quantumTasks'][n] print(f"Quantum task {task['quantumTaskArn']} for {task['deviceArn']} is {task['status']}")

양자 작업 취소

  • cancel_quantum_task(quantumTaskArn)

지정된 양자 작업을 취소합니다.

# Pass the quantum task ARN when sending the request and capture the response response = braket.cancel_quantum_task(quantumTaskArn='arn:aws:braket:us-west-1:123456789012:quantum-task/ce78c429-cef5-45f2-88da-123456789012') print(f"Quantum task {response['quantumTaskArn']} is {response['cancellationStatus']}")