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

Replace calls with .flatten() to .ravel() when appropriate #451

Merged
merged 5 commits into from
Jul 30, 2024

Conversation

rileyjmurray
Copy link
Contributor

@rileyjmurray rileyjmurray commented Jun 6, 2024

This PR aims to resolve #431. It also resolves #424 because "why not."

More specific changes:

  • removed a giant commented-out code block in algorithms/randomcircuit.py.
  • replaced some calls to np.dot with @.
  • simplified some code branching in a handful of cases.
  • reduced use of multiple statements per line. Example: rewrite x = []; y = [] as x, y = [], [].
  • I've left a note asking if it's cool to remove commented-out code in a function function in matrixtools.py.
  • removed matrixtools.py::residuals(a, b) and inlined equivalent code where needed.
  • replaced instances of np.vdot(a.flatten(), b.flatten()) with np.vdot(a, b).
  • changed code like list(array.flatten()) with list(array.flat) instead of list(array.ravel()).
    • Apparently ravel is often faster than flat, so I'm actually sticking with ravel.

@rileyjmurray rileyjmurray changed the base branch from master to develop June 6, 2024 20:12
@rileyjmurray rileyjmurray changed the title WIP: replace calls with .flatten() to .ravel() when appropriate Replace calls with .flatten() to .ravel() when appropriate Jun 6, 2024
@rileyjmurray rileyjmurray marked this pull request as ready for review June 7, 2024 11:20
@rileyjmurray rileyjmurray requested review from a team and pcwysoc as code owners June 7, 2024 11:20
@rileyjmurray rileyjmurray requested a review from sserita June 7, 2024 11:20
Copy link

@pcwysoc pcwysoc 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 to me for my file! One thing I'd keep in mind that you will have to do this file (workspacesplots.ipynb) again when Corey merges in his substantial reporting changes since I doubt the auto-merge will catch this.

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.

Great work, @rileyjmurray! I have left some comments answering the questions that you had asked and pointed out a few (minor) inefficiencies. @sserita, none of my feedback is blocking, so feel free to approve this whenever you and @rileyjmurray think it is ready.

@@ -432,13 +432,13 @@ def deriv_wrt_params(self, wrt_filter=None):
dMx = _np.zeros((self.dim, self.dim), 'complex')
for prefactor, (i, j) in pdesc:
dMx[i, j] = prefactor
tmp = _np.dot(self.B, _np.dot(dMx, self.Bi))
tmp = self.B @ (dMx @ self.Bi)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to future selves (no immediate action item): I am pretty sure that dMx should either be diagonal for non-degenerate matrices, in which case we can do the first product in O(n^2) time, or else block-diagonal (degenerate case) in which case we should still be able to get a speedup by leveraging that structure.

pygsti/report/reportables.py Outdated Show resolved Hide resolved
pygsti/report/reportables.py Show resolved Hide resolved
pygsti/report/workspaceplots.py Outdated Show resolved Hide resolved
pygsti/tools/matrixtools.py Outdated Show resolved Hide resolved
@robinbk
Copy link
Contributor

robinbk commented Jun 12, 2024 via email

…ere originally .flatten(), which is strictly worse than ravel()), and simplify calculations in pygsti/report/reportables.py::general_decomposition
Copy link
Contributor

@sserita sserita left a comment

Choose a reason for hiding this comment

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

Everything looks good to me, thanks @rileyjmurray!

@sserita sserita merged commit 911118c into develop Jul 30, 2024
4 checks passed
@sserita sserita deleted the flatten-vs-ravel branch July 30, 2024 20:44
@sserita sserita added this to the 0.9.13 milestone Jul 30, 2024
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.

Replace unnecessary calls to .flatten() with .ravel().
5 participants