quil-lang / quilc

The optimizing Quil compiler.
Apache License 2.0
454 stars 73 forks source link

PRAGMA PRESERVE_BLOCK with PARTIAL rewiring causing compiler timeouts on Aspen-9 #718

Open jheckey opened 3 years ago

jheckey commented 3 years ago

Creating a minimal example of a program using PRAGMA PRESERVE_BLOCK and attempting to see the Native Quil that was generated when targeting the Aspen-9 lattice will generate a timeout in QuilC. The same program works for the '9q-square' lattice.

preserve_timeout.zip - Jupyter Notebook with minimal repro

Quil program:

PRAGMA INITIAL_REWIRING "PARTIAL"
DECLARE ro BIT[2]
RESET
H 0
PRAGMA PRESERVE_BLOCK
X 0  ;# <-- Substituting for RX(pi) 0 also fails
X 0
PRAGMA END_PRESERVE_BLOCK
CNOT 0 1
MEASURE 0 ro[0]
MEASURE 1 ro[1]

QuilC output:

$ quilc --verbose --log-level debug --host 127.0.0.1 -p 5555 -S
+-----------------+
|  W E L C O M E  |
|   T O   T H E   |
|  R I G E T T I  |
|     Q U I L     |
| C O M P I L E R |
+-----------------+
Copyright (c) 2016-2020 Rigetti Computing.

<134>1 2021-06-16T17:51:07Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 LOG0001 - Launching quilc.
<134>1 2021-06-16T17:51:07Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 - - Spawning server at (tcp://127.0.0.1:5555) .

<133>1 2021-06-16T17:51:08Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 LOG0001 - An update is available to the SDK. You have version 1.22.0. Version 1.23.0 is available from https://qcs.rigetti.com/sdk-downloads

<134>1 2021-06-16T17:51:14Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 - - Request c12a57ee-ebbf-4720-ad23-74149990b61f received for get_version_info
<134>1 2021-06-16T17:51:14Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 LOG0002 [rigetti@0000 methodName="get_version_info" requestID="c12a57ee-ebbf-4720-ad23-74149990b61f" wallTime="0.22" error="false"] Requested get_version_info completed
<134>1 2021-06-16T17:51:15Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 - - Request cc5cc4a1-8058-479f-8b93-9e46f90a2a0b received for get_version_info
<134>1 2021-06-16T17:51:15Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 LOG0002 [rigetti@0000 methodName="get_version_info" requestID="cc5cc4a1-8058-479f-8b93-9e46f90a2a0b" wallTime="0.002" error="false"] Requested get_version_info completed
<134>1 2021-06-16T17:51:15Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 - - Request e78223c2-a86e-4486-9ce4-02670336a698 received for get_version_info
<134>1 2021-06-16T17:51:15Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 LOG0002 [rigetti@0000 methodName="get_version_info" requestID="e78223c2-a86e-4486-9ce4-02670336a698" wallTime="0.0" error="false"] Requested get_version_info completed
<134>1 2021-06-16T17:51:15Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 - - Request e45bc26c-505d-4410-bb84-4e152a769352 received for quil_to_native_quil
<134>1 2021-06-16T17:51:18Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 LOG0002 [rigetti@0000 methodName="quil_to_native_quil" requestID="e45bc26c-505d-4410-bb84-4e152a769352" wallTime="2.837" error="false"] Requested quil_to_native_quil completed
<134>1 2021-06-16T17:51:18Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 - - Request 008444ce-0f43-4c05-a6f2-56c9df6753ab received for get_version_info
<134>1 2021-06-16T17:51:18Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 LOG0002 [rigetti@0000 methodName="get_version_info" requestID="008444ce-0f43-4c05-a6f2-56c9df6753ab" wallTime="0.0" error="false"] Requested get_version_info completed
<134>1 2021-06-16T17:51:18Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 - - Request cd694422-0ba4-4690-8188-8cd3e572fe79 received for quil_to_native_quil
<131>1 2021-06-16T17:51:28Z jupyter-00uskpcriqhwzu2b7356 quilc 1744 LOG0002 [rigetti@0000 methodName="quil_to_native_quil" requestID="cd694422-0ba4-4690-8188-8cd3e572fe79" wallTime="10.004" error="true"] Request cd694422-0ba4-4690-8188-8cd3e572fe79 error: Execution timed out.  Note: time limit: 0 seconds.
jheckey commented 3 years ago

I think I understand the root cause here. By explicitly setting the rewiring to strategy to PARTIAL the qubits that were targeted in the PRESERVE_BLOCK were not the same qubits that the circuit was remapped to. By setting the strategy to NAIVE I was able to successfully compile.

stylewarning commented 3 years ago

We should still look into why it's timing out. Even if the the use of PRESERVE_BLOCK isn't kosher, QUILC should not hang.

jheckey commented 3 years ago

With the more recent changes, I am seeing that it just appears to be the INITIAL_REWIRING "PARTIAL" and PRESERVE_BLOCK interactions in the pragmas. Previously I had seen other issues with PRESERVE_BLOCK allowing some bad things (allowing non-native/defcal'd gates, or even just invalid syntax) when going from Quil -> NativeQuil, but that seems to be resolved now.