View a markdown version of this page

Crea e invia un esempio di task quantistico OpenQASM 3.0 - Amazon Braket

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Crea e invia un esempio di task quantistico OpenQASM 3.0

Puoi utilizzare Amazon Braket Python SDK, Boto3 o per inviare attività quantistiche OpenQASM 3.0 AWS CLI a un dispositivo Amazon Braket.

Un esempio di programma OpenQASM 3.0

Per creare un'attività OpenQASM 3.0, è possibile iniziare con un programma OpenQASM 3.0 di base (ghz.qasm) che prepara uno stato GHZ, come mostrato nell'esempio seguente.

// 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;

Usa Python SDK per creare attività quantistiche OpenQASM 3.0

Puoi utilizzare l'SDK Amazon Braket Python per inviare questo programma a un dispositivo Amazon Braket con il seguente codice. Assicurati di sostituire l'esempio di posizione del bucket Amazon S3 «amzn-s3-demo-bucket» con il tuo nome di bucket Amazon S3.

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-3") from braket.ir.openqasm import Program program = Program(source=ghz_qasm_string) my_task = device.run(program) # Specify an optional s3 bucket location and number of shots s3_location = ("amzn-s3-demo-bucket", "openqasm-tasks") my_task = device.run( program, s3_location, shots=100, )

Usa Boto3 per creare attività quantistiche OpenQASM 3.0

Puoi anche usare AWS Python SDK for Braket (Boto3) per creare i task quantistici usando le stringhe OpenQASM 3.0, come mostrato nell'esempio seguente. Il seguente frammento di codice fa riferimento a ghz.qasm che prepara uno stato GHZ come mostrato sopra.

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-3" 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, )

Usa il AWS CLI per creare attività OpenQASM 3.0

La AWS Command Line Interface (CLI) può essere utilizzata anche per inviare programmi OpenQASM 3.0, come mostrato nell'esempio seguente.

aws braket create-quantum-task \ --region "us-west-1" \ --device-arn "arn:aws:braket:us-west-1::device/qpu/rigetti/Ankaa-3" \ --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) }'