Skip to content

WIP: TVD objective in GST #506

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

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from
Draft

WIP: TVD objective in GST #506

wants to merge 24 commits into from

Conversation

rileyjmurray
Copy link
Contributor

@rileyjmurray rileyjmurray commented Nov 20, 2024

I noticed there's a total variance distance objective function class which is almost finished. The only missing functions for the code to run without formally raising an error were RawTVDFunction.dterms and RawTVDFunction.chi2k_distributed_qty. The former function has a very simple "canonical" implementation, but it's numerically problematic since the 1-norm isn't differentiable at any vector with a zero component. I don't know what a mathematically correct version of the second function looks like (or if there is such an implementation) so I just have it return -1 to indicate "this doesn't mean what you think it means."

I'm mostly opening this PR to facilitate QPL-internal discussion on the topic.

You can run GST where the final iteration is TVD-based instead of log-likelihood using something like the following.

models, opt_results, cache = pygsti.algorithms.run_iterative_gst(
    dataset, starting_model, lsgst_circuit_list_of_lists,
    optimizer={'tol': 1e-5}, resource_alloc=None, verbosity=4,
    iteration_objfn_builders=['chi2'], final_objfn_builders=['tvd']
)

rileyjmurray and others added 6 commits February 17, 2025 13:35
…eparately, modify docstring for run_long_sequence_gst to be consistent with its implementation (including leaving notes for later).
…uge_group. Having the casting occur here makes sense, since a model has access to the associated StateSpace, Basis, and Evotype.
…tchboard.objfn_builder was used when switchboard.objfn_builder_modvi should have been used
@rileyjmurray
Copy link
Contributor Author

@pcwysoc I merged in changes from develop and now I'm getting errors in my example script. I'm working on getting this ready for you to experiment with.

@rileyjmurray
Copy link
Contributor Author

@pcwysoc my latest push includes an example notebook you can use to get started. LMK if you have any questions!

Comment on lines +388 to +392

HISTORICAL NOTE: "XX" indicates that we've at least _intended_ for the
keyword argument to be removed. I've removed documentation for options
that we never reference in the code (truncScheme, estimate_label, and
missingDataAction).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could move this change (and related changes below) to another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to document why changes to this file were needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can move this change to another PR.

Comment on lines +5244 to +5245
# QUESTION: could I just call the base class's implementation of terms and then scale the
# result? If so then I can avoid a ton of code duplication.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to resolve this question before merge.

Comment on lines +5286 to +5287
# QUESTION: could I just call the base class's implementation of dterms and then scale the
# leading rows of the result? If so then I can avoid a ton of code duplication.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to resolve this before merge.

Comment on lines +307 to +309
switchBd.objfn_builder[d, i] = _objfns.ObjectiveFunctionBuilder.create_from('logl') # est.parameters.get('final_objfn_builder', _objfns.ObjectiveFunctionBuilder.create_from('logl'))
switchBd.objfn_builder_modvi[d, i] = _objfns.ObjectiveFunctionBuilder.create_from('logl')
# est_modvi.parameters.get('final_objfn_builder', _objfns.ObjectiveFunctionBuilder.create_from('logl'))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to explain why these changes were made.

Comment on lines +1173 to +1198
- skip_sections : tuple[str], optional
Contains names of standard report sections that should be skipped
in this particular report. Strings will be cast to lowercase,
stripped of white space, and then mapped to omitted Section classes
as follows

{
'summary' : SummarySection,
'goodness' : GoodnessSection,
'colorbox' : GoodnessColorBoxPlotSection,
'invariantgates' : GaugeInvariantsGatesSection,
'invariantgerms' : GaugeInvariantsGermsSection,
'variant' : GaugeVariantSection,
'variantraw' : GaugeVariantsRawSection,
'variantdecomp' : GaugeVariantsDecompSection,
'varianterrorgen' : GaugeVariantsErrorGenSection,
'input' : InputSection,
'meta' : MetaSection,
'help' : HelpSection
}

A KeyError will be raised if skip_sections contains a string
that is not in the keys of the above dict (after casting to
lower case and stripping white space).


Copy link
Contributor Author

@rileyjmurray rileyjmurray Apr 17, 2025

Choose a reason for hiding this comment

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

This can be moved to another PR, along with the changes below.

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.

1 participant