forest-benchmarking icon indicating copy to clipboard operation
forest-benchmarking copied to clipboard

Name "ro" already declared in tomography

Open ellishg opened this issue 6 years ago • 4 comments

If a program has a variable named "ro" then doing tomography will throw the error

rpcq._utils.RPCError: At line 3: The name "ro" has been DECLAREd more than once.

Here's a simple reproducer

from pyquil import Program, get_qc
from forest.benchmarking.tomography import generate_state_tomography_experiment
from pyquil.operator_estimation import measure_observables

pq = Program()
pq.declare("ro") # "_ro" fixes the issue

experiment = generate_state_tomography_experiment(pq, [0])
list(measure_observables(qc=get_qc("1q-qvm"), tomo_experiment=experiment))

This is a problem, especially since this is a common variable name.

ellishg avatar May 30 '19 23:05 ellishg

Currently "ro" is the required register name for reading out bits from measurement, so indeed if the program passed into generate_..._experiment(program, ...) is already measuring qubits then the described error will occur. The current assumption is that the input program simply prepares a state and the methods provided in the tomography module will append the necessary measurement instructions. Given the assumption that the program was created solely for the purpose of state preparation, we expect that we need to declare 'ro' in order to perform the measurements necessary for tomography.

Could you further explain your use-case and your expectation of the behavior of tomography? It would help identify the assumptions above that may need to be updated. Depending on your specific use I could see the solution varying in complexity.

kylegulshen avatar Jun 03 '19 23:06 kylegulshen

We are experimenting with running tomography on programs that might have measurements and control flow. Since the program comes from a user, we don't really have control over the names of declared variables.

ellishg avatar Jun 03 '19 23:06 ellishg

Would it be sufficient to ask the user to provide their pre-declared ro register as an optional argument, in which case tomography would readout qubit q into ro[q]? (Or additionally ask for a qubit-to-ro-index map so it doesn't have to be q -> ro[q])?

kylegulshen avatar Jun 05 '19 19:06 kylegulshen

I think that would work. Maybe this requires a change to pyQuil, but would it be possible to generate a unique name that is not found in the user's program? A hacky fix could be to rename "ro" to something that the user probably will never use. Something like "forest-benchmarking-tomography-readout"?

ellishg avatar Jun 06 '19 04:06 ellishg