Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor operator estimation and replace measure_observables #127

Merged
merged 25 commits into from
Jun 11, 2019

Conversation

kylegulshen
Copy link
Contributor

This is the first step in refactoring this repo to use a standard workflow and move away from dataframes.

operator_estimation.py originated in this repo but was copied over to pyquil and modified extensively. The version of the file in fb/master is outdated, and only the pyquil version is currently ever used within forest benchmarking. Commit 504f032 replaces the outdated version with the latest version from pyquil. Subsequently commit 31aa7aa reflects my changes to the pyquil version along with the updates to the tests. Looking at the diff between these commits will be more instructive, and in particular looking at the changes to the tests should provide a general sense of the change in usage. I've also included a notebook with outputs preserved for convenient inspection of usage.

Note that some things were simply renamed rather than substantively changed. The main update is to decompose measure_observables into several steps, each of which works with lists of programs.

@kylegulshen kylegulshen requested a review from a team as a code owner May 23, 2019 18:05
@@ -57,6 +57,17 @@ def _RY(angle, q):
return p


def _RX(angle, q):
"""
A RX in terms of RX(+-pi/2) and RZ(theta)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring doesn't match the generated Program. I think you intended to swap RZ and _RY below?

Copy link
Contributor

@blakejohnson blakejohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have a chance to a thorough deep dive, but from what I can see, you've already split measure_observables into more digestable chunks.

@kylegulshen kylegulshen changed the title [WIP] Refactor operator estimation and replace measure_observables Refactor operator estimation and replace measure_observables May 28, 2019
Copy link
Contributor

@joshcombes joshcombes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

I agree with your suggestion of observable_estimation.py as this module does not estimate generic operators.

I have some minor comments, fix them if you think they improve things. I'll send you a slack with one larger comment that we might need to discuss in person. None of the above should block you from merging.

forest/benchmarking/operator_estimation.py Show resolved Hide resolved
forest/benchmarking/operator_estimation.py Outdated Show resolved Hide resolved

@property
def in_operator(self):
warnings.warn("ExperimentSetting.in_operator is deprecated in favor of in_state",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again maybe something we can debate later.

Im in three minds [1] about in_state . We seem to have a conceptually mixed abstraction. We use an in_state and have an out observable often we conjugate Pauli inputs by Cliffords (we can conjugate by anything if we want but the DFE stuff works on the group property of cliffords). This seems like a Heisenberg representation of the circuit. But the in state is Schrodinger like.

One way forward would be to have an object prefix_program (with metadata saying if it is clifford or not) adn a sufix_program.

Anyway this issue is probably too large for this PR to take on, it would need input from others...

[1] Well two, but I dislike saying "I'm in two minds about X"

forest/benchmarking/operator_estimation.py Show resolved Hide resolved
if use_basic_compile:
programs.append(basic_compile(total_prog))
else:
programs.append(total_prog)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again not a problem now, but for future use by others do we a compilation step in the else branch?

forest/benchmarking/operator_estimation.py Show resolved Hide resolved
forest/benchmarking/operator_estimation.py Outdated Show resolved Hide resolved
forest/benchmarking/operator_estimation.py Outdated Show resolved Hide resolved
forest/benchmarking/operator_estimation.py Outdated Show resolved Hide resolved
def _RX(angle, q):
"""
A RX in terms of RZ(+-pi/2) and _RY(theta), which is itself decomposed
into native gates RX(+-pi/2) and RZ(theta) above.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, you've made the docstring consistent with the program, but this way of compiling an RX doesn't make much sense to me, unless you are trying to re-use code from the definition of _RY. This is one case where that code re-use instinct works counter to code readability, and so you should instead just write a proper definition of RX in terms of Zs and RX(pi/2)s.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure if I executed your suggestion correctly--if you mean that the sequence of gates itself should be different, then I'm not sure what sequence is simpler. The sequence here matches the output of the compiler.

@mpharrigan
Copy link
Contributor

wait, why are you copying all of this in from pyquil? Why not just use the pyquil version and contribute changes there, "upstream"? Or layer your changes on top of it

@joshcombes
Copy link
Contributor

Hey Matt, based on some requirements from the lower level of the stack we (well Kyle) are refactoring operator_estimation. The idea would be to port it back to pyQuil. But at the moment we need to rapidly iterate the code and that is hard to do in pyQuil.

* Update DFE to match changes to operator estimation.

* Fix op_est calibration coefficient bug

* In op_est tests seed qc where possible, reduce number of repetitions, and increase tolerance
kylegulshen and others added 5 commits June 11, 2019 13:07
* Clean up utils pauli term creation and change name.

* Update tomography after operator_estimation changes.

* Refactor RB and unitarity to use ObservablesExperiment (#133)

* Separate out optional explicit rb sequence generation path

* Make calculation of rb variance account for covariance.

* Updated rb notebooks and changed specification of depths.

* Make rb fitting consistent with qbspec
* Move qbspec tests to fitting tests

* Adjusted T2 experiments including a bug fix for T2echo.

* standardize qbspec fitting/plotting around probability of 'measuring 1'.
* Refactor rpe generation to be more general.
@kylegulshen kylegulshen merged commit fe15c06 into master Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants