{"id":26486588,"url":"https://github.com/shermanlo77/poisson_icing","last_synced_at":"2026-05-21T07:34:22.890Z","repository":{"id":282903370,"uuid":"950012966","full_name":"shermanlo77/poisson_icing","owner":"shermanlo77","description":" Gibbs sampling on the Poisson-Ising model. The Poisson-Ising model is a 2D image of Poisson distributed random variables but has a dependency on their four neighbours. This causes the Poisson random variables to be similar (or dissimilar) to their neighbours.","archived":false,"fork":false,"pushed_at":"2025-06-24T15:06:44.000Z","size":131,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-24T16:24:31.959Z","etag":null,"topics":["cuda","cupy","gibbs-sampling","gpu","ising-model","mcmc","monte-carlo","poisson","poisson-ising"],"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/shermanlo77.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,"zenodo":null}},"created_at":"2025-03-17T13:49:46.000Z","updated_at":"2025-05-01T14:08:04.000Z","dependencies_parsed_at":"2025-03-17T15:51:05.545Z","dependency_job_id":"7a63b7bb-5fc5-4f8d-9a1e-96a933641c56","html_url":"https://github.com/shermanlo77/poisson_icing","commit_stats":null,"previous_names":["shermanlo77/poisson_icing"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/shermanlo77/poisson_icing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shermanlo77%2Fpoisson_icing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shermanlo77%2Fpoisson_icing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shermanlo77%2Fpoisson_icing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shermanlo77%2Fpoisson_icing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shermanlo77","download_url":"https://codeload.github.com/shermanlo77/poisson_icing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shermanlo77%2Fpoisson_icing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33292406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-21T02:57:32.698Z","status":"ssl_error","status_checked_at":"2026-05-21T02:57:31.990Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cuda","cupy","gibbs-sampling","gpu","ising-model","mcmc","monte-carlo","poisson","poisson-ising"],"created_at":"2025-03-20T06:19:53.930Z","updated_at":"2026-05-21T07:34:22.878Z","avatar_url":"https://github.com/shermanlo77.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Poisson Icing 🐟❄️\n\nPoisson Icing is a Python package which does Gibbs sampling on the Poisson-Ising\nmodel. The Poisson-Ising model is a 2D image of Poisson distributed random\nvariables but has a dependency on their four neighbours. This causes the Poisson\nrandom variables to be similar (or dissimilar) to their neighbours.\n\nThis package is designed to run on the GPU (using CUDA and CuPy) but also has a\nslower CPU version.\n\n## How to Install\n\nRequires:\n\n* `nvidia-cuda-toolkit`\n* `build-essential`\n\nGit clone the repository or download from releases.\n\nInside the directory, compile the CUDA code into a `.ptx` file by calling `make`\nand providing compute capability. For example, for an NVIDIA A100 GPU\n\n```bash\nmake NVCC_ARCH=sm_80\n```\n\nwhere `sm_80` is the compute capability. **Please see the [CUDA GPU compilation\ndocumentation](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#gpu-feature-list)\nto find the compute capability for your GPU.** For example:\n\n* An *Nvidia Tesla V100* has a Volta architecture with code `sm_70`.\n* An *Nvidia GeForce GTX 1660* has a Turing architecture with code `sm_75`.\n* An *Nvidia A100* has an Ampere architecture with code `sm_80`.\n* An *Nvidia H100* has an Ampere architecture with code `sm_90`.\n\nInstall the Python package *inside a [virtual\nenvironment](https://docs.python.org/3/library/venv.html)*. This is done by\nactivating a virtual environment and running `pip install`s. For CUDA 11, they\nare\n\n```bash\npip install .\npip install .[cuda12x]\n```\n\nIf you use CUDA 11, replace the last line with `pip install .[cuda11x]` instead.\n\n### How to Install - CPU Only\n\nIf you only require the CPU implementation, the above instructions can be\nsimplified to just\n\n```bash\npip install .\n```\n\n### Troubleshooting\n\nIf you find the above installation instructions do not work, please see below.\n\n#### Compute Capability\n\nWhen compiling the CUDA code into a `.ptx`, the compute capability must be\nprovided. **Please see the [CUDA GPU compilation\ndocumentation](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#gpu-feature-list)\nto find the compute capability for your GPU.**\n\nIt might help to delete `src/poissonicing.ptx` if you wish to recompile it.\n\nIf you do not wish to use the `Makefile`, the following command may be used\ninstead\n\n```bash\nnvcc -ptx src/poissonicing.cu -o src/poissonicing.ptx \\\\\n  -arch=$(NVCC_ARCH) -L$(CUDA_HOME)/lib64 -lcudart\n```\n\nwhere `$(NVCC_ARCH)` is the compute capability, eg `sm_80`.\n\n#### CuPy Version\n\nThe version of CuPy must be compatible with your CUDA version. See the [CuPy\ninstallation guide](https://docs.cupy.dev/en/stable/install.html) to see the\navailable versions of CuPy.\n\nEnsure you use, correctly, either `pip install .[cuda11x]` or `pip install\n.[cuda12x]` in the instructions above. You may also, instead, install CuPy\nyourself.\n\n#### Apptainer Definition File\n\nApptainer definition files `poisson_icing.def`, `poisson_icing_cuda11.def`\nand `poisson_icing_cpu_only.def` are provided should you wish to build this\nlibrary in a container or use it to further troubleshooting.\n\n## Examples\n\n### GPU\n\n![1000x1000 image containing a sample from Poisson-Ising model](gpu-example.webp)\n\nTo define the model, the following were provided:\n\n* The Poisson rate for each pixel in the image `rate_param`\n* The interation term which is constant `interaction`\n\nTo request how many samples to take, the following were provided:\n\n* The number of saved samples `n_sample`\n* The thinning parameter `n_thin`\n\nTo initalise the sampling, the following were provided:\n\n* The initial image to start sampling from `initial_image`. This contains random\n  Poisson samples.\n* A `cupy` random number generator\n\nLastly, the block dimension for the GPU is needed. This is a tuning parameter\nwhich affects the performance of the code. Block dimensions of 32\u0026times;2,\n64\u0026times;1, 8\u0026times;8 are good starting points.\n\n```python\nimport cupy\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom numpy import random\n\nimport poisson_icing.gpu\n\n\ndef main():\n    width = 1000\n    height = 1000\n    rng = random.default_rng(267388082994302295440407913531899274874)\n    rng_gpu = cupy.random.default_rng(65364652167924712153197736465669859297)\n\n    rate_param = np.ones((height, width))\n    interaction = 0.8\n    n_sample = 1\n    n_thin = 100\n\n    block_dim = (32, 2)\n\n    initial_image = rng.poisson(rate_param)\n\n    image_array = poisson_icing.gpu.sample(\n        rate_param,\n        interaction,\n        n_sample,\n        n_thin,\n        initial_image,\n        rng_gpu,\n        block_dim,\n    )\n\n    plt.figure()\n    plt.imshow(image_array[0], vmax=2)\n    plt.colorbar()\n    plt.show()\n    plt.close()\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n### CPU\n\n![200x200 image containing a sample from Poisson-Ising model](cpu-example.webp)\n\nTo define the model, the following were provided:\n\n* The Poisson rate for each pixel in the image `rate_param`\n* The interation term which is constant `interaction`\n\nTo request how many samples to take, the following were provided:\n\n* The number of saved samples `n_sample`\n* The thinning parameter `n_thin`\n\nTo initalise the sampling, the following were provided:\n\n* The initial image to start sampling from `initial_image`. This contains random\n  Poisson samples.\n* A `numpy` random number generator\n\n```python\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom numpy import random\n\nimport poisson_icing.cpu\n\n\ndef main():\n    width = 200\n    height = 200\n    rng = random.default_rng(267388082994302295440407913531899274874)\n\n    rate_param = np.ones((height, width))\n    interaction = 0.8\n    n_sample = 1\n    n_thin = 100\n\n    initial_image = rng.poisson(rate_param)\n\n    image_array = poisson_icing.cpu.sample(\n        rate_param, interaction, n_sample, n_thin, initial_image, rng\n    )\n\n    plt.figure()\n    plt.imshow(image_array[0])\n    plt.colorbar()\n    plt.show()\n    plt.close()\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n## Reproducing Results\n\nThis section is on reproducing results from the accompanying blog post.\n\n### Running the Experiment\n\nThis experiment does a benchmark using various grid configurations to\ninvestigate how different grid configurations affected performance.\n\nRequires additional packages, install them in a virtual environment with\n\n```bash\npip install .[test]\n```\n\nRun the experiment with\n\n```bash\npytest tests/benchmark.py\n```\n\nThis was repeated for three different GPUs, V100, A100 and H100.\n\n### Plotting\n\nRequires additional packages, install them in a virtual environment with\n\n```bash\npip install .[script]\n```\n\nSave the screen output from the experiment in the previous section to a file.\nExamples are provided called `script/volta*`, `script/ampere*` and\n`script/hopper*`.\n\nPlot graphs and show tables from the provided results with\n\n```bash\npython script/plot.py V100,A100,H100 script/volta* script/ampere* script/hopper*\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshermanlo77%2Fpoisson_icing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshermanlo77%2Fpoisson_icing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshermanlo77%2Fpoisson_icing/lists"}