Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsmierz committed Jul 11, 2024
2 parents 73ba504 + 43e74f4 commit 98f66bd
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 41 deletions.
3 changes: 2 additions & 1 deletion AGV_quantum/process_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def analyze_constraints(lp, sample):
result[f"eq_{num_eq}"] = expr <= lp.b_ub[i]
num_eq += 1

return result, sum(x is False for x in result.values())
not_feas = list(result.values()).count(False)
return result, not_feas


def process_result(sampleset: list):
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

In directory ```examples``` there are AGVs scheduling problems. In order of increasing size of the problem these are:

- example_tiny.py - 2 AGVs reduced size
- example_smallest.py - 2 AGVs, 4 zones
- example_small.py - 4 AGVs, 4 zones
- example_medium_small.py - 6 AGVs, 7 zones
- example_medium.py - 7 AGVs, 7 zones
- example_large.py - 12 AGVs, 7 zones
- example_largest.py - 15 AGVs, 7 zones
- example_tiny.py - 2 AGVs reduced size
- example_smallest.py - 2 AGVs, 4 zones
- example_small.py - 4 AGVs, 4 zones
- example_medium_small.py - 6 AGVs, 7 zones
- example_medium.py - 7 AGVs, 7 zones
- example_large.py - 12 AGVs, 7 zones
- example_largest.py - 15 AGVs, 7 zones
- example_largest_ever.py - 21 AGVs, 7 zones


## Usage
Expand Down
Binary file added annealing_results/21_AGV/new_bqm.pkl
Binary file not shown.
Binary file added annealing_results/21_AGV/new_bqm_info.pkl
Binary file not shown.
14 changes: 11 additions & 3 deletions check_sol.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def csv_write_hist(file_name, hist, key1 = "value", key2 = "count"):
cwd = os.getcwd()
train_diagram = False

#count = "_10"
count = "_1"
count = "_10"
count = ""

if args.example == "tiny":
sol_folder = Path("annealing_results/tiny_2_AGV")
Expand Down Expand Up @@ -111,7 +111,15 @@ def csv_write_hist(file_name, hist, key1 = "value", key2 = "count"):
lp.to_bqm_qubo_ising(p)
sampleset = lp.interpreter(sampleset)
solutions = get_results(sampleset, lp)
#print(solutions)
print(solutions[0]['energy'])

constraints = len(solutions[0]['feas_constraints'][0])
not_feas = solutions[0]['feas_constraints'][1]

print("feasible", solutions[0]['feasible'])
print("n.o. constraints", constraints)
print("broken feas", not_feas)
print("precentage broken", not_feas/constraints)


elif hybrid == "cqm":
Expand Down
48 changes: 22 additions & 26 deletions make_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@



n_vars = {2:16, 4:36, }


def read_single_file(size, k, solver):

Expand Down Expand Up @@ -81,7 +79,7 @@ def read_smapleset(size, k, solver):

def print_info(key, sizes):
print(key)
no_qbits = []
no_vars = []
means = []
stds = []
for size in sizes:
Expand All @@ -96,19 +94,19 @@ def print_info(key, sizes):
m = np.mean(series/k)
s = np.std(series/k)

no_qbits.append(vars)
no_vars.append(vars)
means.append(m)
stds.append(s)


print(vars, m, m-s, m+s)

return no_qbits, means, stds
return no_vars, means, stds


def print_obj(sizes, examples, optimum):

no_qbits = []
no_vars = []
means = []
stds = []

Expand All @@ -123,19 +121,19 @@ def print_obj(sizes, examples, optimum):
print(vars, m,m-s, m+s)


no_qbits.append(vars)
no_vars.append(vars)
means.append(m)
stds.append(s)

print(obj)
print(np.mean(obj), np.std(obj))

return no_qbits, means, stds
return no_vars, means, stds


def print_feas(sizes, examples):

no_qbits = []
no_vars = []
means = []
stds = []

Expand All @@ -149,25 +147,25 @@ def print_feas(sizes, examples):
print(vars, m,m-s, m+s)


no_qbits.append(vars)
no_vars.append(vars)
means.append(m)
stds.append(s)


return no_qbits, means, stds
return no_vars, means, stds




def csv_write(file_name, no_qbits, means, stds):
def csv_write(file_name, no_vars, means, stds):
with open(file_name, 'w', newline='', encoding="utf-8") as csvfile:
fieldnames = ["no_qbits", "mean", "mean-std", "mean+std"]
fieldnames = ["no_vars", "mean", "mean-std", "mean+std"]

writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
for i,v in enumerate(no_qbits):
for i,v in enumerate(no_vars):
m = means[i]
s = stds[i]
writer.writerow({"no_qbits": v, "mean": np.round(m, 4), "mean-std": np.round(m-s, 4), "mean+std": np.round(m+s, 4)})
writer.writerow({"no_vars": v, "mean": np.round(m, 4), "mean-std": np.round(m-s, 4), "mean+std": np.round(m+s, 4)})



Expand All @@ -181,37 +179,35 @@ def get_no_vars(size):

#sizes = [2,4,6,7,12,15,21]

optimum = {2:4, 4: 8.2, 6: 3.22, 7: 4.25, 12: 9.175, 15: 10.975 }
optimum = {2:4, 4: 8.2, 6: 3.22, 7: 4.25, 12: 9.175, 15: 10.975, 21: 17.625}

examples = {2:"smallest", 4:"small", 6:"medium_small", 7:"medium", 12:"large", 15:"largest", 21:"largest_ever"}
sizes = examples.keys()


key = 'qpu_access_time'
no_qbits, means, stds = print_info(key, sizes)
no_vars, means, stds = print_info(key, sizes)

file = "article_plots/CQM_QPU_time.csv"
csv_write(file, no_qbits, means, stds)
csv_write(file, no_vars, means, stds)

key = 'run_time'
no_qbits, means, stds = print_info(key, sizes)
no_vars, means, stds = print_info(key, sizes)

file = "article_plots/time_CQM.csv"
csv_write(file, no_qbits, means, stds)
csv_write(file, no_vars, means, stds)

no_qbits, means, stds = print_feas(sizes, examples)
no_vars, means, stds = print_feas(sizes, examples)

file = "article_plots/feasibility_CQM.csv"
csv_write(file, no_qbits, means, stds)
csv_write(file, no_vars, means, stds)

# TODO we do not have yet CPLEX largest ever
examples = {2:"smallest", 4:"small", 6:"medium_small", 7:"medium", 12:"large", 15:"largest"}
sizes = examples.keys()

no_qbits, means, stds = print_obj(sizes, examples, optimum)
no_vars, means, stds = print_obj(sizes, examples, optimum)

file = "article_plots/obj_CQM.csv"
csv_write(file, no_qbits, means, stds)
csv_write(file, no_vars, means, stds)



Expand Down
9 changes: 5 additions & 4 deletions run_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@

model.to_bqm_qubo_ising(p)

print("n.o. qubits", model._count_qubits())
print("n.o. quandratic couplings", model._count_quadratic_couplings())
print("n.o. linear fields", model._count_linear_fields())

# check if results are saved
is_file = os.path.isfile(os.path.join(save_path, f"new_{hybrid}_info{count}.pkl"))
if is_file:
print(".......... files exist ............")
if hybrid == "bqm":
print("n.o. qubits", model._count_qubits())
print("n.o. quandratic couplings", model._count_quadratic_couplings())
print("n.o. linear fields", model._count_linear_fields())

else:
model.to_cqm()
cwd = os.getcwd()
Expand Down

0 comments on commit 98f66bd

Please sign in to comment.