{"id":20669488,"url":"https://github.com/iitis/rl_for_vqsd_ansatz_optimization","last_synced_at":"2025-04-19T18:12:39.245Z","repository":{"id":174974929,"uuid":"638481597","full_name":"iitis/RL_for_VQSD_ansatz_optimization","owner":"iitis","description":"Utilization of Reinforcement Learning in Variational Quantum State Diagonalization.","archived":false,"fork":false,"pushed_at":"2024-07-12T18:50:57.000Z","size":88942,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T11:34:28.468Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iitis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-09T13:04:29.000Z","updated_at":"2024-09-09T12:30:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d495819-9861-4c30-9f15-edf41c9a8717","html_url":"https://github.com/iitis/RL_for_VQSD_ansatz_optimization","commit_stats":null,"previous_names":["iitis/rl_for_vqsd_ansatz_optimization"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iitis%2FRL_for_VQSD_ansatz_optimization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iitis%2FRL_for_VQSD_ansatz_optimization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iitis%2FRL_for_VQSD_ansatz_optimization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iitis%2FRL_for_VQSD_ansatz_optimization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iitis","download_url":"https://codeload.github.com/iitis/RL_for_VQSD_ansatz_optimization/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249760126,"owners_count":21321843,"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-11-16T20:14:31.857Z","updated_at":"2025-04-19T18:12:39.228Z","avatar_url":"https://github.com/iitis.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8042976.svg)](https://doi.org/10.5281/zenodo.8042976)\n\n# Code for \"Enhancing variational quantum state diagonalization using reinforcement learning techniques\"\n\n---\n\nThis is a repository for the code used to calculate the numerical results presented in the manuscript:\n\nAkash Kundu, Przemysław Bedełek, Mateusz Ostaszewski, Onur Danaci, Yash J. Patel, Vedran Dunjko, Jarosław A. Miszczak,\n*Enhancing variational quantum state diagonalization using reinforcement learning techniques*,\narXiv:[2306.11086](https://arxiv.org/abs/2306.11086) (2023).\n\n```\n@Misc{kundu2023enhancing,\n  author    = {Kundu, Akash and Bedełek, Przemysław and Ostaszewski, Mateusz and Danaci, Onur and Patel, Yash J. and Dunjko, Vedran and Miszczak, Jarosław A.},\n  title     = {Enhancing variational quantum state diagonalization using reinforcement learning techniques},\n  year      = {2023},\n  copyright = {Creative Commons Attribution 4.0 International},\n  doi       = {10.48550/ARXIV.2306.11086},\n  keywords  = {Quantum Physics (quant-ph), Artificial Intelligence (cs.AI), Machine Learning (cs.LG), FOS: Physical sciences, FOS: Physical sciences, FOS: Computer and information sciences, FOS: Computer and information sciences},\n  publisher = {arXiv},\n}\n```\n---\n\n## Software Installation\nThe code was used on Ubuntu GNU/Linux 22.04.\n\nFor this project, we use Anaconda which can be downloaded from https://www.anaconda.com/products/individual.\n\nTo install activate the environment please do the following:\n```\nconda env create -f rl-vqsd.yml\nconda activate rl-vqsd \n```\nAlternatively, you could run\n```\nconda create -n rl-vqsd python=3.8.5\nconda activate rl-vqsd\npip install qiskit==0.31.0 qiskit-aqua\npip install torch\n```\nAdditionally, for running Jupyter notebooks you should also install\n```\npip install jupyter\npip install mpl-axes-aligner\n```\nand Conda environment with all packages can be created using\n```\nconda env create -f rl-vqsd-full.yml\n```\n## How to generate quantum state to diagonalize?\nThe `utils.py` python script contains two important functions `random_state_gen(...)` and `ground_state_reduced_heisenberg_model(...)` corresponding to the generation of **(1)** An arbitrary quantum state sampled from the Haar measure. **(2)** The reduced ground state of the Heisenberg model. You just need to run\n```\npython utils.py --state state_type --max_dim maxdim --seed seedno\n```\n**To generate (1) :** `state_type` (`str`) is replaced by `mixed`, `maxdim` (`int`) can be any upper limit to the size of the quantum state to be produced, and `seedno` (`int`) specifies the seed for the quantum state.\n**Example** \n``` \npython utils.py --state mixed --max_dim 4 --seed 1\n```\n**To generate (2) :** `state_typ` (`str`) is replaced by `reduced-heisenberg`, `maxdim` (`int`) is either 3 or 4 and `seedno` (`int`) is a redundant variable.\n**Example** \n``` \npython utils.py --state reduced-heisenberg --max_dim 3 --seed 342425\n```\n---\n## How to run RL-VQSD?\nTo diagonalize a quantum state we can just run the `main.py` python script using the following line of code:\n```\npython main.py --seed seedagent --config config_file --experiment_name \"global_COBYLA/\"\n```\nIn the above, the `seedagent` (`int`) corresponds to the different initialization to the Neural Network (NN) and the `config_file` (`str`) is the configuration corresponding to the state that need to be diagonalized, the hyperparameters of the NN and the agent configuration and it looks like: `h_s_2_rank_4_1`  where `2` corresponds to the number of qubit of the state, `4` is the rank of the state and `1` is the seed used to generate the state.\n**Example:** \n```\npython main.py --seed 1 --config h_s_2_rank_4_1 --experiment_name \"global_COBYLA/\"\n```\nAll the possible configurations can be found in the folder `configuration_files`.\n**To run the reduced Heisenberg model:**\n```\npython main.py --seed 102 --config h_s_3_reduced_heisenberg --experiment_name \"global_COBYLA/\"\n```\n**Diagonalizing using random search:**\n```\npython main.py --seed 100 --config h_s_3_reduced_heisenberg --experiment_name \"random_search/\"\n```\n## How to reproduce the results?\nThe results of the above will be saved in the `results` folder.\n**The reproduce the 2-qubit eigenvalue convergence (Fig. 6a in article) :** You can run one of the jupyter notebooks titled `eigenvalue_analysis.ipynb` and run each cell. Similarly,\n**The reproduce the 3-qubit eigenvalue convergence (Fig. 9 in article) :** You can run one of the jupyter notebooks titled `eigenvalue_analysis_reduced_heisenberg.ipynb` and run each cell.\n**Constant structure RL-ansatz statistics (Fig. 8 in article) :** You just need to run the `constant_structure_VQSD.ipynb` to first load the RL-ansatz of your choice and then use this ansatz to diagonalize `N` arbitrary quantum states of same dimension. This is utilized to plot in the last couple of cells of the notebook.\n**The reproduce the 2-qubit eigenvalue error (Fig. 6b in article) :** You first need to produce the diagonalization results using Layered Hardware Efficient Ansatz (LHEA) which can be done using and by running the `LHEA_VQSD.ipynb` file. Then utilizing the LHEA results in `LHEA_plot_analysis.ipynb` we produce Figure 6b.\n**Comparison with random search (Fig. 12a, 12b and 13)** Both the plots for 2 and 3 qubits to compare the DDQN with random search can be generated just by running the `plot_analysis_random_search.ipynb` file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiitis%2Frl_for_vqsd_ansatz_optimization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiitis%2Frl_for_vqsd_ansatz_optimization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiitis%2Frl_for_vqsd_ansatz_optimization/lists"}