{"id":22882592,"url":"https://github.com/cqcl/peptide-binding-classification-on-quantum-computers","last_synced_at":"2025-06-16T06:31:58.837Z","repository":{"id":209305348,"uuid":"723708388","full_name":"CQCL/peptide-binding-classification-on-quantum-computers","owner":"CQCL","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-26T14:35:38.000Z","size":330,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-08T03:06:52.238Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CQCL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-26T14:28:38.000Z","updated_at":"2025-02-25T11:38:28.000Z","dependencies_parsed_at":"2023-11-26T15:38:31.728Z","dependency_job_id":null,"html_url":"https://github.com/CQCL/peptide-binding-classification-on-quantum-computers","commit_stats":null,"previous_names":["cqcl/peptide-binding-classification-on-quantum-computers"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CQCL/peptide-binding-classification-on-quantum-computers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fpeptide-binding-classification-on-quantum-computers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fpeptide-binding-classification-on-quantum-computers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fpeptide-binding-classification-on-quantum-computers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fpeptide-binding-classification-on-quantum-computers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CQCL","download_url":"https://codeload.github.com/CQCL/peptide-binding-classification-on-quantum-computers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CQCL%2Fpeptide-binding-classification-on-quantum-computers/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260114368,"owners_count":22960887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T18:18:30.398Z","updated_at":"2025-06-16T06:31:58.814Z","avatar_url":"https://github.com/CQCL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## Structure\n- `Additional Data/` contains the peptide data split for cross validation\n- `csvs/` contains the model configurations required to reproduce classical and quantum results in the paper; additional parameters can be added by examining the `arg_type_map` variable in `run.py`\n- `model/` contains the TorchQuantum and PyTorch quantum and classical models, as well as utility files\n- `utils/` contains other miscellaneous functions used in processing\n\n- `run.py` and `run_classical.py` run the specified model and save data using Tensorboard\n- `average_folds.py` averages test and validation F1 data from executed runs\n- `get_attributions.py` and `get_attributions_classical.py` compute the Captum IG/SVS attributions\n\n## Modifications to TorchQuantum\nA small number of modifications have to be made to TorchQuantum to support the recurrent methods used here. As of TQ 0.1.7, these are:\n1. Replace line 90 in the `GeneralEncoder` class in `encoding/encodings.py` with the following four lines:\n    ```python\n    50  class GeneralEncoder(Encoder, metaclass=ABCMeta):\n\n        ...\n\n    90      def forward(self, qdev: tq.QuantumDevice, x, reset=True):\n    91          self.q_device = qdev\n    92          if reset:\n    93             self.q_device.reset_states(x.shape[0])\n    ```\ni.e. add `reset` as a default parameter and add the `if` statement resetting the state.\n\n2. Create the `MeasureOne` class in `measurement/measurements.py`:\n    ```python\n    class MeasureOne(tq.QuantumModule):\n        \"\"\"Obtain the expectation value of all the qubits.\"\"\"\n\n        def __init__(self, obs, v_c_reg_mapping=None):\n            super().__init__()\n            self.obs = obs\n            self.v_c_reg_mapping = v_c_reg_mapping\n\n        def forward(self, qdev: tq.QuantumDevice):\n            x = expval(qdev, [0], [self.obs()])\n\n            if self.v_c_reg_mapping is not None:\n                c2v_mapping = self.v_c_reg_mapping[\"c2v\"]\n                \"\"\"\n                the measurement is not normal order, need permutation\n                \"\"\"\n                perm = []\n                for k in range(x.shape[-1]):\n                    if k in c2v_mapping.keys():\n                        perm.append(c2v_mapping[k])\n                x = x[:, perm]\n\n            if self.noise_model_tq is not None and self.noise_model_tq.is_add_noise:\n                return self.noise_model_tq.apply_readout_error(x)\n            else:\n                return x\n\n        def set_v_c_reg_mapping(self, mapping):\n            self.v_c_reg_mapping = mapping\n    ```\nThis is identical to the pre-existing `MeasureAll` class except for the first line of the `forward` method, which here returns only a single observable. \n\nThen add `MeasureAll` to the `__all__` list defined on line 17 in the same file.\n\n## Usage\n1. Install the requirements in a `venv` by using `pip install -r requirements.txt`.\n2. Then install [TorchQuantum](https://github.com/mit-han-lab/torchquantum) in editable mode following the instructions on their homepage, and the modifications required above.\n3. Create a `.csv` file detailing the structure of the model you wish to run (`csvs/` contain some examples of this).\n4. Attributions can be calculated and the best F1 score over folds found by using `get_attributions.py` and `average_folds.py`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqcl%2Fpeptide-binding-classification-on-quantum-computers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcqcl%2Fpeptide-binding-classification-on-quantum-computers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqcl%2Fpeptide-binding-classification-on-quantum-computers/lists"}