quil-lang / quilc

The optimizing Quil compiler.
Apache License 2.0
455 stars 72 forks source link

"IDENTITY" initial rewiring strategy #646

Open notmgsk opened 4 years ago

notmgsk commented 4 years ago

The "NAIVE" initial rewiring strategy tries to avoid rewiring qubits, but will if there is a 2Q instruction that cannot be enacted on the provided qubits:

QUIL> (print-parsed-program
       (compiler-hook (parse "PRAGMA INITIAL_REWIRING \"NAIVE\"; CZ 0 2")
                      chip))
PRAGMA INITIAL_REWIRING "NAIVE"
CZ 1 2                                  # Entering rewiring: #(1 0 2 3)
HALT                                    # Exiting rewiring: #(1 0 2 3)

It may be useful to also have a strategy that strictly adheres to an identity map between logical and physical qubits:

QUIL> (print-parsed-program
       (compiler-hook (parse "PRAGMA INITIAL_REWIRING \"IDENTITY\"; CZ 0 2")
                      chip))
PRAGMA INITIAL_REWIRING "IDENTITY"
RZ(-2.5488357645048048) 0               # Entering rewiring: #(0 1 2 3)
RX(pi/2) 0
RZ(2.079807667586275) 0
RX(-pi/2) 0
RZ(-2.2709115010202283) 1
RX(pi/2) 1
RZ(2.5039458858335597) 1
RX(-pi/2) 1
CZ 1 0
RZ(1.4358710688580993) 0
RX(pi/2) 0
RZ(-1.5173734837788224) 1
RX(-pi/2) 1
CZ 1 0
RX(-pi/2) 0
RX(pi/2) 1
CZ 1 0
RZ(1.807326329153546) 1
RX(pi/2) 1
RZ(0.5250671103423779) 1
RX(-pi/2) 1
CZ 1 2
RZ(-1.6103374643670643) 0
RX(pi/2) 0
RZ(0.9342061478727135) 0
RX(-pi/2) 0
RZ(-0.8042280573284075) 0
RZ(-0.8644370089703486) 1
HALT                                    # Exiting rewiring: #(1 0 2 3)
stylewarning commented 4 years ago

I propose calling it PROGRAM, RIGID, STATIC, or FIXED, not because IDENTITY is bad (it's not; it's a great name and fits well with the permutation representation), but because IDENTITY is an overloaded word and doesn't describe the rewiring strategy so much as it describes the trivial rewiring result.