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

physics/quantum: wrapper class for python functions used in OracleGate #22887

Merged
merged 5 commits into from
Feb 17, 2022

Conversation

ThePauliPrinciple
Copy link
Contributor

@ThePauliPrinciple ThePauliPrinciple commented Jan 19, 2022

References to other Issues or PRs

Brief description of what is fixed or changed

Currently python functions are stored directly in OracleGate's
args. This is now updated to use a wrapper Atom class.

Other comments

Release Notes

  • physics.quantum
    • The wrapper class OracleGateFunction is now provided for python functions used in OracleGate.

Currently python functions are stored directly in `OracleGate`'s
args. This is now updated to use a wrapper `Atom` class.

def return_one_on_one(qubits):
return qubits == IntQubit(1, nqubits=qubits.nqubits)

return_one_on_one=OracleGateFunction(return_one_on_one)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess you could use this as a decorator like:

@OracleGateFunction()
def return_one_on_one(qubits):
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I'll add such an example to the docstring too, since it is potentially a lot more convincing for a user to use it in that way.

@oscarbenjamin
Copy link
Collaborator

Looks good

@sympy-bot
Copy link

sympy-bot commented Jan 19, 2022

Hi, I am the SymPy bot (v163). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • physics.quantum
    • The wrapper class OracleGateFunction is now provided for python functions used in OracleGate. (#22887 by @ThePauliPrinciple)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.11.

Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->


#### Brief description of what is fixed or changed
Currently python functions are stored directly in `OracleGate`'s
args. This is now updated to use a wrapper `Atom` class.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* physics.quantum
  * The wrapper class `OracleGateFunction` is now provided for python functions used in `OracleGate`.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@ThePauliPrinciple
Copy link
Contributor Author

@asmeurer I approached this from a computer science point of view, so I am not sure if this is also a convenient approach from quantum physics point of view

@github-actions
Copy link

github-actions bot commented Jan 20, 2022

Benchmark results from GitHub Actions

Lower numbers are good, higher numbers are bad. A ratio less than 1
means a speed up and greater than 1 means a slowdown. Green lines
beginning with + are slowdowns (the PR is slower then master or
master is slower than the previous release). Red lines beginning
with - are speedups.

Significantly changed benchmark results (PR vs master)

       before           after         ratio
     [1c20bad3]       [55bc0463]
+      63.7±0.3μs        97.6±30μs     1.53  lambdify.TimeLambdifyEvaluate.time_lambdify_evaluate(['numpy'])

Significantly changed benchmark results (master vs previous release)

       before           after         ratio
     [907895ac]       [1c20bad3]
-         255±4ms        155±0.5ms     0.61  large_exprs.TimeLargeExpressionOperations.time_subs
-     17.1±0.04ms      11.1±0.01ms     0.65  matrices.TimeMatrixExpression.time_MatAdd_doit
-        274±10μs          122±2μs     0.45  matrices.TimeMatrixExpression.time_MatMul
-     16.6±0.06ms      8.56±0.07ms     0.51  matrices.TimeMatrixExpression.time_MatMul_doit
-      4.88±0.02s          358±2ms     0.07  polygon.PolygonArbitraryPoint.time_bench01
+      3.92±0.1ms      6.56±0.07ms     1.68  solve.TimeMatrixOperations.time_det(4, 2)
+      3.92±0.1ms      6.65±0.06ms     1.70  solve.TimeMatrixOperations.time_det_bareiss(4, 2)
+      44.1±0.3ms       77.5±0.3ms     1.76  solve.TimeMatrixSolvePyDySlow.time_linsolve(1)
+      44.7±0.1ms       78.0±0.2ms     1.74  solve.TimeMatrixSolvePyDySlow.time_solve(1)

Full benchmark results can be found as artifacts in GitHub Actions
(click on checks at the top of the PR).

@ThePauliPrinciple
Copy link
Contributor Author

With the conversion now being done by the OracleGate class, the API doesn't need to change at all, so I reverted all the docs and test changes.

@oscarbenjamin
Copy link
Collaborator

Looks good to me

@ThePauliPrinciple ThePauliPrinciple merged commit 3821fd7 into sympy:master Feb 17, 2022
@ThePauliPrinciple ThePauliPrinciple deleted the oraclegate_function branch February 17, 2022 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants