{"id":23015186,"url":"https://github.com/ptsolvers/pt-ad","last_synced_at":"2025-07-19T11:11:41.229Z","repository":{"id":47302451,"uuid":"510815361","full_name":"PTsolvers/PT-AD","owner":"PTsolvers","description":"Pseudo-transient auto-diff playground","archived":false,"fork":false,"pushed_at":"2023-03-27T14:27:27.000Z","size":5630,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-19T10:08:25.596Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Julia","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/PTsolvers.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":"2022-07-05T16:32:31.000Z","updated_at":"2023-02-08T13:31:16.000Z","dependencies_parsed_at":"2023-01-28T21:00:55.870Z","dependency_job_id":null,"html_url":"https://github.com/PTsolvers/PT-AD","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PTsolvers/PT-AD","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PTsolvers%2FPT-AD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PTsolvers%2FPT-AD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PTsolvers%2FPT-AD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PTsolvers%2FPT-AD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PTsolvers","download_url":"https://codeload.github.com/PTsolvers/PT-AD/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PTsolvers%2FPT-AD/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262151861,"owners_count":23266929,"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-12-15T11:11:34.228Z","updated_at":"2025-06-26T22:35:52.195Z","avatar_url":"https://github.com/PTsolvers.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PT-AD\n\nThe aim of this repository is to combine solvers using the [Pseudo-Transient Method](https://doi.org/10.5194/gmd-15-5757-2022) with Automatic Differentiation (AD) tools, here [Enzyme.jl](https://enzyme.mit.edu/julia/), on GPUs in order to retrieve necessary objects to perform inversions or parameter optimisation. \n\n:bulb: See our [JuliaCon22 talk](https://youtu.be/K2VtJe9baO4) for details.\n\nAs proof of concept, we successfully used AD to:\n1. retrieve the residual of the Adjoint variable we can then use in the Pseudo-Transient solving procedure in order to solve for the Adjoint problem, and to;\n2. retrieve the gradient of the cost-function with respect to the parameter we are inverting/optimising for.\n\n\u003e :warning: _**Note:** currently, the master branch of Enzyme.jl is needed to successfully execute the presented scripts. Consider `] add Enzyme#master` within Julia's pkg manager._\n\n## Benchmarks\nThe benchmark codes are available in the [**scripts_ok**](/scripts_ok/) folder and execute on Nvidia GPUs if `cuda` is appended in their name, and on the CPU otherwise. The `adjoint_nonlin_diff_1D_v2.jl` script provides a direct comparison between the CPU and GPU implementation.\n\n### 1D power-law diffusion\nWe tested our workflow in a 1D configuration in which we try to invert for the power-law exponent of a nonlinear diffusion equation as described in [Reuber et al. 2020 - Appendix](https://doi.org/10.1016/j.jcp.2020.109797) and [Reuber 2021](https://doi.org/10.1007/s13137-021-00186-y). We used a gradient descent approach to minimise the misfit between observed (synthetic) and calculated quantity `H` to retrieve the optimal power-law exponent `n`:\n\n![Inverting for power-law exponent in 1D](/docs/npow_inverse1D.gif)\n\n\u003e code: [`adjoint_nonlin_diff_1D_v2.jl`](/scripts_ok/adjoint_nonlin_diff_1D_v2.jl), [`adjoint_nonlin_diff_1D_v2_cuda.jl`](/scripts_ok/adjoint_nonlin_diff_1D_v2_cuda.jl)\n\n### Shallow-Ice\nWe tested our approach to invert for the equilibrium line (ELA) or the \"mass-balance gradient\" in an ice-flow model as described by [Visnjevic et al. 2018](http://www.doi.org/10.1017/jog.2018.82), both in 1D and 2D. For testing purpose, we use a slightly more synthetic configuration:\n\n![Inverting forMB gradient in 2D](/docs/inverse_2D_sia.gif)\n\n\u003e code: [`adjoint_nonlin_diff_react_2D_cuda.jl`](/scripts_ok/adjoint_nonlin_diff_react_2D_cuda.jl)\n\n#### 1D inversion for ELA\nThe ELA inversion code is available only in 1D and was used to prototype the 2D SIA inversion.\n\n\u003e code: [`adjoint_nonlin_diff_react_1D_cuda_ELA.jl`](/scripts_ok/adjoint_nonlin_diff_react_1D_cuda_ELA.jl)\n\n## Note on performance\n\n### Effective memory throughput\nPerformance-wise, we compared the efficiency (measuring the effective memory throughput $T_\\mathrm{eff}$ in GB/s) of the forward and adjoint solver. In addition, we also report the time per iteration as function of numerical grid resolution for both solvers.\n\n![Effective memory throughput](/docs/Teff_timeit.png)\n\n### Time per iteration\nIn addition, we also \"naively\" compared the execution time per forward solve iteration in seconds when executing both on the GPU and on the CPU. There we see about 2 orders of magnitude speed-up.\n\n![CPU vs GPU timing](/docs/timeit_gpu_cpu.png)\n\n## References\nGiles, M. B., \u0026 Pierce, N. A. (2000). An Introduction to the Adjoint Approach to Design. Flow, Turbulence and Combustion, 65(3/4), 393–415. https://doi.org/10.1023/A:1011430410075\n\nReuber, G. S. (2021). Statistical and deterministic inverse methods in the geosciences: Introduction, review, and application to the nonlinear diffusion equation. GEM - International Journal on Geomathematics, 12(1), 19. https://doi.org/10.1007/s13137-021-00186-y\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptsolvers%2Fpt-ad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fptsolvers%2Fpt-ad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptsolvers%2Fpt-ad/lists"}