mit-han-lab / torchquantum

A PyTorch-based framework for Quantum Classical Simulation, Quantum Machine Learning, Quantum Neural Networks, Parameterized Quantum Circuits with support for easy deployments on real quantum computers.
https://torchquantum.org
MIT License
1.3k stars 197 forks source link

Develop the TorchQuantum Testing Suite #261

Closed GenericP3rson closed 3 months ago

GenericP3rson commented 4 months ago

Currently, TQ’s tests don’t quite have full coverage, and we need your helps to achieve near-full coverage! To take on this task, take a module which has limited or lacking tests (found in test/) and write a comprehensive testing set for it! Some places that still need tests include the encoders, the operators (with different params like inverse=True), and covering all of the measurements!

Another super helpful directions we would love help with is we want to automatically run ALL of our tests using GitHub actions, but we don’t yet have a method to authenticate through IBMQ via GitHub actions. If you can design a workflow that can run the test/plugin tests on GitHub actions, that would super helpful!

The task will be considered complete if you develop a rigorous testing suite for at least two different components (and one of those tqo can be adding IBMQ support on GH actions).

SaashaJoshi commented 4 months ago

Hey, For the GitHub Actions issue, did you try saving an IBM API Token as a GitHub secret? GitHub secrets can be called from within the GitHub Actions workflow to run the tests.

For example, the files in tests/plugin require an IBM backend and consequently require an IBM token to initiate the IBMProvider. You could do something like this in the GitHub Actions workflow,

- name: Unit Tests
- env:
    IBM_API_TOKEN: ${{ secrets.IBM_API_TOKEN }}
run: |
    python -m pytest tests

And, any file that defines the IBMProvider or QiskitRuntimeSevice such as this can be written as,

import os
token = os.getenv("IBM_API_TOKEN")

provider = QiskitRuntimeService(channel = "ibm_quantum", token=token, instance = "ibm-q-research/mass-inst-tech-1/main")

The workflow will replace IBM_API_TOKEN with the saved token.

Correct me if I am wrong in understanding the situation. If this makes sense, I am glad to open a PR to see how this works out.

Update: I worked the above on a toy model and I was able to authenticate and schedule a job on the IBM Quantum platform.

GenericP3rson commented 4 months ago

Hey, thanks for letting us know! Feel free to open a PR with those updates (I can add in the secret with GH secrets as you recommended) + some tests for an aspect of your choosing, and we can merge it in!

SaashaJoshi commented 4 months ago

Hey @GenericP3rson, just to confirm, does the testing suite require functional tests or unit tests?