-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from ProvideQ/release/0.4.0
ProvideQ Release 0.4.0
- Loading branch information
Showing
182 changed files
with
7,554 additions
and
2,183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import cplex | ||
import random | ||
import time | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import sys | ||
from io import StringIO | ||
|
||
if len(sys.argv) != 4: | ||
raise TypeError('This script expects exactly 3 arguments: max number of variables, step size, and number of repetitons') | ||
|
||
maxNbVars = int(sys.argv[1]) | ||
stepSize = int(sys.argv[2]) | ||
repetitions = int(sys.argv[3]) | ||
|
||
def generatePlot(table,): | ||
""" generates plot with table elements (x,y) | ||
table: elements are tuples first tuple is title of axes | ||
""" | ||
xvalues = [ a for (a,_) in table] | ||
yvalues = [ a for (_,a) in table] | ||
xlabel = xvalues.pop(0) | ||
ylabel = yvalues.pop(0) | ||
|
||
regression = np.poly1d(np.polyfit(xvalues, yvalues, 3)) | ||
plt.plot(xvalues, regression(xvalues)) | ||
|
||
plt.plot(xvalues, yvalues, 'o') | ||
plt.ylabel(ylabel=ylabel) | ||
plt.xlabel(xlabel=xlabel) | ||
|
||
plt.title(ylabel + " for " + xlabel) | ||
|
||
stringIo = StringIO() | ||
plt.savefig(stringIo, format='svg') | ||
plt.close() | ||
|
||
print(stringIo.getvalue()) | ||
|
||
def generateProblem(numberVars): | ||
""" returns random MIP Problem | ||
numberVars: the number if variables and constraints | ||
""" | ||
pb = cplex.Cplex() | ||
pb.set_problem_type(pb.problem_type.MILP) | ||
|
||
pb.objective.set_sense(pb.objective.sense.maximize) | ||
|
||
obj = [1 for _ in range(0,numberVars)] | ||
ub = [random.randint(1,100) for _ in range(0,numberVars)] | ||
lb = [ -i for i in ub] | ||
pb.variables.add(obj=obj, lb=lb, ub=ub) | ||
|
||
senses=['L' for _ in range(0,numberVars)] | ||
rhs = [random.randint(1,10) for _ in range(0,numberVars)] | ||
|
||
lin_expr = [cplex.SparsePair(ind = [i for i in range(0,numberVars)], val = [random.choice([-1,1]) * round(random.randint(1, 10)) for _ in range(0,numberVars)]) for _ in range(0,numberVars)] | ||
pb.linear_constraints.add(senses=senses, rhs=rhs, lin_expr=lin_expr) | ||
|
||
#print(pb.write_as_string()) | ||
return pb | ||
|
||
# The following experiment generates MIP problems and solves them with CPLEX. | ||
# It calculates the time taken by the solver for rising numbers of variables and shows results as plot. | ||
|
||
results = [("number of variables","time (sec)")] | ||
|
||
for i in [j*stepSize for j in range(0, maxNbVars // stepSize)]: | ||
totalTime = 0 | ||
for _ in (0,repetitions): | ||
problem = generateProblem(i) | ||
problem.set_results_stream(None) | ||
problem.set_log_stream(None) | ||
|
||
start = time.perf_counter() | ||
problem.solve() | ||
end = time.perf_counter() | ||
totalTime += end - start | ||
|
||
results.append((i,totalTime)) | ||
|
||
generatePlot(results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cplex | ||
matplotlib | ||
numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
# this script is made for the CI-pipeline, do not use this to install dependencies on your private machine! | ||
|
||
# exit on error | ||
set -e | ||
|
||
# get base directory of the repository | ||
REPO_DIR=$(dirname "$(dirname "$(readlink -f "$0")")") | ||
|
||
# make sure to install to the gams conda env | ||
source /opt/conda/bin/activate gams | ||
|
||
# install solver dependencies / quantum frameworks and python wrappers | ||
python3 "$REPO_DIR/scripts/install-python-dependencies.py" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
import subprocess | ||
|
||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
base_dirs = [ | ||
os.path.join(script_dir, '..', 'solvers'), | ||
os.path.join(script_dir, '..', 'demonstrators') | ||
] | ||
|
||
for base_dir in base_dirs: | ||
for root, dirs, files in os.walk(base_dir): | ||
# Check if 'requirements.txt' is in the current directory | ||
req_file = os.path.join(root, 'requirements.txt') | ||
if os.path.exists(req_file): | ||
print(f"Found requirements.txt in {root}, installing dependencies...") | ||
try: | ||
subprocess.run(['pip', 'install', '-r', req_file], check=True) # single thread to avoid dep. errors | ||
except subprocess.CalledProcessError as e: | ||
print(f"Error installing requirements for {root}: {e}") |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Cirq MaxCut | ||
matplotlib | ||
cirq==1.5.0.dev20241009204224 |
Oops, something went wrong.