Nyalakan klien Amazon Braket Boto3 - Amazon Braket

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Nyalakan klien Amazon Braket Boto3

Untuk menggunakan Boto3 dengan Amazon Braket, Anda harus mengimpor Boto3 dan kemudian menentukan klien yang Anda gunakan untuk terhubung ke Amazon Braket. API Dalam contoh berikut, klien Boto3 diberi nama. braket

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

Sekarang karena Anda memiliki klien braket yang telah ditetapkan, Anda dapat membuat permintaan dan tanggapan proses dari layanan Amazon Braket. Anda bisa mendapatkan detail lebih lanjut tentang permintaan dan data tanggapan di Referensi API.

Mencari perangkat

  • search_devices(**kwargs)

Cari perangkat menggunakan filter yang ditentukan.

# 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'])

Ambil perangkat

  • get_device(deviceArn)

Ambil perangkat yang tersedia di 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']}")

Membuat tugas kuantum

  • create_quantum_task(**kwargs)

Buat tugas kuantum.

# 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")

Mengambil tugas kuantum

  • get_quantum_task(quantumTaskArn)

Ambil tugas kuantum yang ditentukan.

# 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'])

Mencari tugas kuantum

  • search_quantum_tasks(**kwargs)

Cari tugas kuantum yang cocok dengan nilai filter yang ditentukan.

# 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']}")

Batalkan tugas kuantum

  • cancel_quantum_task(quantumTaskArn)

Batalkan tugas kuantum yang ditentukan.

# 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']}")