{"id":13870035,"url":"https://github.com/li012589/NeuralRG","last_synced_at":"2025-07-15T20:31:03.706Z","repository":{"id":83559271,"uuid":"123075623","full_name":"li012589/NeuralRG","owner":"li012589","description":"Pytorch source code for arXiv paper Neural Network Renormalization Group, a generative model using variational renormalization group and normalizing flow.","archived":false,"fork":false,"pushed_at":"2019-10-02T04:51:33.000Z","size":383252,"stargazers_count":79,"open_issues_count":0,"forks_count":21,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-08-06T21:22:57.609Z","etag":null,"topics":["ising-model","normalizing-flow","pytorch","renormalization-group"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/li012589.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,"roadmap":null,"authors":null}},"created_at":"2018-02-27T05:05:37.000Z","updated_at":"2024-07-13T10:22:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"ecde9b88-bbd9-48aa-8076-f07ae107da65","html_url":"https://github.com/li012589/NeuralRG","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/li012589%2FNeuralRG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/li012589%2FNeuralRG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/li012589%2FNeuralRG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/li012589%2FNeuralRG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/li012589","download_url":"https://codeload.github.com/li012589/NeuralRG/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226068153,"owners_count":17568704,"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":["ising-model","normalizing-flow","pytorch","renormalization-group"],"created_at":"2024-08-05T20:01:26.134Z","updated_at":"2024-11-23T16:31:00.097Z","avatar_url":"https://github.com/li012589.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\n\n# NeuralRG \n\nPytorch implement of arXiv paper: Shuo-Hui Li and Lei Wang, *Neural Network Renormalization Group* [arXiv:1802.02840](https://arxiv.org/abs/1802.02840).\n\n**NeuralRG** is a deep generative model using variational renormalization group approach, it's also a kind of [normalizing flow](https://blog.evjang.com/2018/01/nf1.html), it is composed by layers of bijectors (In our implementation, we use [realNVP](https://arxiv.org/abs/1605.08803)). After training, it can generate statistically independent physical configurations with tractable likelihood via directly sampling.\n\n## How does NeuralRG work\n\nIn NeuralRG Network(a), we use realNVP (b) networks as building blocks, realNVP is a kind of bijectors(a normalizing flow), they can transform one distribution into other distribution and revert this process. For multi-in-multi-out blocks, we call they disentanglers(gray blocks in (a)), and for multi-in-single-out blocks, we can they decimators(white blocks in (a)). And stacking multiple layers of these blocks into a hierarchical structure forms NeuralRG network, so NeuralRG is also a bijector. In inference process, each layer tries to \"separate\" entangled variables into independent variables, and at layers composed of decimators, we only keep one of these independent variables, this is renormalization group.\n\n![NeuralRG Network](etc/Nflow.png)\n\nThe structure we used to construct realNVP networks into NeuralRG network is inspired by multi-scale entanglement renormalization ansatz (MERA), as shown in (a). Also, the process of variable going through our network can be viewed as a renormalization process.\n\nThe resulted effect of a trained NeuralRG network can be visualized using gradients plot (a) and MI plot of variables of the same layer (b)(c). The latent variables of NeuralRG appears to be a nonlinear and adaptive generalization of wavelet basis.\n\n![gradientAndMi](etc/gradAndMi.png)\n\n## How to Run \n\n### Train\n\nUse `main.py` to train model. Options available are:\n\n* `folder` specifies saving path. At that path a `parameters.hdf5` will be created to keep training parameters, a `pic` folder will be created to keep plots, a `records` folder will be created to keep saved HMC records, and a `savings` folder to save models in.\n* `name` specifies model's name. If not specified, a name will be created according to training parameters.\n* `epochs`, `batch`, `lr`, `savePeriod` are the number of training epochs, batch size, learning rate, the number of epochs before saving.\n* `cuda` indicates on which GPU card should the model be trained, the default value is -1, which means running on CPU.\n* `double` indicates if use double float.\n* `load` indicates if load a pre-trained model. If true, will try to find a pre-trained model at where `folder` suggests. Note that if true all other parameters will be overwritten with what saved in `folder`'s `parameters.hdf5`.\n* `nmlp`, `nhidden` are used to construct MLP networks inside of realNVP networks. `nmlp` is the number of layers in MLP networks and `nhidden` is the number of hidden neurons in each layer.\n* `nlayers` is used to construct realNVP networks, it suggests how many layers in each realNVP networks.\n* `nrepeat` is used to construct MERA network, it suggests how many layers of bijectors inside of each layer of MERA network.\n* `L`, `d`, `T` are used to construct the Ising model to learn, `L` is the size of configuration, `d` is the dimension, and `T` is the temperature.\n* `alpha` ,`symmetry` are options about symmetried , symmetrized will be used if use `-symmetry` option. If `-symmetry` option is not added, `-alpha` can add a regulation term to loss to try to inflate symmetry.\n* `skipHMC` is used to skip HMC process during training save memory.\n\nFor example, to train the Ising model mentioned in our paper:\n\n```bash\npython ./main.py -epochs 5000 -folder ./opt/16Ising -batch 512 -nlayers 10 -nmlp 3 -nhidden 10 -L 16 -nrepeat 1 -savePeriod 100 -symmetry\n```\n\n### Plot\n\nUse `plot.py` to plot the loss curve and HMC results. Options available are:\n\n* `folder` specifies saving path. `plot.py` will use the data saved in that path to plot. And if `save` is true, the plot will be saved in `folder`'s `pic` folder.\n* `per` specifies how many seconds between each refresh.\n* `show`, `save` specifies if will show/save the plot.\n* `exact` specifies the exact result of HMC.\n\nFor example, to plot along with the training process mentioned above:\n\n```bash\npython ./plot.py -folder ./opt/16Ising -per 30 -exact 0.544445\n```\n\n### Train multiple models\n\nChange settings in `settings.py` to train diffierent models in different temperatures and different depths. Then `python core.py`  will read these settings and train these models. Figure of relative loss of different temperatures and depths can be plotted using `paperplot/plotCore.py`.\n\n## Citation\n\nIf you use this code for your research, please cite our [paper](https://arxiv.org/abs/1802.02840):\n\n```\n@article{neuralRG,\n  Author = {Shuo-Hui Li and Lei Wang},\n  Title = {Neural Network Renormalization Group},\n  Year = {2018},\n  Eprint = {arXiv:1802.02840},\n}\n```\n\n## Contact\n\nFor questions and suggestions, contact Shuo-Hui Li at [contact_lish@iphy.ac.cn](mailto:contact_lish@iphy.ac.cn).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fli012589%2FNeuralRG","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fli012589%2FNeuralRG","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fli012589%2FNeuralRG/lists"}