{"id":15898739,"url":"https://github.com/dylanljones/exactdiag","last_synced_at":"2025-10-26T10:38:31.611Z","repository":{"id":37055771,"uuid":"488552641","full_name":"dylanljones/exactdiag","owner":"dylanljones","description":"Exact diagonalization of fermionic (many-body) systems","archived":false,"fork":false,"pushed_at":"2025-02-17T19:42:20.000Z","size":191,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T17:38:38.465Z","etag":null,"topics":["exact-diagonalization","greens-functions","lehmann-representation","physics"],"latest_commit_sha":null,"homepage":"","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/dylanljones.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-04T10:57:45.000Z","updated_at":"2022-11-16T09:18:10.000Z","dependencies_parsed_at":"2024-01-29T20:40:21.627Z","dependency_job_id":"5d768f3c-30e5-4f37-ab4f-1ea39aa27a6a","html_url":"https://github.com/dylanljones/exactdiag","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/dylanljones%2Fexactdiag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylanljones%2Fexactdiag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylanljones%2Fexactdiag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dylanljones%2Fexactdiag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dylanljones","download_url":"https://codeload.github.com/dylanljones/exactdiag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244660071,"owners_count":20489288,"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":["exact-diagonalization","greens-functions","lehmann-representation","physics"],"created_at":"2024-10-06T10:08:18.338Z","updated_at":"2025-10-26T10:38:31.542Z","avatar_url":"https://github.com/dylanljones.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Exact diagonalization\n\n[![Tests][tests-badge]][tests-url]\n[![License: MIT][license-badge]][license-url]\n[![Code style: black][black-badge]][black-url]\n\n\n|⚠️|  This project is still under heavy development and might contain bugs or have breaking API changes in the future. |\n|----|:------------------------------------------------------------------------------------------------------------------|\n\n\n## 🔧 Installation\n\nInstall via `pip` from github:\n```commandline\npip install git+https://github.com/dylanljones/exactdiag.git@VERSION\n```\n\nor download/clone the package, navigate to the root directory and install via\n````commandline\npip install .\n````\n\n## 🚀 Quick-Start\n\n\n### Basis\n\nA ``Basis`` object can be initalized with the number of sites in the (many-body) system:\n\n````python\nimport exactdiag as ed\n\nbasis = ed.Basis(num_sites=3)\n````\n\nThe corresponding states of a particle sector can be obtained by calling:\n````python\nsector = basis.get_sector(n_up=1, n_dn=1)\n````\nIf no filling for a spin-sector is passed all possible fillings are included.\nThe labels of all states in a sector can be created by the ``state_labels`` method:\n````python\n\u003e\u003e\u003e sector.state_labels()\n['..⇅', '.↓↑', '↓.↑', '.↑↓', '.⇅.', '↓↑.', '↑.↓', '↑↓.', '⇅..']\n````\nThe states of a sector can be iterated by the ``states``-property.\nEach state consists of an up- and down-``SpinState``:\n````python\nstate = list(sector.states)[0]\nup_state = state.up\ndn_state = state.dn\n````\nEach ``SpinState`` provides methods for optaining information about the state, for example:\n`````python\n\u003e\u003e\u003e up_state.binstr(width=3)\n001\n\u003e\u003e\u003e up_state.n\n1\n\u003e\u003e\u003e up_state.occupations()\n[1]\n\u003e\u003e\u003e up_state.occ(0)\n1\n\u003e\u003e\u003e up_state.occ(1)\n0\n\u003e\u003e\u003e up_state.occ(2)\n0\n`````\n\n\n### Operators\n\nThe ``operators``-module provides the base-class ``LinearOperator`` based on ``scipy.LinearOperator``.\nA simple sparse implementation of a Hamiltonian is also included.\n````python\nimport exactdiag as ed\n\nsize = 5\nrows = [0, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4]\ncols = [0, 1, 2, 3, 4, 1, 2, 3, 4, 0, 1, 2, 3]\ndata = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]\nindices = (rows, cols)\nhamop = ed.HamiltonOperator(size, data, indices)\n````\nConverting the operator to an array yields\n````python\n\u003e\u003e\u003e hamop.array()\n[[0 1 0 0 0]\n [1 0 1 0 0]\n [0 1 0 1 0]\n [0 0 1 0 1]\n [0 0 0 1 0]]\n````\n\nMany-Body Hamiltonian matrices can be constructed by projecting the\nelements onto a basis sector. First, the basis has to be initialized:\n````python\nimport exactdiag as ed\n\nbasis = ed.Basis(num_sites=2)\nsector = basis.get_sector()  # Full basis\n````\n\nThe Hubbard Hamilton-operator, for example, can then be constructed as follows:\n````python\n\ndef hubbard_hamiltonian_data(sector):\n    up_states = sector.up_states\n    dn_states = sector.dn_states\n    # Hubbard interaction\n    yield from ed.project_hubbard_inter(up_states, dn_states, u=[2.0, 2.0])\n    # Hopping between sites 0 and 1\n    yield from ed.project_hopping(up_states, dn_states, site1=0, site2=1, hop=1.0)\n\nrows, cols, data = list(), list(), list()\nfor i, j, val in hubbard_hamiltonian_data(sector):\n    rows.append(i)\n    cols.append(j)\n    data.append(val)\n\nhamop = ed.HamiltonOperator(sector.size, data, (rows, cols))\n````\n\n### Models\n\nSome methods require a model object to work. Users can define their own\nmodels or use one of the following included models:\n\n| Module     | Description                                         | Lattice support    |\n|:-----------|:----------------------------------------------------|:-------------------|\n| abc        | Model-Parameter container and abstract base classes | -                  |\n| anderson   | Anderson impurity models                            | :x:                |\n| hubbard    | Hubbard model                                       | :heavy_check_mark: |              |\n\n\nA custom model can be defined by inheriting from the abstract base classes.\nMany-body models, for example, have to implement the `_hamiltonian_data` method,\nwhich generates the rows, columns and values of the Hamilton operator for each\nbasis sector:\n\n````python\nimport exactdiag as ed\n\n\nclass CustomModel(ed.models.AbstractManyBodyModel):\n\n    def __init__(self, num_sites, eps=0.0, ...):\n        super().__init__(num_sites, eps=eps, ...)\n\n    def _hamiltonian_data(self, up_states, dn_states):\n        yield from ed.project_onsite_energy(up_states, dn_states, self.eps)\n        ...\n````\n\nThe Hamilton operator can then be acessed for the full basis or a specific sector\nin operator or matrix representation:\n````python\nmodel = ed.models.HubbardModel(num_sites=2, neighbors=[[0, 1]], inter=2)\n\n# Sector n↑=1, n↓=1\nhamop = model.hamilton_operator(n_up=1, n_dn=1)\n\n# Full basis\nsector = model.basis.get_sector()\nham = model.hamiltonian(sector=sector)\ned.matshow(ham, ticklabels=sector.state_labels(), values=True)\n````\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"examples/hubbard_ham.png\" width=400 alt=\"Sublime's custom image\"/\u003e\n\u003c/p\u003e\n\n### Green's function\n\nUsing a custom defined model or one of the included models the one-particle\n(many-body) Green's function can be computed, for example using the Lehmann sum:\n````python\nimport numpy as np\nimport exactdiag as ed\n\nmodel = ed.models.HubbardModel.chain(num_sites=7, inter=4.0, beta=10.0).hf()\n\nz = np.linspace(-8, +8, 1001) + 1e-1j\ngf = ed.gf_lehmann(model, z, i=3, sigma=ed.UP)[0]\n````\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"examples/hubbard_gf.png\" alt=\"Sublime's custom image\"/\u003e\n\u003c/p\u003e\n\n\n[tests-badge]: https://img.shields.io/github/actions/workflow/status/dylanljones/exactdiag/test.yml?branch=master\u0026label=test\u0026logo=github\u0026style=flat\n[license-badge]: https://img.shields.io/github/license/dylanljones/exactdiag?color=lightgrey\u0026style=flat-square\n[black-badge]: https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square\n\n[license-url]: https://github.com/dylanljones/exactdiag/blob/master/LICENSE\n[black-url]: https://github.com/psf/black\n[tests-url]: https://github.com/dylanljones/exactdiag/actions/workflows/test.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylanljones%2Fexactdiag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdylanljones%2Fexactdiag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdylanljones%2Fexactdiag/lists"}