Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrections in QUBO tutorial. #1254

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions demonstrations/tutorial_QUBO.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def time_to_solution(n, time_single_case):
# .. math:: S = 2^0 s_0 + 2^1 s_1 + 2^2 s_2 + 2^3 s_3 + 2^4 s_4
#
# To compact our equation later, let’s rename our slack variables by :math:`s_0=x_5`, :math:`s_1=x_6,`
# :math:`s_3=x_7`, :math:`s_4=x_8,` and :math:`s_5=x_9.` Then we have
# :math:`s_2=x_7`, :math:`s_3=x_8,` and :math:`s_4=x_9.` Then we have
#
# .. math:: S = 1 x_5 + 2 x_6 + 4 x_7 + 8 x_8 + 16 x_9.
#
Expand Down Expand Up @@ -352,19 +352,19 @@ def time_to_solution(n, time_single_case):
import pennylane as qml

shots = 5000 # Number of samples used
dev = qml.device("default.qubit", shots=shots)
dev = qml.device("default.qubit", shots=shots, wires=n_qubits)


@qml.qnode(dev)
def qaoa_circuit(gammas, betas, h, J, num_qubits):
wmax = max(
np.max(np.abs(list(h.values()))), np.max(np.abs(list(h.values())))
np.max(np.abs(list(h.values()))), np.max(np.abs(list(J.values())))
) # Normalizing the Hamiltonian is a good idea
p = len(gammas)
# Apply the initial layer of Hadamard gates to all qubits
for i in range(num_qubits):
qml.Hadamard(wires=i)
# repeat p layers the circuit shown in Fig. 1

for layer in range(p):
# ---------- COST HAMILTONIAN ----------
for ki, v in h.items(): # single-qubit terms
Expand Down
Loading