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

Greedy term grouping #754

Merged
merged 43 commits into from
Jan 31, 2019
Merged

Conversation

msohaibalam
Copy link
Contributor

@msohaibalam msohaibalam commented Jan 5, 2019

Greedy grouping method for TomographyExperiments.

fixes #718

Copy link
Contributor

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

Please refactor to reduce the total number of different data structures / representations of PauliTerms and the number of conversions between these representations

return diagonal_sets


def _commuting_sets_by_zbasis_tomo_expt(tomo_expt: TomographyExperiment):
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this function name mean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed this function to _max_tpb_overlap(..), and moved the other function formerly named so into this one.

# loop through dict items
for key, es_list in diagonal_sets.items():
# determine if key is diagonal in the same tpb as expt_setting
b_diagonal_tpb = _expt_settings_diagonal_in_tpb(key, expt_setting)
Copy link
Contributor

Choose a reason for hiding this comment

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

better variable name than key?

Copy link
Contributor

Choose a reason for hiding this comment

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

put this line in an if to avoid nebulously named b_diagonal_tpb?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

diagonalizing_in_term = _get_diagonalizing_basis([es.in_operator for es in updated_es_list])
diagonalizing_out_term = _get_diagonalizing_basis([es.out_operator for es in updated_es_list])
# update the diagonalizing basis (key of dict) if necessary
if len(diagonalizing_in_term) > len(key.in_operator) or len(diagonalizing_out_term) > len(key.out_operator):
Copy link
Contributor

Choose a reason for hiding this comment

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

this "or" seems dangerous. What if one is larger and the other is (much) smaller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can't be true that one is larger and the other smaller. In fact, neither can be smaller than their respective counterparts. I've added assert checks to ensure this. The "or" is basically just saying to update the tpb if either the in-term or out-term can't be measured with the current tpb; the idea being that if either of those checks fail, the experiment as a whole can't be carried out in the same tpb.

return diagonal_sets


def group_experiments_greedy(tomo_expt: TomographyExperiment):
Copy link
Contributor

Choose a reason for hiding this comment

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

on the subject of grouping: try to organize the functions within this file:

  • similar / analogous functionality (ie the two "group" functions) should live near each other
  • try to order it so things only call functions defined above them culminating in the meaty user-facing functions at the bottom or at the bottom of a group of related functionality (use your judgement)

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've re-organized as follows:

  • At the very top sit the classes (ExperimentSetting, etc.) and any private helper functions they need
  • The class definitions are followed by some functionality converting operator_estimation objects to/from JSONs
  • In the middle is the user-facing function measure_observables(..) immediately preceded by its private helper functions
  • Towards the end sit the user-facing functions for grouping, similarly preceded by private helper functions needed to define them

@msohaibalam
Copy link
Contributor Author

@mpharrigan Changes (from merge) look good!

@mpharrigan mpharrigan merged commit db42246 into rigetti:master Jan 31, 2019
@msohaibalam msohaibalam deleted the greedy_term_grouping branch January 31, 2019 23:05
@karalekas karalekas modified the milestones: v2.5.0, v2.4.0 Feb 14, 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.

Greedy term grouping in operator estimation
3 participants