Giter Club home page Giter Club logo

example_problem's Introduction

example_problem

A Basic Mathematical Optimisation Problem With A Basic Boundary Condition To Demonstrate QUBO Formulation

This script demonstrates how to formulate the optimisation problem

$$ min \text{ } x^2 $$

$$ s.t. \text{ } x^2-c \quad \text{for a constant c} $$

up to a positive integer constant of 15.

Formulation of Minimization Problem and the Boundary Condition

The problem variable is expressed in binary manner to make it easier to express in the forms of 1's and 0's - those are the only allowed values in the QUBO formulation anyway. In the code, this is expressed as

expression_1 = (8x+4y+2z+q)

coefficients being the powers of 2. expression_1 is here just our variable x given in the minimization problem. The x in the expression itself is just a simpy symbol, and should not be confused with the one in the optimization problem.

Boundary condition is expressed in the same manner with a constant factor between 0 and 15 (4 bit's allowance span).

Creation of the Cost Matrix

After the problem is created, coefficients of the variables are placed in the symmetrical cost matrix. We don't differentiate between quadratic expressions and singular experrions(such as $x^2$ and $x$), since $0^2=0$ and $1^2=1$. The coefficients of the singular variables are placed in the diagonal of the cost matrix, while the coefficients of the multiplicative variables are placed in the off-diagonal elements.

$$ Q_{m,n} = \begin{pmatrix} q_{x,x} & q_{x,y} & q_{x,z} & q_{x,q} \\ q_{y,x} & q_{y,y} & q_{y,z} & q_{y,q} \\ q_{z,x} & q_{z,y} & q_{z,z} & q_{z,q} \\ q_{q,x} & q_{q,y} & q_{q,z} & q_{q,q} \end{pmatrix} $$

Choice of Lambda

That's the big question!

Determination of the Offset Energy

The constant part in the problem definition (that would be e.g. 36, for the case of c=6 or 144, for the case of c=12) is the energy which can not be decreased with the manipulation of the variables. Hence, it stays in the problem. This energy is communicated with the quantum annealer via

e_offset=boundary.as_independent(x,y,z,q)[0]*langrange_hard

Reformulation of the Answer from the Annealer Back to the Integer

Since the Annealer returns back a vector of binary variables, one must translate it back to a readable answer. To do that, we just to binary to decimal conversation. smpl[0] is equivalent to our symbol x, and smpl[1] to our y etc.

answer = 8smpl[0] + 4smpl[1] + 2*smpl[2] + smpl[3]

helpers.py

Here are some helping functions for the sake of keeping the main script clean. Hopefully they are well commented by the time!

example_problem's People

Contributors

jcxatsiemens avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.