Skip to content

Commit

Permalink
Update pragma rewiring expectations (rigetti#878)
Browse files Browse the repository at this point in the history
* update tests to not expect PRAGMA ..._REWIRING
* tolerate extended whitespace before comments or newlines
* tolerate comments in replies from quilc
  • Loading branch information
ecpeterson authored Apr 22, 2019
1 parent d8d9f92 commit 341e282
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 195 deletions.
14 changes: 6 additions & 8 deletions docs/source/compiler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ with output

.. code:: python
PRAGMA EXPECTED_REWIRING "#(0 1 2 3 4 5 6 7)"
RZ(pi/2) 0
RX(pi/2) 0
RZ(-pi/2) 1
Expand All @@ -73,7 +72,6 @@ with output
RZ(-pi/2) 1
RX(-pi/2) 2
RZ(pi/2) 2
PRAGMA CURRENT_REWIRING "#(0 1 2 3 4 5 6 7)"
The compiler connection is also available directly via the property ``qc.compiler``. The
precise class of this object changes based on context (e.g., ``QPUCompiler``,
Expand Down Expand Up @@ -247,12 +245,12 @@ Rewirings

When a Quil program contains multi-qubit instructions that do not name qubit-qubit links present on a
target device, the compiler will rearrange the qubits so that execution becomes possible. In order to
help the user understand what rearrangement may have been done, the compiler emits two forms of
``PRAGMA``: ``PRAGMA EXPECTED_REWIRING`` and ``PRAGMA CURRENT_REWIRING``. From the perspective of the
user, both ``PRAGMA`` instructions serve the same purpose: ``PRAGMA ..._REWIRING "#(n0 n1 ... nk)"``
indicates that the logical qubit labeled ``j`` in the program has been assigned to lie on the physical
qubit labeled ``nj`` on the device. This is strictly for human-readability: user-supplied instructions
of the form ``PRAGMA [EXPECTED|CURRENT]_REWIRING`` are discarded and have no effect.
help the user understand what rearrangement may have been done, the compiler emits comments at various
points in the raw Quil code (which is not currently visible from a pyQuil ``Program`` object's ``.out()``
method): ``# Entering rewiring`` and ``# Exiting rewiring``. From the perspective of the user, both
comments serve the same purpose: ``# Entering rewiring: #(n0 n1 ... nk)`` indicates that the logical
qubit labeled ``j`` in the program has been assigned to lie on the physical qubit labeled ``nj`` on
the device. This is strictly for human-readability: these comments are discarded and have no effect.

In addition, you have some control over how the compiler constructs its
rewiring, which is controlled by ``PRAGMA INITIAL_REWIRING``. The syntax is as follows.
Expand Down
4 changes: 2 additions & 2 deletions pyquil/_parser/Quil.g4
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ UNDERSCORE : '_' ;
// Whitespace

TAB : ' ' ;
NEWLINE : ( '\r'? '\n' | '\r' )+ ;
NEWLINE : (' ' | '\t' )* ( '\r'? '\n' | '\r' )+ ;

// Skips

COMMENT : '#' ~( '\n' | '\r' )* -> skip ;
COMMENT : (' ' | '\t' )* '#' ~( '\n' | '\r' )* -> skip ;
SPACE : ' ' -> skip ;

// Error
Expand Down
Loading

0 comments on commit 341e282

Please sign in to comment.