Skip to content

Commit

Permalink
Direct error calculation from matmul
Browse files Browse the repository at this point in the history
  • Loading branch information
GaidaiIgor committed Aug 6, 2021
1 parent 61bb99c commit 1920443
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions qde.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,13 @@ def solve_ode_qubo(system_terms, grid, known_points, bits_integer, bits_decimal,
job_label = f'Point {known_points.shape[1]}; Eq. {eq_ind}; Attempt {attempt + 1}'
sample_set = sampler.sample_qubo(Q, label=job_label, **kwargs)
samples_plain = np.array([list(sample.values()) for sample in sample_set]) # 2D, each row - solution (all bits together), sorted by energy
solution_error = sample_set.data_vectors['energy'][0] + energy_shift
trial_bits = samples_plain[0, :]
solution_error = np.dot(np.matmul(trial_bits, Q), trial_bits) + energy_shift
log.write(f'{job_label}; Error {solution_error}\n')

if solution_error < lowest_error:
lowest_error = solution_error
solution_bits = samples_plain[0, :]
solution_bits = trial_bits

if solution_error < max_error:
break
Expand Down
4 changes: 2 additions & 2 deletions test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ def get_qubo_solution(problem, N=100, time_max=400, initial_position=1.3, bits_i


def main():
# grid, sln, errors = get_qubo_solution(problem=21, N=200)
# grid, sln, errors = get_qubo_solution(problem=21, N=50, time_max=400, sampler_name='qbsolv', num_repeats=100)

_, solution, error = get_qubo_solution(problem=21, N=50, time_max=400, sampler_name='dwave', max_attempts=5, max_error=1e-5, num_reads=10000)
_, solution, error = get_qubo_solution(problem=21, N=50, time_max=400, sampler_name='dwave', max_attempts=10, max_error=5e-10, num_reads=10000)
np.savetxt('solution.txt', solution)
np.savetxt('error.txt', error)

Expand Down

0 comments on commit 1920443

Please sign in to comment.