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

Support for NumPy-style data types #18

Merged
merged 19 commits into from
May 31, 2021
Merged

Support for NumPy-style data types #18

merged 19 commits into from
May 31, 2021

Conversation

Mandrenkov
Copy link
Collaborator

Context:
Python bindings for templated C++ classes require a unique class name for each template specialization. This introduces some boilerplate code on the C++ side and increases the verbosity of code on the Python side.

Description of the Change:

  • The name parameter passed to Python binding generators is now derived with the help of a Type structure.
  • Python bindings of templated C++ classes now include a static dtype attribute.
  • Factory methods which accept a dtype parameter are now available in the jet Python package.
  • Class parametrizations in Python unit tests have been replaced with dtype parametrizations.

Benefits:

  • The C++ code used to generate the Python bindings is cleaner.
  • The classes generated from Python bindings can be instantiated using a convention that mirrors NumPy.

Possible Drawbacks:

  • The tensor template parameter of classes with Python bindings is restricted to instances of the Tensor class.
    • This may be problematic when it comes time to generate Python bindings for CUDA tensor specializations.

Related GitHub Issues:
None.

@Mandrenkov Mandrenkov added enhancement ✨ New feature or request code quality 🎓 Improvements to code quality labels May 27, 2021
@github-actions
Copy link

github-actions bot commented May 27, 2021

Test Report (C++) on Ubuntu

    1 files  ±0      1 suites  ±0   0s ⏱️ ±0s
239 tests ±0  239 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
519 runs  ±0  519 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit ea17dd5. ± Comparison against base commit ea17dd5.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented May 27, 2021

Test Report (C++) on MacOS

    1 files  ±0      1 suites  ±0   0s ⏱️ ±0s
239 tests ±0  239 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
519 runs  ±0  519 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit ea17dd5. ± Comparison against base commit ea17dd5.

♻️ This comment has been updated with latest results.

Copy link
Member

@mlxd mlxd 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. Just a quick q or 2.

python/setup.py Show resolved Hide resolved
Comment on lines +28 to +29
tn.add_tensor(B, ["B", "Identity", "Real"])
tn.add_tensor(C, ["C", "Vector", "Real"])
Copy link
Member

Choose a reason for hiding this comment

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

Looks good, though just a thought on mixing real and complex data types: given everything is a complex datatype on the backend, we could potentially speed-up BLAS ops for real * real, and real * complex contractions (and save memory too) by extending BLAS supports for the above types. Granted, I think this can be done later as needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

given everything is a complex datatype on the backend

Do you mean currently? Or will this always be the case?

we could potentially speed-up BLAS ops for real * real, and real * complex contractions (and save memory too) by extending BLAS supports for the above types.

I'm not sure about real * complex, but would adding bindings for cblas_dgemv, cblas_dgemm, and cblas_ddotu_sub be enough (so that you can instantiate a Tensor<double>)? Or are you talking about something else?

python/tests/jet/test_tensor_network_io.py Show resolved Hide resolved
@Mandrenkov Mandrenkov merged commit ea17dd5 into main May 31, 2021
@Mandrenkov Mandrenkov deleted the dtype-support branch May 31, 2021 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality 🎓 Improvements to code quality enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants