This article assumes that you have already installed the Ocean™ software and set up the required dependencies .
Note: The two-qubit problem shown here is a simple example. For more detailed examples, see the Ocean documentation.
Two-qubit problem
The Ising Hamiltonian of a two-qubit system is written as:
H = h_1 * s_1 + h_2 * s_2 + J_{1,2} * s_1 *s_2
where s_1,s_2 can be {-1,1}.
h1 and h2 are biases on individual qubits and J_{1,2} is the coupling term. Since we are trying to find the ground state of the above Hamiltonian: minimum energy, if h_1 is positive, qubit 1 (s_1) will "want" to be -1 (and same for qubit 2).
If J_{1,2} is negative, s_1 and s_2 will "want" to have the same sign. This is ferromagnetic (FM) coupling. If J_{1,2} is positive, s_1 and s_2 will tend to have the opposite sign to minimize the energy: this is antiferromagnetic (AFM) coupling.
Access a solver
To access a D-Wave™ QPU (a solver), you need to know the following details, all of which are available to you in your Leap™ dashboard:
- API end point (URL) that you will connect to
- Your API token that you will use to authenticate
- The name of the solver
Access the solver using the following command:
from dwave.system import DWaveSampler
solver = DWaveSampler()
Each solver has properties that are stored in a dict format that you can access as follows:
print(solver.properties.keys())
View qubit details
For now, let's concentrate on the keys for the quantum bits (qubits) and couplers on the QPU; run these commands to enumerate the qubits and couplers in the device:
qubits = solver.properties['qubits']
couplers = solver.properties['couplers']
Two qubits that we can use (that are coupled) are 0 and 4. First, let's ensure both are available in our system:
qubit_1 = 0
qubit_2 = 4
coupler = [qubit_1,qubit_2]
if (qubit_1 in qubits) and \
(qubit_2 in qubits) and \
(coupler in couplers):
print('Qubits {} and {} and their coupler {} are available'.format(qubit_1,
qubit_2,
coupler))
Define the problem
Now we can define a problem. Let's force the qubits to be spin-up by setting h_0 = h_4 = -1 and have a FM coupling between them. We expect to get samples with spin up (1) qubits and an energy of -1 + -1 + -1 = -3.
h = {qubit_1:-1,qubit_2:-1}
J = {tuple(coupler):-1}
Let's ask for a solution with 10 samples (reads):
solution = solver.sample_ising(h,J,num_reads=10)
For this problem, we are likely to get a single, unique solution for all 10 runs. This is because the problem has a non-degenerate ground state that is well separated from its excited states, so we managed to reach the correct solution 100 percent of the time.
See also: https://support.dwavesys.com/hc/en-us/articles/360049893333-View-Results-Problem-Solution
Comments
Article is closed for comments.