Adam Glos
29.09.2021, Gliwice/Żory/Istanbul
INPUT
OUTPUT
# TSP
# create model
from docplex.mp.model import Model
mdl = Model('docplex model')
x = mdl.binary_var('x')
y = mdl.integer_var(lb=-1, ub=5, name='y')
mdl.minimize(x + 2 * y)
mdl.add_constraint(x - y == 3)
mdl.add_constraint((x + y) * (x - y) <= 1)
print(mdl.export_as_lp_string())
# transform to QUBO
conv = AnyToQUBO(mdl) # optionally AnyToQUBO(mdl, method="pyqubo")
conv.int_to_var(mode="binary", penalty=1000)
conv.constraints_to_objective(penalty=1000)
if conv.is_hobo():
conv.quadratize(method="pyqubo")
conv.export(package="dwave")
# solving the
solution = ...
conv.interpret(solution) # final outcome
# TSP
# create model
n = 10
w_matrix = np.random.rand(n, n)
x = [Symbol(f"x{i}") for i in range(n)]
expr
for v in range(n):
for i in range(n):
for j in range(n):
expr += w[i,j] * kronecker_delta(v, i) * kronecker_delta(v+1, j)
# Make an optimization model object (to be implemented)
model = SympyOpt()
model.set_objective(expr)
# transform to QUBO
conv = AnyToQUBO(model)
conv.to_qubo(int_to_var="one-hot", penalty_int_to_var=1000) # still an abstract QUBO
conv.export(package="qiskit")
# solving the
solution = ...
conv.interpret(solution) # final outcome
Basic - most user friendly, it simply transforms the Integer model into QUBO/HOBO with default parameters
Intermediate - still user friendly, some parameters can be chosen but in global way (for example turn all integers into QUBO in one-hot way)
Hard - most advanced once, each integer, constraint can be transformed independently.
MODEL
docplex, pyqubo, or-tools, pyomo
my general model
with sympy, maybe pyqubo
QUBO/HOBO
with sympy, maybe pyqubo
QUBO/HOBO
qiskit, pyqubo, dwave, cqirc,...
transpile
conversion
interpret
interpret
convert
SOLVER
transpile
SymPy |
pyqubo |
---|---|
general model | only polynomials |
slow (probably) | fast |
old package | very fresh one |
arbitrary output | only QUBO as output (for now) |
no quadratization | quadratization |
I plan to use both, as polynomials are very popular!
Abstract models (we specify parameters at the very end of making QUBO)
# TSP
# create model
n = 10
w = MatrixSymbol('W', n, n)
x = [Symbol(f"x{i}") for i in range(n)]
expr
for v in range(n):
for i in range(n):
for j in range(n):
expr += w[i,j] * kronecker_delta(v, i) * kronecker_delta(v+1, j)
# Make an optimization model object (to be implemented)
model = SympyOpt()
model.set_objective(expr)
# transform to QUBO
conv = AnyToQUBO(model)
conv.to_qubo(int_to_var="one-hot", penalty_int_to_var=1000) # still an abstract QUBO
# introduce W matrix
w_matrix = np.random.rand(n, n)
conv.concretize({'W': w_matrix})
conv.export(mode="qiskit")
# solving the
solution = ...
conv.interpret(solution) # final outcome
removing non-polynomial operations (like Kronecker Delta, sinus, cosinus)
First option (Taylor series)
Second option (Kronecker Delta)
we only need to implement \(\delta\)
Mixed Integer Programming