Giter Site home page Giter Site logo

dwave-examples / nae3sat Goto Github PK

View Code? Open in Web Editor NEW
1.0 7.0 4.0 191 KB

Compare the performance of the Advantage QPU and the Advantage2 prototype on not-all-equal 3-satisfiability problems.

License: Apache License 2.0

Python 100.00%
bqm embedding-composite optimization advanced

nae3sat's Introduction

Open in GitHub Codespaces

Not-All-Equal 3-Satisfiability (NAE3SAT)

NAE3SAT is an NP-complete Boolean satisfiability (SAT) problem that has clauses of three literals each and requires that for every clause the literals are not all equal to each other; i.e., all configurations are valid except (-1, -1, -1) and (+1, +1, +1) (for spin-valued variables, or (0,0,0) and (1, 1, 1) for binary-valued variables).


SAT Terminology:

The SAT problem problem is to decide whether the literals in its clauses can be assigned values that satisfy all the clauses. In CNF, the SAT is satisfied only if all its clauses are satisfied.

  • Literal is a Boolean variable such as x and its negation.
  • Clause is a disjunction of literals such as x1 OR x0.
  • conjunctive normal form (CNF) conjoins clauses by the AND operator; i.e., (clause 1) AND (clause 2) AND (clause 3).

NAE3SAT problems are known to transition from the satisfiable to the unsatisfiable regime at a clause-to-variable ratio ρ=2.1. This code example solves problems with ρ=2.1 (critical point) as well as with ρ=3.0 (max-SAT regime).

This example explores solving this satisfiability problem with two different generations of D-Wave quantum computers:

  • A Pegasus-topology Advantage system.
  • An experimental prototype of a Zephyr-topology quantum processing unit (QPU) for the Advantage2 next-generation system currently under development.

Installation

You can run this example without installation in cloud-based IDEs that support the Development Containers specification (aka "devcontainers").

For development environments that do not support devcontainers, install requirements:

pip install -r requirements.txt

If you are cloning the repo to your local system, working in a virtual environment is recommended.

Usage

Your development environment should be configured to access Leap’s Solvers. You can see information about supported IDEs and authorizing access to your Leap account here.

To run the example:

python nae3sat_example.py

The code saves the resulting graphics under a plots folder.

Code Overview

The code reformulates NAE3SAT instances as Ising problems, embeds these onto the QPU graphs, and analyzes the solution quality obtained from both QPUs.

Ising Formulation

NAE3SAT problems can be mapped to the Ising model by anti-ferromagnetically coupling the variables of a clause. For example, a clause for variables (s0, s1, s2) is represented by the Ising Hamiltonian,

H(s0, s1, s2) = s0*s1 + s1*s2 + s0*s2.

The table below shows the energy for all configurations of the variables. The valid not-all-equal configurations have a lower energy than the all-equal ones. Therefore, the NAE3SAT clause is solved when minimizing the Hamiltonian objective.

s0 s1 s2 E
-1 -1 -1 3
1 -1 -1 -1
1 1 -1 -1
-1 1 -1 -1
-1 1 1 -1
1 1 1 3
1 -1 1 -1
-1 -1 1 -1

Negated variables are represented by a spin-reverse transform of such variables. For example, a clause with -s1, the negation of s1, is represented by the Ising Hamiltonian,

H(s0, -s1, s2) = -s0*s1 - s1*s2 + s0*s2.

A NAE3SAT problem is generated by adding all its clauses together; for example:

H(s0,..., sN) = H(s0, s1, s2) + H(s6, -s1, s4) + H(-s3, s5, -s9) + ...

The minimization of this objective solves the NAE3SAT problem.

For more information on reformulating SAT problems in Ising format, see the system documentation.

Embedding

Both the Pegasus and Zephyr graphs natively support triangles, enabling the embedding of three-variable clauses without chains. Nevertheless, large NAE3SAT problems typically include interactions between variables that are not natively connected and do require chains.

The graphic below shows the distribution of chain lengths for a ρ=3.0 NAE3SAT problem of 75 variables minor-embedded into the two topologies using Ocean software's minorminer heuristic. Smaller chains typically improve the success of quantum-annealing computations.

The Zephyr topology of the Advantage2 prototype has a greater connectivity than the Pegasus topology of Advantage. This enables more-compact embedding (minor embeddings with shorter chains) of problems in the Advantage2 prototype, which in turn improves the performance of the QPU on embedded problems.

Solution Analysis

The graphic below shows the solution quality of 100 samples from a ρ=3.0 problem.

The distribution of samples obtained by the Advantage2 prototype tends to have lower energy than that of the Advantage QPU. Lower energies mean better solutions.


Note: The data displayed in the graphics above was generated for a particular execution of this code example; results will slightly vary from run to run. If you wish to experiment further to get more consistent results, you can increase the number of samples or the number of calls (keep in mind these runs will consume your solver access time at the standard rate).


License

Released under the Apache License 2.0. See LICENSE file.

nae3sat's People

Contributors

arcondello avatar joelpasvolsky avatar pau557 avatar randomir avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nae3sat's Issues

Optional to address.

N=75 means that the number of clauses has to be rounded when rho=2.1. Would be tidier to choose rho such that rho*N is integer.

Rescaling the x-axis to (H(s)+rhoN)/4 could make the presentation a bit more intuitive. The x-axis labeling could then be "Number of violated clauses ([H(s) + rhoN/4])", or "Number of violated clauses ([Energy + rho*N/4])"

The example begins with a definition of a clause as a disjuction (appropriate for SAT), but the usage of clause in the rest of the repository is for NAE3SAT (which cannot be written as a disjunction). Might be better to define 'A clause as a logical function of the literals (in the case of SAT a disjunction x1 v x2)'

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.