I am challenging Amazon Braket to motivate me to create blueqatSDK.
Actually, I haven't used it much.
First of all, I'm going to make a entangled circuit as a preparatory exercise.
from braket.circuits import Circuit
from braket.devices import LocalSimulator
import matplotlib.pyplot as plt
%matplotlib inline
First, let's draw the circuit.
bell = Circuit().h(0).cnot(0,1)
print(bell)
T : |0|1|
q0 : -H-C-
|
q1 : ---X-
T : |0|1|
Next, let's try the calculation using a local simulator.
#device
device = LocalSimulator()
result = device.run(bell, shots=10).result()
#result
counts = result.measurement_counts
print(counts)
#draw hystogram
# plot using Counter
plt.bar(counts.keys(), counts.values());
Counter({'00': 7, '11': 3})
<Figure size 432x288 with 1 Axes>
It's done. That's pretty easy. Next, I would like to use the actual machine. The actual machine should have different gates that it is good at depending on the type. In reality, the transpiler converts the gates, so I don't think there will be any problem, but just in case, let's take a look.
Let's start with IonQ. It is an ion trap type.
from braket.aws import AwsDevice
device = AwsDevice("arn:aws:braket:::device/qpu/ionq/ionQdevice")
print(device.properties.action['braket.ir.jaqcd.program'].supportedOperations)
['x', 'y', 'z', 'rx', 'ry', 'rz', 'h', 'cnot', 's', 'si', 't', 'ti', 'v', 'vi', 'xx', 'yy', 'zz', 'swap', 'i']
Next we will look at Lucy from OQC in the UK.
device = AwsDevice("arn:aws:braket:eu-west-2::device/qpu/oqc/Lucy")
print(device.properties.action['braket.ir.jaqcd.program'].supportedOperations)
['ccnot', 'cnot', 'cphaseshift', 'cswap', 'cy', 'cz', 'h', 'i', 'phaseshift', 'rx', 'ry', 'rz', 's', 'si', 'swap', 't', 'ti', 'v', 'vi', 'x', 'y', 'z', 'ecr', 'start_verbatim_box', 'end_verbatim_box']
And Rigetti is now available during the daytime Japan time.
device = AwsDevice("arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-2")
print(device.properties.action['braket.ir.jaqcd.program'].supportedOperations)
['cz', 'xy', 'ccnot', 'cnot', 'cphaseshift', 'cphaseshift00', 'cphaseshift01', 'cphaseshift10', 'cswap', 'h', 'i', 'iswap', 'phaseshift', 'pswap', 'rx', 'ry', 'rz', 's', 'si', 'swap', 't', 'ti', 'x', 'y', 'z', 'start_verbatim_box', 'end_verbatim_box']
Next is D-Wave. It is an annealer, so no gate is specified. Let's look at system 6.1.
device = AwsDevice('arn:aws:braket:us-west-2::device/qpu/d-wave/Advantage_system6')
topology = device.properties.dict()['provider']['topology']
qubit_number = device.properties.dict()['provider']['qubitCount']
print(topology)
print('qubit number = ', qubit_number)
{'type': 'pegasus', 'shape': [16]}
qubit number = 5760
This one has information on 5760 qubits of Pegasus coupling.
Finally, let's look at Borealis, which does not have much information. This one has a gate set, although the other quantum gates are different for continuous quantities.
device = AwsDevice('arn:aws:braket:us-east-1::device/qpu/xanadu/Borealis')
print(device.properties.action['braket.ir.blackbird.program'].supportedOperations)
['s', 'r0', 'r1', 'r2', 'bs0', 'bs1', 'bs2', 'loop0_phase', 'loop1_phase', 'loop2_phase']
As you can see, there are many different types of machines. The last two, D-Wave and Borealis, are used differently from other machines. We are also looking forward to another machine that will soon be available for special use. In the meantime, let's see how to run it on the actual machine.
Let's try to calculate quantum entanglement on Rigetti's machine.
device = AwsDevice("arn:aws:braket:us-west-1::device/qpu/rigetti/Aspen-M-2")
bell = Circuit().h(0).cnot(0, 1)
task = device.run(bell)
print(task.result().measurement_counts)
Counter({'00': 447, '11': 432, '10': 65, '01': 56})
Let's try to use it! That's all.