-
Notifications
You must be signed in to change notification settings - Fork 55
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
Remove commented-out function definitions and delete files with no executable code #452
base: develop
Are you sure you want to change the base?
Conversation
…itions. Likely over-zealous.
These changes address unexpected behavior that can occur when manually adding an operation without then manually rebuilding the parameter vector. When this happens it is possible for the Model's internal attributes to fall out of sync with those of it's child objects. Now we check for the need to rebuild the parameter vector every time.
This is relevant when attempting to use Dask outside of pyGSTi, where signals cannot be set in the workers. Setting the PYGSTI_NO_CUSTOMLM_SIGINT env variable now skips this behavior.
A bug in the parameter label handling code was causing parameter labels to explode exponentially in size when _rebuild_paramvec was caused, leading to major memory issues. This now makes it so that the value of _paramlbls is fixed to that of the underlying operations and adds a new version of the parameter_labels property that goes through the interposer (making the interposer labels something generated on demand). Also add a threshold for coefficients printing in the LinearInterposer to avoid obnoxious labels.
The creation of COPA layouts relies on a number of specialized circuit structures which require non-trivial time to construct. In the context of iterative GST estimation with nested circuit lists (i.e. the default) this results in unnecessarily repeat construction of these objects. This is an initial implementation of a caching scheme allowing for more efficient re-use of these circuit structures across iterations.
Cache the expanded SPAM-free circuits to reduce recomputing things unnecessarily.
Adds a new method to OpModel that allows for doing instrument expansion and povm expansion in bulk, speeding things up be avoiding recomputation of shared quantities. Also adds a pipeline for re-using completed or split circuits (as produced by the related OpModel methods) for more efficient re-use of done work.
Some minor performance oriented tweaks to the init for COPA layouts.
Refactor some of the ordered dictionaries in matrix layout creation into regular ones.
Start adding infrastructure for caching things used in MDC store creation and for plumbing in stuff from layout creation.
Performance optimization for the method for adding omitted frequencies to incorporate caching of the number of outcomes per circuit (which is somewhat expensive since it goes through the instrument/povm expansion code). Additionally refactor some other parts of this code for improved efficiency. Also makes a few minor tweaks to the method for adding counts to speed that up as well. Can probably make this a bit faster still by merging the two calls to reduce redundancy, but that is a future us problem. Additionally make a few microoptimizations to the dataset code for grabbing counts, and to slicetools adding a function for directly giving a numpy array for a slice (instead of needing to cast from a list). Miscellaneous cleanup of old commented out code that doesn't appear needed any longer.
Fix a bug I introduced in dataset indexing into something that could be None.
Another minor bug caught by testing.
Improve the performance of __getitem__ when indexing into static circuits by making use of the _copy_init code path.
Implement caching of circuit structures tailored to the map forward simulator's requirements.
This finishes the process of refactoring expand_instruments_and_separate_povm from a circuit method to a method of OpModel.
Refactor expand_instruments_and_separate_povm to use the multi-circuit version under the hood to reduce code duplication.
I accidentally put down the wrong directory for temp testing files in the RB testing code.
01f3ccc
to
2cdfe87
Compare
Hi @pcwysoc, @kmrudin, @kevincyoung, @adhumu, and @sserita. This pull request is a big spring-cleaning for commented-out code. You're all designated as code-owners for files that are affected by this pull request. Please review the changes for files you "own" and let me know if you object to removing specific blocks of commented-out code. Things to keep in mind:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto what Piper said. Stefan and I were working on changing parts of ForwardSims in a different branch and on my local computer. This part of the code is still in development. I'm happy to approve these changes, thanks Riley!
@@ -79,11 +79,6 @@ def label_index(self, label, ok_if_missing=False): | |||
return None | |||
return self._label_indices[label] | |||
|
|||
#@property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: Check whether or not I resuscitated this code or not on the error generator propagation branch. If so this shouldn’t be deleted here (will probably create stuff to clean up upon merging).
@@ -558,574 +543,6 @@ def to_rep(self): # , max_num_vars=None not needed anymore -- given at __init__ | |||
Polynomial = FASTPolynomial | |||
|
|||
|
|||
# class SLOWPolynomial(dict): # REMOVE THIS CLASS (just for reference) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleting this looks fine, but with this deleted we should rename the other class in this file as simply Polynomial, instead of FASTPolynomial (which is how it is currently being aliased anyhow).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: turn the slow polynomial into a unit test for FASTPolynomial (to be Polynomial)
@@ -727,24 +727,6 @@ cdef class OpRepExpErrorgen(OpRep): | |||
return _copy.deepcopy(self) # I think this should work using reduce/setstate framework TODO - test and maybe put in base class? | |||
|
|||
|
|||
#TODO: can add this after creating OpCRep_IdentityPlusErrorgen if it seems useful | |||
#cdef class OpRepIdentityPlusErrorgen(OpRep): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which rep type currently covers the identity plus error generator object? Is this already covered, or are we deficient in this regard in which case should this be re-enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to look into this
pygsti/models/model.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to merge in latest develop. This code was merged in with #482 so shouldn’t be showing up in the diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird. I just tried to rebase from develop, and git says that this branch is already up to date. I'll poke around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the GitHub summary of changes might be messed up. I experimented by creating a copy of the current develop branch and then merging in this branch to that copy. The summary of changes in the command line interface didn't include additions to this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will likely be adding real tests for this module as part of a pending PR I have. If this is a full deletion let’s keep this file for now to avoid merge issues.
Whoops, forgot to add the top-level comment for my review. TLDR: Good work @rileyjmurray. It will be a while till most of us can vie for the crown of most lines written, but at this pace you’re definitely in the running for most lines of pyGSTi deleted! I’ll defer judgement to other code owners for stuff they manage (i.e. a lack of comment may just mean I am waiting for one of them to decide whether to chime in rather than explicit approval), but have added a few comments regarding code I would like to keep, as well as a few minor suggestion for additional deletion related clean-up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why I made this change. Reverting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2/3 of the way check-in
@@ -21,92 +21,6 @@ | |||
|
|||
from . import randomcircuit as _rc | |||
|
|||
# ### TODO: THIS IS TIMS OLD CODE WHICH SHOULD PERHAPS ALSO BE AN OPTION IN THE `CREATE_MIRROR_CIRCUIT` FUNCTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tim's old mirroring code.
@@ -198,139 +198,6 @@ def find_all_sets_of_compatible_two_q_gates(edgelist, n, gatename='Gcnot', aslab | |||
return co2Qgates | |||
|
|||
|
|||
# TJP: I am not aware this is ever used anymore, and it's functionality is possibly even included in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More Tim RC code
@@ -17,132 +17,6 @@ | |||
from pygsti.tools import rbtools as _rbt | |||
|
|||
|
|||
# Obsolute function to be deleted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tim RB fitting.
@@ -558,574 +543,6 @@ def to_rep(self): # , max_num_vars=None not needed anymore -- given at __init__ | |||
Polynomial = FASTPolynomial | |||
|
|||
|
|||
# class SLOWPolynomial(dict): # REMOVE THIS CLASS (just for reference) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: turn the slow polynomial into a unit test for FASTPolynomial (to be Polynomial)
# + self.op_rep.chp_ops(seed_or_state=seed_or_state) | ||
|
||
# TODO: Untested, only support computational and composed for now | ||
#class StateRepTensorProduct(StateRep): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Stefan to check out
|
||
|
||
#UNUSED - I think we can remove this | ||
#class DensePOVMEffect(_POVMEffect): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: DensePOVMEffect reference
@@ -207,85 +207,6 @@ def __reduce__(self): | |||
self.sslbls_after_marginalizing), | |||
{'_gpindices': self._gpindices}) # preserve gpindices (but not parent) | |||
|
|||
#May need to implement this in future if we allow non-static MarginalizedPOVMs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: non-static MarginalizedPOVM ideas
@@ -272,16 +272,6 @@ def __mul__(self, x): | |||
def __rmul__(self, x): | |||
return self.__mul__(x) | |||
|
|||
#Not needed - but we would use this if we changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave this
@@ -42,127 +42,6 @@ def _get_cachefile_names(std_module, param_type, simulator, py_version): | |||
raise ValueError("No cache files used for param-type=%s" % param_type) | |||
|
|||
|
|||
# XXX is this used? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was used for modelpack generation. Fine to remove but note TermForwardSim caching for model packs
# items = [(k,v) for k,v in self.iteritems()] | ||
# return (_PrefixOrderedDict, (self._prefix, items), None) | ||
|
||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove reduce, but leave docstring
I’m guessing I’m meant to be doing something? My main reaction to this pull request is/was “argh I’m pretty sure some of that commented out code should be revived, but I have no time to even think about this”. That’s probably very unhelpful, but that’s how it is right now. -T
From: Stefan Seritan ***@***.***>
Date: Tuesday, November 12, 2024 at 11:53 AM
To: sandialabs/pyGSTi ***@***.***>
Cc: Proctor, Timothy James ***@***.***>, Mention ***@***.***>
Subject: [EXTERNAL] Re: [sandialabs/pyGSTi] Remove commented-out function definitions and delete files with no executable code (PR #452)
<<< Insert lots of content here >>>
—
Reply to this email directly, view it on GitHub<#452 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFQEBIBJDOEXVBODCBD527L2AI5VXAVCNFSM6AAAAABI6RXALOVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIMZQGIZDSOBYGI>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Nah, you're good, Tim. No action items for you!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The majority of my comments are just personal notes for things we should highlight/bookmark in the PR in case we want to come back and revive them later.
Some of my comments are things I would like to be left in, and at least one is an item I need to dig further into to decide.
Thanks for your hard work in help clean up the code, it is super appreciated!
@@ -662,90 +662,6 @@ def _evaluate(individual): | |||
return solution | |||
|
|||
|
|||
#def fmin_homebrew(f, x0, maxiter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark that we are removing some of Erik's experimental optimizer algorithms
#class PassStabilityTest(_proto.Protocol): | ||
# pass | ||
|
||
# Commented out as we are not using this currently. todo: revive or delete this in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark that we are removing VBGrid code that may be revived later
#This older version on an RB decay plot contained a lot more theory detail | ||
# compared with the current one - so we'll keep it around (commented out) | ||
# in case we want to steal/revive pieces of it in the future. | ||
#class OLDRandomizedBenchmarkingPlot(WorkspacePlot): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark RB plotting that may want to be revived later
@@ -458,255 +458,6 @@ def R_matrix(model, group, group_to_model=None, weights=None): # noqa N802 | |||
|
|||
return R | |||
|
|||
### COMMENTED OUT SO THAT THIS FILE DOESN'T NEED "from .. import construction as _cnst". | |||
### THIS SHOULD BE ADDED BACK IN AT SOME POINT. | |||
# def exact_rb_asps(model, group, m_max, m_min=0, m_step=1, success_outcomelabel=('0',), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More RB tools in case we need to revive them.
@@ -1,62 +0,0 @@ | |||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Corey mentioned, keep this file for now to avoid merge issues with his branch.
This PR aims to resolve #428.
At time of opening this PR, the changes might be over-zealous, so I'm happy to roll some changes back. That said, I suggest we be aggressive in removing this kind of unused text. Here's a proposal for how to decide what to actually keep and what to remove:
Another source of criteria for figuring out what to keep is to look for a short note at the beginning of some commented-out code block. Often there are notes that say "FUTURE," "Removed," "unused," "REMOVE," "Debugging," etc...
Other, miscellaneous changes