-
-
Save hariby/933e705b2c96be0ff09ddf8f2b0495d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from braket.circuits import Circuit | |
from braket.aws import AwsDevice | |
from braket.tracking import Tracker | |
# function to build a GHZ state | |
def ghz_circuit(n_qubits): | |
""" | |
function to return a GHZ circuit ansatz | |
input: number of qubits | |
""" | |
# instantiate circuit object | |
circuit = Circuit() | |
# add Hadamard gate on first qubit | |
circuit.h(0) | |
# apply series of CNOT gates | |
for ii in range(0, n_qubits-1): | |
circuit.cnot(control=ii, target=ii+1) | |
return circuit | |
device = AwsDevice("arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy") | |
## | |
with Tracker() as tracker: | |
tasks = {} | |
results = {} | |
# submit tasks in parallel | |
for n_qubits in range(2,9): | |
ghz = ghz_circuit(n_qubits) | |
tasks[n_qubits] = device.run(ghz, shots=1000) | |
print('{}-qubit task {}'.format(n_qubits,tasks[n_qubits].state())) | |
print('\n') | |
print('${}'.format(tracker.qpu_tasks_cost())) | |
## | |
for n_qubits in range(2, 9): | |
# check the status of the task and wait until the task is complete | |
status = tasks[n_qubits].state() | |
while status != 'COMPLETED': | |
status = tasks[n_qubits].state() | |
results[n_qubits] = tasks[n_qubits].result() | |
# get the 'shots' parameter from metadata | |
num_shots = results[n_qubits].task_metadata.shots | |
# get the measurement counts | |
counts = results[n_qubits].measurement_counts | |
print('{}-qubit task {}.'.format(n_qubits, status)) | |
print("Measured qubits: {}".format(results[n_qubits].measured_qubits)) | |
# plot using Counter | |
plt.bar(counts.keys(), counts.values()); | |
plt.xlabel('bitstrings'); | |
plt.ylabel('counts'); | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to build GHZ state | |
def ghz_circuit_lucy(n_qubits=7): | |
""" | |
function to return GHZ circuit ansatz | |
input: number of qubits | |
""" | |
# instantiate circuit object | |
circuit = Circuit() | |
# add Hadamard gate on first qubit | |
circuit.h(0) | |
# # apply series of CNOT gates | |
# for ii in range(0, n_qubits-1): | |
# circuit.cnot(control=ii, target=ii+1) | |
circuit.cnot(0, 1).cnot(1, 2).cnot(2, 3) | |
circuit.cnot(0, 7).cnot(7, 6).cnot(6, 5) | |
return circuit | |
## | |
device = AwsDevice("arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy") | |
ghz = ghz_circuit_lucy() | |
task = device.run(ghz, shots=1000, disable_qubit_rewiring=True) | |
result = task.result() | |
counts = result.measurement_counts | |
# plot using Counter | |
plt.bar(counts.keys(), counts.values()); | |
plt.xlabel('bitstrings'); | |
plt.ylabel('counts'); | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment