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

Optimize dispatcher by using positional only arguments #2135

Merged
merged 7 commits into from Apr 11, 2023

Conversation

Ericgig
Copy link
Member

@Ericgig Ericgig commented Mar 27, 2023

Description
I optimized the dispatched by only supporting positional arguments for matrix to dispatch on:

The dispatcher was supporting any signature for dispatched functions.
Since each dispatchers is an instance of the Dispatcher class and cython does not support patching methods, it had to find the inputs matrix to convert from __call__(*args, **kwargs) and re-implemented the _bind method to do so.
But all our dispatched functions have the matrix as the first positional argument, by embracing this we get a nice speed up for small matrices.

Also when the specialization existed, it would not call it directly, but call a _constructed_specialisation that called ti. Adding another unneeded layer to each calls. This was changed so it would call the function directly.

For a 2x2 matrix:

Before After
data.add_dense 214ns 210ns
data.add (dense) 774ns 388ns
data.add[Dense, Dense] 541ns 182ns
data.add_csr 429ns 447ns
data.add (csr) 986ns 649ns
data.add[CSR. CSR] 744ns 401ns
numpy 473ns -

Sadly it will not improve the benchmarks that much since the Qobj operations overhead is quite large:

Before After
Qboj + Qobj (dense) 2430ns 2070ns
Qboj + Qobj (csr) 3070ns 2330ns

@coveralls
Copy link

coveralls commented Mar 27, 2023

Coverage Status

Coverage: 75.317% (-0.01%) from 75.328% when pulling d1160dc on Ericgig:enh_dispatcher into ab6a0d7 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 some small suggestions, but overall this is a great simplification.

qutip/core/data/dispatch.pyx Outdated Show resolved Hide resolved
qutip/core/data/dispatch.pyx Outdated Show resolved Hide resolved
qutip/core/data/dispatch.pyx Outdated Show resolved Hide resolved
qutip/core/data/dispatch.pyx Outdated Show resolved Hide resolved
qutip/core/data/dispatch.pyx Outdated Show resolved Hide resolved
qutip/core/data/dispatch.pyx Show resolved Hide resolved
qutip/core/data/dispatch.pyx Outdated Show resolved Hide resolved
qutip/core/data/dispatch.pyx Show resolved Hide resolved
Ericgig and others added 2 commits April 11, 2023 09:10
Co-authored-by: Simon Cross <hodgestar+github@gmail.com>
@Ericgig Ericgig merged commit df08d96 into qutip:master Apr 11, 2023
12 checks passed
@Ericgig Ericgig deleted the enh_dispatcher branch April 11, 2023 19:01
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