From 0219a24433d18a6f899d8a8606c5d5185dd6519b Mon Sep 17 00:00:00 2001 From: Krzysztof Domino Date: Thu, 11 Jul 2024 11:04:15 +0200 Subject: [PATCH] compute Ising energy --- decipher_results.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/decipher_results.py b/decipher_results.py index 51d7fd1..abd3a20 100644 --- a/decipher_results.py +++ b/decipher_results.py @@ -150,20 +150,26 @@ def print_results(dict_list): results = pd.read_csv(path_to_results, sep=";") ising_solution = results[results["instance"] == f"{instance}.csv"] print(ising_solution) - state = ising_solution["state"].item() - state = eval(state) - state = [(k+1)//2 for k in state] + state_ising = ising_solution["state"].item() + state_ising = eval(state_ising) + state = [(k+1)//2 for k in state_ising] solution = {i + 1: state[i] for i in range(len(state))} + solution_ising = {i + 1: state_ising[i] for i in range(len(state_ising))} + with open(path_to_renumeration, "rb") as f: var_to_nums, nums_to_var = pickle.load(f) solutions_vars = {nums_to_var[k]: val for k, val in solution.items()} + solutions_vars_ising = {nums_to_var[k]: val for k, val in solution_ising.items()} with open(path_to_lp, "rb") as f2: lp = pickle.load(f2) model = QuadraticAGV(lp) model.to_bqm_qubo_ising() + + energy_computed = dimod.utilities.ising_energy(solutions_vars_ising, model.ising[0], model.ising[1]) + sampleset = dimod.SampleSet.from_samples(solutions_vars, vartype=dimod.BINARY, energy=ising_solution["energy"].item()) decrypted_sapleset = model.interpreter(sampleset, "BIN") decrypted_results = get_results(decrypted_sapleset, lp) @@ -174,3 +180,5 @@ def print_results(dict_list): print("broken constraints", broken_constr) print("constraints", constraints) print("prec broken constr", broken_constr/constraints) + print("energy computed", energy_computed) + print("ising offset", model.ising[2])