本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
建立並提交範例 OpenQASM 3.0 量子任務
您可以使用 Amazon Braket Python SDK、Boto3 或 AWS CLI ,將 OpenQASM 3.0 量子任務提交至 Amazon Braket 裝置。
在本節中:
OpenQASM 3.0 程式範例
若要建立 OpenQASM 3.0 任務,您可以從準備GHZ狀態
// ghz.qasm // Prepare a GHZ state OPENQASM 3; qubit[3] q; bit[3] c; h q[0]; cnot q[0], q[1]; cnot q[1], q[2]; c = measure q;
使用 Python SDK建立 OpenQASM 3.0 量子任務
您可以使用 Amazon Braket PythonSDK
with open("ghz.qasm", "r") as ghz: ghz_qasm_string = ghz.read() # import the device module from braket.aws import AwsDevice # choose the Rigetti device device = AwsDevice("arn:aws:braket:us-west-1::device/qpu/rigetti/Ankaa-2") from braket.ir.openqasm import Program program = Program(source=ghz_qasm_string) my_task = device.run(program) # You can also specify an optional s3 bucket location and number of shots, # if you so choose, when running the program s3_location = ("amzn-s3-demo-bucket", "openqasm-tasks") my_task = device.run( program, s3_location, shots=100, )
使用 Boto3 建立 OpenQASM 3.0 量子任務
您也可以使用 AWS Python SDK for Braket (Boto3)
import boto3 import json my_bucket = "amzn-s3-demo-bucket" s3_prefix = "openqasm-tasks" with open("ghz.qasm") as f: source = f.read() action = { "braketSchemaHeader": { "name": "braket.ir.openqasm.program", "version": "1" }, "source": source } device_parameters = {} device_arn = "arn:aws:braket:us-west-1::device/qpu/rigetti/Ankaa-2" shots = 100 braket_client = boto3.client('braket', region_name='us-west-1') rsp = braket_client.create_quantum_task( action=json.dumps( action ), deviceParameters=json.dumps( device_parameters ), deviceArn=device_arn, shots=shots, outputS3Bucket=my_bucket, outputS3KeyPrefix=s3_prefix, )
使用 AWS CLI 建立 OpenQASM 3.0 任務
AWS Command Line Interface (CLI)
aws braket create-quantum-task \ --region "us-west-1" \ --device-arn "arn:aws:braket:us-west-1::device/qpu/rigetti/Ankaa-2" \ --shots 100 \ --output-s3-bucket "amzn-s3-demo-bucket" \ --output-s3-key-prefix "openqasm-tasks" \ --action '{ "braketSchemaHeader": { "name": "braket.ir.openqasm.program", "version": "1" }, "source": $(cat ghz.qasm) }'