The goal here is to create tests for the recently added custom diagonalization functionality, which allows users to determine what libraries are used for Hamiltonian diagonalization of the systems they define.
The current test suite is located here. Assuming pytest is installed (if not, can run pip install pytest), to run tests defined in a specific file, one can simply execute (from a directory above):
pytest -v --pyargs ./tests/test_noise.py
which, here will run tests outlined in test_noise.py.
One approach to implement this feature, would thus, be the following:
-
Create a file scqubits/tests/diag_tests.py and add relevant imports (to see what's needed one can look at the other files in the tests folder).
-
Look at an example notebook that shows how the custom diagonalization functionality can be used.
-
Pick a few examples from the notebook shown in (2), and/or dream up a few of your own, and create the corresponding test functions (see other files in tests folder for examples of what these should look like). So for example inside a given test function, one might create a qubit object, while passing in a particular diagonalization method, e.g., evals_method='evals_scipy_sparse', and then perform the diagonalization. Ideally it should also include a comparison to a default case, where a custom method has not been chosen.
-
Use pytest to be sure that the everything is working correctly.
One important thing that should be handled properly is the fact that some of the custom diaognalization methods depend on the existence of specific libraries/packages on the user's system (e.g. primme, cupy, jax). The tests should then only tests methods that rely on this optinal packages if they are present on the user's system - if they are not installed, a simple warning should be printed along the lines of e.g., "Package primme not installed; skipping test".
The goal here is to create tests for the recently added custom diagonalization functionality, which allows users to determine what libraries are used for Hamiltonian diagonalization of the systems they define.
The current test suite is located here. Assuming
pytestis installed (if not, can runpip install pytest), to run tests defined in a specific file, one can simply execute (from a directory above):which, here will run tests outlined in
test_noise.py.One approach to implement this feature, would thus, be the following:
Create a file
scqubits/tests/diag_tests.pyand add relevant imports (to see what's needed one can look at the other files in thetestsfolder).Look at an example notebook that shows how the custom diagonalization functionality can be used.
Pick a few examples from the notebook shown in (2), and/or dream up a few of your own, and create the corresponding test functions (see other files in
testsfolder for examples of what these should look like). So for example inside a given test function, one might create a qubit object, while passing in a particular diagonalization method, e.g.,evals_method='evals_scipy_sparse', and then perform the diagonalization. Ideally it should also include a comparison to a default case, where a custom method has not been chosen.Use
pytestto be sure that the everything is working correctly.One important thing that should be handled properly is the fact that some of the custom diaognalization methods depend on the existence of specific libraries/packages on the user's system (e.g.
primme,cupy,jax). The tests should then only tests methods that rely on this optinal packages if they are present on the user's system - if they are not installed, a simple warning should be printed along the lines of e.g., "Packageprimmenot installed; skipping test".