{"id":32441024,"url":"https://github.com/matteoacrossi/adapt_ic-povm","last_synced_at":"2025-10-26T01:53:57.734Z","repository":{"id":47217127,"uuid":"381615852","full_name":"matteoacrossi/adapt_ic-povm","owner":"matteoacrossi","description":"Learning to measure: adaptive informationally complete POVMs for near-term quantum algorithms","archived":false,"fork":false,"pushed_at":"2021-12-07T08:46:47.000Z","size":10388,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-09-18T08:58:37.583Z","etag":null,"topics":["python","quantum-computing","research-paper"],"latest_commit_sha":null,"homepage":"https://doi.org/10.1103/PRXQuantum.2.040342","language":"Jupyter Notebook","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/matteoacrossi.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}},"created_at":"2021-06-30T07:37:28.000Z","updated_at":"2024-01-10T07:32:28.000Z","dependencies_parsed_at":"2022-07-21T05:32:46.495Z","dependency_job_id":null,"html_url":"https://github.com/matteoacrossi/adapt_ic-povm","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/matteoacrossi/adapt_ic-povm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteoacrossi%2Fadapt_ic-povm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteoacrossi%2Fadapt_ic-povm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteoacrossi%2Fadapt_ic-povm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteoacrossi%2Fadapt_ic-povm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matteoacrossi","download_url":"https://codeload.github.com/matteoacrossi/adapt_ic-povm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matteoacrossi%2Fadapt_ic-povm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281047760,"owners_count":26435124,"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","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["python","quantum-computing","research-paper"],"created_at":"2025-10-26T01:52:10.234Z","updated_at":"2025-10-26T01:53:57.712Z","avatar_url":"https://github.com/matteoacrossi.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# adapt_ic-povm\nCode used to produce the results of the paper\nG. García-Pérez, M. A. C. Rossi, B. Sokolov, F. Tacchino, P. K. Barkoutsos, G. Mazzola, I. Tavernelli, S. Maniscalco, \"Learning to Measure: Adaptive Informationally Complete Generalized Measurements for Quantum Algorithms\", [PRX Quantum 2, 040342 (2021)](https://doi.org/10.1103/PRXQuantum.2.040342).\n\nThe code uses qiskit 0.23 for simulating a near term quantum device, generating qubit Hamiltonian for small molecules and running VQE.\n\n\u003e NOTE: The simulations are quite demanding, especially for large molecules. The data was generated using a HPC cluster, and is openly available on [Zenodo.org](https://doi.org/10.5281/zenodo.5759030).\n\n## Installation\nThis repository requires Python 3 (tested with Python 3.8.5). Since we need to patch the qiskit aqua module in order to add the JKMN mapping, we recommend creating a virtual environment.\n\nClone the repository and move to the folder\n\n```\ngit clone https://github.com/matteoacrossi/adapt_ic-povm.git\ncd adapt_ic-povm\n```\n\nInstall the prerequisites with\n\n```\npip install -r requirements.txt\n```\n\nApply the patch to add the JKMN mapping\n\n```\npypatch apply neven.patch qiskit\n```\n\n## Usage\n\n### Downloading the data\n\nThe data used to reproduce the results presented in the paper is available at [https://doi.org/10.5281/zenodo.5759030](https://doi.org/10.5281/zenodo.5759030). Download the\nfile `data.tar` and extract it in the repository folder:\n\n```\nwget https://zenodo.org/record/5759030/files/data.tar\ntar -xvf data.tar\n```\n\nA folder `data/` will be created.\n\n### Example Hamiltonians\n\nThe example Hamiltonians are generated with `python preprare_chemistry_hamiltonians.py`. It will take a considerable amount of time and a workstation or cluster is recommended.\nThe molecules are defined in the file `preprare_chemistry_hamiltonians.py`.\n\nThe file `data/hamiltonians.pickle` contains a list of example chemistry Hamiltonians for the H2, LiH and H2O molecules,\nwith different bases, symmetries and fermion-to-qubit mappings. For each Hamiltonian, the exact ground state and an approximated\nground state found with VQE (using qiskit 0.23.6 default settings) are stored in the file.\n\nEach entry in the file is a dictionary of the form:\n\n```python\n{'molecule': 'H2',\n 'basis': 'sto3g',\n 'two_qubit_reduction': False,\n 'z2symmetry_reduction': False,\n 'freeze_core': False,\n 'mapping': 'parity',\n 'operator': \u003cqiskit.aqua.operators.legacy.weighted_pauli_operator.WeightedPauliOperator at 0x2b3a9078b9a0\u003e,\n 'qubits': 4,\n 'num_paulis': 15,\n 'vqe_circuit': \u003cqiskit.circuit.library.n_local.real_amplitudes.RealAmplitudes at 0x2b3a8febd970\u003e,\n 'vqe_value': -1.842665192696192,\n 'exact_circuit': \u003cqiskit.circuit.quantumcircuit.QuantumCircuit at 0x2b3a8f0747f0\u003e,\n 'exact_value': -1.842686681905733,\n 'name': '4q H2 parity'}\n ```\n\nSimilarly, the file `data/hamiltonians_h_chain.pickle` contains a list of Hamiltonians for hydrogen chains of various length. The file can be generated with `python prepare_h_chain_hamiltonians.py`.\n\n\nThe list of hamiltonians is shown in [Hamiltonians_summary.ipynb](./Hamiltonians_summary.ipynb).\n\n\n\n### Simulations\n\nThe simulations can be executed with `run_simulation.py`. The file takes a number of arguments as input\n\n```\nusage: run_simulation.py [-h] [--file FILE] [--hamiltonian HAMILTONIAN] [--samples SAMPLES] [--shots SHOTS [SHOTS ...]] [--method METHOD] [--outfile OUTFILE] [--exact] [--counts]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --file FILE                   The file with the Hamiltonians (hamiltonians.pickle)\n  --hamiltonian HAMILTONIAN     The id of the Hamiltonian\n  --samples SAMPLES             How many samples to take\n  --shots SHOTS [SHOTS ...]     The shots to use for the measurement (multiple amounts of shots can be passed)\n  --method METHOD               One of the methods: SIC-POVM, Pauli, Grouped_Pauli, Grad-POVM, Google-POVM, Grad-Google-POVM\n  --outfile OUTFILE             File where to save the results\n  --exact                       Use the exact diagonalization state\n  --counts                      Store the measurement counts to file (for tomography)\n  ```\n\nThe output files are in the JSON lines format:\n\n```json\n{\"qubits\": 4, \"true\": -1.8426866160309918, \"estimate\": -1.8394723164727411, \"estimated_error\": 0.01613556904575243, \"error\": 0.0032142995582506995, \"circuits\": 15, \"shots_per_circuit\": 66, \"shots\": 990, \"time_qc\": 2.879150152206421, \"time_post\": 0.5117971897125244, \"method\": \"Pauli\", \"counts\": null, \"name\": \"4q H2 jordan_wigner\", \"commit\": \"d59fe99\", \"exact_ground_state\": false, \"id\": \"MzZya4nhC6fQdvZsob332H\", \"timestamp\": 1625040177.894622}\n{\"qubits\": 4, \"true\": -1.8426866160309918, \"estimate\": -1.8418662180482184, \"estimated_error\": 0.01523071106596722, \"error\": 0.0008203979827734464, \"circuits\": 15, \"shots_per_circuit\": 66, \"shots\": 990, \"time_qc\": 2.938889980316162, \"time_post\": 0.522057294845581, \"method\": \"Pauli\", \"counts\": null, \"name\": \"4q H2 jordan_wigner\", \"commit\": \"d59fe99\", \"exact_ground_state\": false, \"id\": \"Xd9n4GGivADMxi8fT6CuZJ\", \"timestamp\": 1625040177.956557}\n...\n```\n\nand can be easily processed with Pandas.\n\nA convenience script `process_raw_data.py` joins multiple files, adds Hamiltonian information and saves the final dataset to a binary `.feather` file. For example:\n\n```\npython process_raw_data.py 'raw_data/*.txt' --hamiltonians hamiltonians.pickle -o data/chemistry_data.feather\n```\n\n\n### Tomography\n\nFor producing the results related to k-RDM tomography, all the counts coming from the measurements need to be stored. This can be achieved with the `--counts` flag of `run_simulation.py`.\n\nThe data used for the paper is stored in the JSON Lines file `counts_data.txt`. The data can be processed using `python tomography_script.py`.\n\n### Figures\n\nThe notebook [Figures.ipynb](./Figures.ipynb) generates all the figures contained in the published paper from the data available at [https://doi.org/10.5281/zenodo.5759030](https://doi.org/10.5281/zenodo.5759030).\n\n## Citation\n\nG. García-Pérez, M. A. C. Rossi, B. Sokolov, F. Tacchino, P. K. Barkoutsos, G. Mazzola, I. Tavernelli, S. Maniscalco, \"Learning to Measure: Adaptive Informationally Complete Generalized Measurements for Quantum Algorithms\", [*PRX Quantum* **2**, 040342 (2021)](https://doi.org/10.1103/PRXQuantum.2.040342).\n\n```\n@misc{garciaperez2021learning,\n        title = {Learning to Measure: Adaptive Informationally Complete Generalized Measurements for Quantum Algorithms},\n  author = {Garc\\'{\\i}a-P\\'erez, Guillermo and Rossi, Matteo A.C. and Sokolov, Boris and Tacchino, Francesco and Barkoutsos, Panagiotis Kl. and Mazzola, Guglielmo and Tavernelli, Ivano and Maniscalco, Sabrina},\n  journal = {PRX Quantum},\n  volume = {2},\n  issue = {4},\n  pages = {040342},\n  numpages = {17},\n  year = {2021},\n  month = {Nov},\n  publisher = {American Physical Society},\n  doi = {10.1103/PRXQuantum.2.040342},\n  url = {https://link.aps.org/doi/10.1103/PRXQuantum.2.040342}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatteoacrossi%2Fadapt_ic-povm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatteoacrossi%2Fadapt_ic-povm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatteoacrossi%2Fadapt_ic-povm/lists"}