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

Bugfix vanishing instances after elimination #158

Merged
merged 18 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
14 changes: 10 additions & 4 deletions openqaoa/rqaoa/rqaoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def redefine_problem(problem: QUBO, spin_map: dict):
spin_map: `dict`
Updated spin_map with sponatenous eliminations from cancellations during spin removal process.
"""

# Define new QUBO problem as a dictionary
new_problem_dict = {}

Expand Down Expand Up @@ -498,9 +498,15 @@ def redefine_problem(problem: QUBO, spin_map: dict):
# Delete isolated node from new problem
new_problem_dict.pop((node,))

# Redefine new QUBO problem from the dictionary
new_problem = problem_from_dict(new_problem_dict)

# For some unweighted graphs specific eliminations can lead to eliminating the whole instance before reaching cutoff.
if new_problem_dict == {}:
new_problem = problem # set the problem to the old problem and solve classically for the smallest non-vanishing instance.

else:
# Redefine new QUBO problem from the dictionary
new_problem = problem_from_dict(new_problem_dict)


return new_problem, spin_map


Expand Down
33 changes: 18 additions & 15 deletions openqaoa/workflows/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,26 +713,29 @@ def optimize(self, verbose=False):
spin_map = rqaoa.spin_mapping(problem, max_terms_and_stats)
# Eliminate spins and redefine problem
new_problem, spin_map = rqaoa.redefine_problem(problem, spin_map)
if new_problem == problem:
vishal-ph marked this conversation as resolved.
Show resolved Hide resolved
print("Eliminations lead to a total reduction of the problem.\n Increasing the cutoff to solve the smallest non-vanishing problem.")
break
else:
kidiki marked this conversation as resolved.
Show resolved Hide resolved
# Extract final set of eliminations with correct dependencies and update tracker
eliminations = {(spin_map[spin][1],spin):spin_map[spin][0] for spin in sorted(spin_map.keys()) if spin != spin_map[spin][1]}
elimination_tracker.append(eliminations)

# Extract final set of eliminations with correct dependencies and update tracker
eliminations = {(spin_map[spin][1],spin):spin_map[spin][0] for spin in sorted(spin_map.keys()) if spin != spin_map[spin][1]}
elimination_tracker.append(eliminations)
# Extract new number of qubits
n_qubits = new_problem.n

# Extract new number of qubits
n_qubits = new_problem.n
# Save qaoa object and new problem
qaoa_steps.append(copy.deepcopy(q))
problem_steps.append(copy.deepcopy(new_problem))

# Save qaoa object and new problem
qaoa_steps.append(copy.deepcopy(q))
problem_steps.append(copy.deepcopy(new_problem))
# problem is updated
problem = new_problem

kidiki marked this conversation as resolved.
Show resolved Hide resolved
# problem is updated
problem = new_problem

# Compile qaoa with the problem
q.compile(problem, verbose=False)
# Compile qaoa with the problem
q.compile(problem, verbose=False)

# Add one step to the counter
counter += 1
# Add one step to the counter
counter += 1

# Solve the new problem classically
cl_energy, cl_ground_states = ground_state_hamiltonian(problem.hamiltonian)
Expand Down