Skip to content

qb2qmasm

Scott Pakin edited this page May 10, 2018 · 3 revisions

Name

qb2qmasm—Convert Qubist input to QMASM input

Synopsis

qb2qmasm [-h] [-o file] [-f format] [file]

Options

Positional arguments

file
Qubist-format input file (default: standard input)

Optional arguments

-h, --help
show this help message and exit
-o file, --output=file
file to which to write QMASM code (default: stdandard output)
-f format, --format=format
printf-style format string for formatting qubit numbers (default: %d)
-r int, --renumber-from=int
starting number from which to renumber qubits

Description

qb2qmasm converts a Hamiltonian function expressed in the numerical format used by D-Wave's Qubist Web interface into the symbolic format accepted by qmasm. The result can then easily be wrapped in a macro and incorporated into other QMASM programs.

The input to qb2qmasm need only be syntactically correct. The program does not consider the physical network topology but rather assumes all-to-all connectivity of qubits. The program does not consider hardware limitations on the range of weights and strengths but rather allows all floating-point numbers to be used.

Qubist format is fairly simple. The first line specifies the maximum qubit number plus 1 and the number of lines that follow. Each subsequent line specifies two qubit numbers and a coefficient. If the two qubit numbers are the same, the coefficient represents a point weight (h); otherwise, the coefficient represents a coupler strength (J).

Examples

A Fredkin gate (a.k.a. a CSWAP gate) conditionally swaps its two inputs (i1 and i2) when producing two outputs (o1 and o2) based on a control bit (c). The corresponding truth table looks like this:

c i1 i2 o1 o2
0 0 0 0 0
0 0 1 0 1
0 1 0 1 0
0 1 1 1 1
1 0 0 0 0
1 0 1 1 0
1 1 0 0 1
1 1 1 1 1

One way to express that table in Qubist format is as follows:

1152 34
680 680 0.5
681 681 0.041666666666666664
682 682 0.125
683 683 0.125
684 684 0.125
685 685 -0.0625
686 686 0.125
687 687 0.041666666666666664
690 690 0.0
692 692 0.0
693 693 -0.0625
695 695 0.041666666666666664
680 684 0.5
681 684 -0.0625
682 684 0.125
683 684 -1.0
680 685 -0.25
681 685 0.125
682 685 -0.125
683 685 -0.5
680 686 0.5
681 686 0.0625
682 686 -1.0
683 686 0.125
680 687 0.25
681 687 -1.0
682 687 0.0625
683 687 -0.0625
684 692 0.375
690 692 -1.0
685 693 -1.0
690 693 -0.375
687 695 -1.0
690 695 -0.25

The preceding code is based on the following mappings of variables to physical qubits:

c i1 i2 o1 o2
682, 686 681, 687, 695 685, 693 683, 684 690, 692

Other numbers appearing in the Qubist file are used for ancilla qubits and for chains that link together physically distant qubits.

In QMASM format, there is no header line, and lines representing point weights specify a single qubit as opposed to two identical qubits:

$ qb2qmasm fredkin.qb
680 0.5
681 0.041666666666666664
682 0.125
683 0.125
684 0.125
685 -0.0625
686 0.125
687 0.041666666666666664
690 0.0
692 0.0
693 -0.0625
695 0.041666666666666664
680 684 0.5
681 684 -0.0625
682 684 0.125
683 684 -1.0
680 685 -0.25
681 685 0.125
682 685 -0.125
683 685 -0.5
680 686 0.5
681 686 0.0625
682 686 -1.0
683 686 0.125
680 687 0.25
681 687 -1.0
682 687 0.0625
683 687 -0.0625
684 692 0.375
690 692 -1.0
685 693 -1.0
690 693 -0.375
687 695 -1.0
690 695 -0.25

QMASM qubits are named rather than numbered. The --format option facilitates assigning qubit names as a function of their number:

$ qb2qmasm --format='cs$%d' fredkin.qb
cs$680 0.5
cs$681 0.041666666666666664
cs$682 0.125
cs$683 0.125
cs$684 0.125
cs$685 -0.0625
cs$686 0.125
cs$687 0.041666666666666664
cs$690 0.0
cs$692 0.0
cs$693 -0.0625
cs$695 0.041666666666666664
cs$680 cs$684 0.5
cs$681 cs$684 -0.0625
cs$682 cs$684 0.125
cs$683 cs$684 -1.0
cs$680 cs$685 -0.25
cs$681 cs$685 0.125
cs$682 cs$685 -0.125
cs$683 cs$685 -0.5
cs$680 cs$686 0.5
cs$681 cs$686 0.0625
cs$682 cs$686 -1.0
cs$683 cs$686 0.125
cs$680 cs$687 0.25
cs$681 cs$687 -1.0
cs$682 cs$687 0.0625
cs$683 cs$687 -0.0625
cs$684 cs$692 0.375
cs$690 cs$692 -1.0
cs$685 cs$693 -1.0
cs$690 cs$693 -0.375
cs$687 cs$695 -1.0
cs$690 cs$695 -0.25

680 is a fairly arbitrary number from which to start numbering. Furthermore, the list of qubit numbers is disjoint: 680–687, 690, 692–693, and 695. (In this case, the numbering was the result of running D-Wave's heuristic embedder.) We can make the QMASM version of the Fredkin gate even prettier by renumbering the qubits:

$ qb2qmasm --renumber-from=1 --format='cs$%d' fredkin.qb
cs$1 0.5
cs$2 0.041666666666666664
cs$3 0.125
cs$4 0.125
cs$5 0.125
cs$6 -0.0625
cs$7 0.125
cs$8 0.041666666666666664
cs$9 0.0
cs$10 0.0
cs$11 -0.0625
cs$12 0.041666666666666664
cs$1 cs$5 0.5
cs$2 cs$5 -0.0625
cs$3 cs$5 0.125
cs$4 cs$5 -1.0
cs$1 cs$6 -0.25
cs$2 cs$6 0.125
cs$3 cs$6 -0.125
cs$4 cs$6 -0.5
cs$1 cs$7 0.5
cs$2 cs$7 0.0625
cs$3 cs$7 -1.0
cs$4 cs$7 0.125
cs$1 cs$8 0.25
cs$2 cs$8 -1.0
cs$3 cs$8 0.0625
cs$4 cs$8 -0.0625
cs$5 cs$10 0.375
cs$9 cs$10 -1.0
cs$6 cs$11 -1.0
cs$9 cs$11 -0.375
cs$8 cs$12 -1.0
cs$9 cs$12 -0.25
Clone this wiki locally