rmlarose / nisqai-dev

Development repository for NISQAI.
Apache License 2.0
15 stars 4 forks source link

Count the number of operations in a pyquil Program. #1

Closed rmlarose closed 5 years ago

rmlarose commented 5 years ago

There seems to be no easy way to do this, unfortunately, as the length of a Program includes operations like "DECLARE."

naezzell commented 5 years ago

After writing the circuit drawer, I think this could be solved. Before writing it, I need to address two things.

1.) Is DECLARE the only operation that takes up more than 1 line?

Supposing that that is true, then DECLARE is followed by a matrix. What I noticed is that the matrix lines are prepended with a tab so that str.split(' ') creates a list that begins with four empty strings. In that way, it would be easy to ignore directive lines by enumeration and then ignore any lines that begin with four empty spaces.

2.) Is ignoring based on open spaces/ enumeration of directives reliable? I know this would work for now, but does pyquil change often enough for this to deprecate often?

rmlarose commented 5 years ago

This was actually solved a while back by BaseAnsatz.depth, which iterates through the objects in a compiled program and counts the number of gates based on object type. Closing this issue -- this is probably more elegant than pattern matching in strings.