Amazon Braket SDK からの量子タスクの追跡 - Amazon Braket

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Amazon Braket SDK からの量子タスクの追跡

コマンドは、一意の量子タスク ID を持つ量子タスクdevice.run(…​)を定義します。次の例に示すように、task.state() を使用してステータスを照会および追跡できます。

: task = device.run()は非同期オペレーションです。つまり、システムが量子タスクをバックグラウンドで処理している間も動作し続けることができます。

結果を取得する

を呼び出すとtask.result()、SDK は Amazon Braket のポーリングを開始し、量子タスクが完了したかどうかを確認します。SDK は、.run() で定義したポーリングパラメータを使用します。量子タスクが完了すると、SDK は S3 バケットから結果を取得し、QuantumTaskResultオブジェクトとして返します。

# create a circuit, specify the device and run the circuit circ = Circuit().rx(0, 0.15).ry(1, 0.2).cnot(0,2) device = AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1") task = device.run(circ, s3_location, shots=1000) # get ID and status of submitted task task_id = task.id status = task.state() print('ID of task:', task_id) print('Status of task:', status) # wait for job to complete while status != 'COMPLETED': status = task.state() print('Status:', status)
ID of task: arn:aws:braket:us-west-2:123412341234:quantum-task/b68ae94b-1547-4d1d-aa92-1500b82c300d Status of task: QUEUED Status: QUEUED Status: QUEUED Status: QUEUED Status: QUEUED Status: QUEUED Status: QUEUED Status: QUEUED Status: RUNNING Status: RUNNING Status: COMPLETED

量子タスクをキャンセルする

量子タスクをキャンセルするには、次の例に示すように、 cancel()メソッドを呼び出します。

# cancel quantum task task.cancel() status = task.state() print('Status of task:', status)
Status of task: CANCELLING

メタデータの確認

次の例に示すように、完成した量子タスクのメタデータを確認できます。

# get the metadata of the quantum task metadata = task.metadata() # example of metadata shots = metadata['shots'] date = metadata['ResponseMetadata']['HTTPHeaders']['date'] # print example metadata print("{} shots taken on {}.".format(shots, date)) # print name of the s3 bucket where the result is saved results_bucket = metadata['outputS3Bucket'] print('Bucket where results are stored:', results_bucket) # print the s3 object key (folder name) results_object_key = metadata['outputS3Directory'] print('S3 object key:', results_object_key) # the entire look-up string of the saved result data look_up = 's3://'+results_bucket+'/'+results_object_key print('S3 URI:', look_up)
1000 shots taken on Wed, 05 Aug 2020 14:44:22 GMT. Bucket where results are stored: amazon-braket-123412341234 S3 object key: simulation-output/b68ae94b-1547-4d1d-aa92-1500b82c300d S3 URI: s3://amazon-braket-123412341234/simulation-output/b68ae94b-1547-4d1d-aa92-1500b82c300d

量子タスクまたは結果を取得する

量子タスクを送信した後、またはノートブックまたはコンピュータを閉じた後にカーネルが死亡した場合、一意の ARN (量子タスク ID) を使用してtaskオブジェクトを再構築できます。次に task.result() を呼び出して、保存されている S3 バケットから結果を取得します。

from braket.aws import AwsSession, AwsQuantumTask # restore task with unique arn task_load = AwsQuantumTask(arn=task_id) # retrieve the result of the task result = task_load.result()