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

Add dispatcher capacity to support any type specialisation #2157

Merged
merged 13 commits into from Jul 6, 2023

Conversation

Ericgig
Copy link
Member

@Ericgig Ericgig commented Apr 19, 2023

Description
Allow the dispatcher to accept specialisations on generic Data.
This as 2 uses:

  • Simplify the creation of complex function using simpler ones: inner defined in term of matmul.
  • Allow us to create niche dispatched functions for some data layer without the need to be supported by all: blas' zgemm (matmul) can transpose and adjoint of each input matrix in the same operation.

The Data dispatched functions have less priority than direct specialization. They are used directly (no _constructed_specialisation) when the Data is in the inputs, but when the output data type is set, there will always be a conversion from Data to the desired type.

In this PR:

  • Add dispatch on Data.
  • Add direct tests for the dispatcher.
  • Create kron_transpose which is kron(left.T, tright). It's commonly used for superoperator and it can be optimized for Dense and Jax by doing it in one operation.
  • Add Data specialization for inner, inner_op, expect, expect_super and trace_oper_ket.
  • Make zeros_like and identity_like as dispatched function so the order is kept during operation for dense.

@coveralls
Copy link

Coverage Status

Coverage: 77.746% (+0.01%) from 77.733% when pulling 357673b on Ericgig:feature.data.dispatch into fc9c580 on qutip:master.

@coveralls
Copy link

Coverage Status

Coverage: ?%. Remained the same when pulling 0bcd59f on Ericgig:feature.data.dispatch into fc9c580 on qutip:master.

@coveralls
Copy link

coveralls commented Apr 19, 2023

Coverage Status

coverage: 78.118% (+0.01%) from 78.106% when pulling 932ad81 on Ericgig:feature.data.dispatch into f66b8f2 on qutip:master.

Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

I left a few small comments, but overall this looks great.

if not output:
out = dispatched(*ins)
out = dispatched[in_types](*ins)
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what is happening with this continue statement. Perhaps we can just do:

if not output:
    ...
else:
    ... rest of the current loop without all the `if output:` checks


def test_Data_low_priority_one_dispatch():
class func():
__name__ = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

If __name__ has to be here, can we put something in it like __name__ = "dummy name" rather than leaving it blank which just looks a bit odd.

qutip/core/data/convert.pyx Outdated Show resolved Hide resolved
qutip/core/data/convert.pyx Outdated Show resolved Hide resolved
Co-authored-by: Simon Cross <hodgestar+github@gmail.com>
@Ericgig Ericgig merged commit 54936b3 into qutip:master Jul 6, 2023
12 checks passed
@Ericgig Ericgig deleted the feature.data.dispatch branch July 6, 2023 15:13
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.

None yet

3 participants