I’m pleased to announce that BURGLED-BATTERIES has not failed me (despite being far from finished), and I have been making steady progress with my Common Lisp interface to D-Wave’s Python Pack and Adiabatic Quantum Computer Simulator: SILVER-SWORD. It is now available in alpha as a Quicklisp-installable ASDF package on GitHub: https://github.com/thephoeron/silver-sword
Features left to implement: reading and writing of qubo files, ising to qubo to ising converter functions, chimera graph indexing, and the BlackBox Solver.
Of course, you still need D-Wave’s Python Pack first, so unless you’re already a registered D-Wave developer, SILVER-SWORD won’t be much use to you. You will also need a few other dependencies, which are all conveniently listed in the repo’s README file.
That being said, I have already included a few tutorials, so you can at least see Common Lisp quantum energy programming in action.
Let’s start ourselves with the tutorial hello-multiverse.lisp
. The code is reproduced here for your convenience:
(defun hello-multiverse () (let ((solver "c4-sw_sample") ;; set up default solver (h (make-list 128 :initial-element 0)) ;; list of energies, h (j (make-hash-table)) ;; hash-table for couplers, J (answer nil)) ;; define answer symbol for later ;; Define the energy program ; energies for 'h' (setf (elt h 48) 0.5 (elt h 53) 0.5 (elt h 52) -0.5 (elt h 49) -0.1) ; couplers for 'J' (setf (gethash "(48,53)" j) -0.5 (gethash "(48,52)" j) 0.2 (gethash "(52,49)" j) -0.3 (gethash "(53,49)" j) 0.8) ;; Solve the problem (setf answer (ss:solve-ising solver h j :num-reads 100 :max-answers 100)) ;; Print the results (ss::print-hash-table answer) ;; Or access them individually (format t "~%Solutions: ~S" (gethash "solutions" answer)) (format t "~%128-bit Best solution: ~S" (elt (gethash "solutions" answer) 0)) (format t "~%Lowest Energy: ~S" (elt (gethash "energies" answer) 0)) (format t "~%Number of solutions: ~S" (length (gethash "solutions" answer))) (format t "~%Best solution: ~S ~S ~S ~S" (elt (elt (gethash "solutions" answer) 0) 48) (elt (elt (gethash "solutions" answer) 0) 49) (elt (elt (gethash "solutions" answer) 0) 52) (elt (elt (gethash "solutions" answer) 0) 53))))
After reviewing the code for yourself, take note of the following points:
- The
SOLVE-ISING
function expects the name of a local solver as a string, the qubit energies as a list, the couplers to energies as a hash-table, and a number of optional keyword arguments. It returns a hash-table with the slotssolutions
,energies
, andnum_occurences
. - Since the Python Pack is based on the architecture of the D-Wave One adiabatic quantum computer, a maximum of 128 qubits and 352 couplers is available.
Now let’s run this function and see what we get. Load SILVER-SWORD and its tutorial package with quicklisp:
* (ql:quickload '("silver-sword" "silver-sword-tutorials"))
Run the hello-multiverse wrapper function:
* (sst::hello-multiverse)
And you should see a result similar to this:
;; For # ;; -- "energies": #(-3.4000000000000004 -1.4000000000000004) ;; -- "num_occurrences": #(99 1) ;; -- "solutions": #(#(3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -1 1 3 3 1 -1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3) #(3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -1 1 3 3 -1 -1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3)) Solutions: #(#(3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -1 1 3 3 1 -1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3) #(3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -1 1 3 3 -1 -1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3)) 128-bit Best solution: #(3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -1 1 3 3 1 -1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3) Lowest Energy: -3.4000000000000004 Number of solutions: 2 Best solution: -1 1 1 -1 NIL
You may get back a different number of solutions, but the best—the solution that requires the lowest energy—should be the same.
Now, for fun, re-write the hello-multiverse
function properly. It should accept the name of the solver, a list of qubit energies, a list or hash-table of coupler energies, and the number of occurrences as parameters, and output the result to a stream of your choice; the function should also return T
if it finds any solution, or NIL
if it fails.
Enjoy!