Skip to content

Conversation

@rileyjmurray
Copy link
Contributor

@rileyjmurray rileyjmurray commented Sep 23, 2025

This resolves issue #655.

There's a change to the public API for Report.write_notebook and changes to the code in the notebook it generates. Report.write_notebook only saves data as a pickle if it's called with kwarg use_pickle=True. There's a new Report.results_dict_from_dir function that can accept either the a filename with a .pkl extension or a directory name. If the pkl extension is present then we try to load from a pickle (to ensure backward-compatibility). Otherwise, we try to load from a directory generated by the new Report.write_results_dict function.

I introduced a little testing infrastructure so our write_notebook test actually runs the notebooks that it generates. I also added a test that that calls Report.write_notebook with kwarg use_pickle=True.

…rates. Make changes to get that test to pass.
…cceed when Estimate.circuit_weights is a nontrivial dict keyed by Circuit objects. This solution to enabling Estimate.write(...) is not the most elegant. It also doesnt make Estimate NicelySerializable. But this solution is useful.
…N serialization (as opposed to pickling, which was used up until this commit)
…ons. Use these to simplify code in write_notebook (both code executed there and code generated there). Add a test for Report.write_notebook which uses kwarg use_pickle=True.
@rileyjmurray rileyjmurray requested review from a team and pcwysoc as code owners September 23, 2025 17:30
Copy link
Contributor

@pcwysoc pcwysoc Sep 23, 2025

Choose a reason for hiding this comment

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

Glad to see the ErrgenTable fixed!

Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate this warning.

return self.IS_SIMPLE



Copy link
Contributor Author

Choose a reason for hiding this comment

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

There should only be two blank lines between class definitions.

self._bare_init(labels, my_line_labels, editable, name, stringrep,
occurrence, compilable_layer_indices_tup)


Copy link
Contributor Author

Choose a reason for hiding this comment

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

There should only be one blank line between method definitions.

self._hashable_tup = self.tup
self._hash = hash(self._hashable_tup)


Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two blank lines between class definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted several spurious blank lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes to this file fix a longstanding bug about calling .write() on Estimate objects whose circuit_weights member is a non-empty dict. The fix is to transform circuit_weights from a dict[Circuit,float] to a dict[str,float] before serializing.

None
"""
if self.circuit_weights is not None:
self.circuit_weights = {getattr(c,'str',c): v for c,v in self.circuit_weights.items()}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The dict comprehension uses getattr in case self.circuit_weights is already keyed by strings.

@rileyjmurray rileyjmurray changed the title WIP: enhancements and bugfixes in Report.write_notebook Enhancements and bugfixes in Report.write_notebook Sep 23, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added newline at end of file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added newline at end of file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nbformat is needed for tests in test_packages to run successfully. I can't figure out if nbformat is an explicit dependency of notebook (it is, after all, the reference implementation of the Jupyter notebook format), but there's no harm in making its dependency explicit for us.

Copy link
Contributor

@coreyostrove coreyostrove left a comment

Choose a reason for hiding this comment

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

Looks great, thank you for your effort purging these pickle stragglers, @rileyjmurray!

@coreyostrove coreyostrove merged commit cba9c6b into develop Sep 30, 2025
4 checks passed
@coreyostrove coreyostrove deleted the resolve-issue-655 branch September 30, 2025 23:53
@coreyostrove coreyostrove added this to the 0.9.15 milestone Sep 30, 2025
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.

3 participants