Use the Dwave Ocean tools to (A) try their
factorization example under a simulator and then (B) on the Dwave 2000Q
system.
- PART A: Install the Ocean
tools. For me, it's simple:
pip install --user dwave-ocean-sdk
- Download the factoring example:
git clone https://github.com/dwavesystems/factoring-demo.git
- Consult the following files:
factoring-demo/demo.py
factoring-demo/factoring/interfaces.py
https://github.com/dwavesystems/dwavebinarycsp/blob/master/dwavebinarycsp/factories/csp/circuits.py
and read the
factoring
paper, which explains how to express factoring as a binary CSP.
- Modify demo.py and interfaces.py to run it in simulation mode
to factor the number 42:
python demo.py
- Verify that your results are correct.
- Hints:
- Look at
Constrained
Scheduling and change interfaces.py to "solve
classically".
- use an ExactSolver() instead of DWaveSampler()
- You will neither need embeddings nor kwargs (for
sampling), nor any unembedding, nor client.close operations
- PART B: Sign up for a Dwave
leap account.
- Once you have it, take a look at the
factoring
example and check out "More Information" for each page, but
don't run it in the final step.
- Modify interfaces.py to run it on the Dwave hardware, use 4
bits for each factor and 8 bits for the product. Then factor
the number 26.
- Modify demo.py and interfaces.py to run it in hardware mode.
- Verify that your results are correct.
- Hints:
- Look at
Constrained
Scheduling and change interfaces.py to solve
"on a D-Wave System".
- obtain the API token from your Dashboard
- use DWaveSampler(endpoint='https://cloud.dwavesys.com/sapi',
token='your-Token-here', solver = 'DW_2000Q_6') #used to be DW_2000Q_2
- Change the number of reads to 500 (more than 50 samples needed)
- Change the output to be 8 bits (p0..p7) and inputs to be 4
bits (a0..a3, b0..b3).
- Change the multiplication_circuit to operate on 4 bits.
- Modify demo.py to invoke factor with a 2nd parameter of False to
indicate that no prior embedding exists.
As part of this exercise, you should create the following files:
interface-sim.py, demo-sim.py, output-sim.txt, interface-hw.py,
demo-hw.py, output-hw.txt