rigetti / pyquil

A Python library for quantum programming using Quil.
http://docs.rigetti.com
Apache License 2.0
1.41k stars 342 forks source link

Memory Declaration are sometimes moved to the top of the program #1667

Open bramathon opened 1 year ago

bramathon commented 1 year ago
from pyquil.quil import Program

print(Program("DEFGATE DDXX_184:\n    1.0, 0.0\n    0.0, 1.0\n\nDDXX_184 2\nCPHASE(0.1) 0 1\nDECLARE ro BIT[3]\nMEASURE 0 ro[0]\nMEASURE 1 ro[1]\nMEASURE 2 ro[2]\n").out())

Yields:

DECLARE ro BIT[3]
DEFGATE DDXX_184 AS MATRIX:
    1, 0
    0, 1

DDXX_184 2
CPHASE(0.1) 0 1
MEASURE 0 ro[0]
MEASURE 1 ro[1]
MEASURE 2 ro[2]

Possibly related to #1666

MarquessV commented 1 year ago

For now at least, this is intended behavior on the part of quil-rs.

bramathon commented 1 year ago

The problem here is that this seems to be non-deterministic. Sometimes the declarations are at the top, sometimes they are not.