아마존 브라켓 Boto3 클라이언트를 켜세요 - Amazon Braket

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

아마존 브라켓 Boto3 클라이언트를 켜세요

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

import boto3 import botocore braket = boto3.client("braket", config=botocore.client.Config(user_agent_extra="BraketSchemas/1.8.0"))

이제 braket 클라이언트가 설정되었으므로 클라이언트로부터 요청을 하고 응답을 처리할 수 있습니다.Amazon 브라켓 서비스. 요청 및 응답 데이터에 대한 자세한 내용은 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']}")