{"id":22225504,"url":"https://github.com/beliavsky/optimization-codes-by-chatgpt","last_synced_at":"2025-08-11T17:08:11.979Z","repository":{"id":167358314,"uuid":"642964559","full_name":"Beliavsky/Optimization-Codes-by-ChatGPT","owner":"Beliavsky","description":"numerical optimization subroutines in Fortran generated by ChatGPT-4","archived":false,"fork":false,"pushed_at":"2023-06-07T14:03:05.000Z","size":48,"stargazers_count":5,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-27T17:54:44.802Z","etag":null,"topics":["chatgpt","chatgpt4","conjugate-gradient","conjugate-gradient-descent","fortran","gradient-descent","hooke-jeeves","nelder-mead","numerical-optimization","simulated-annealing","unconstrained-optimization"],"latest_commit_sha":null,"homepage":"","language":"Fortran","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/Beliavsky.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}},"created_at":"2023-05-19T18:54:49.000Z","updated_at":"2023-10-09T00:44:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"fdfee372-0fe3-483e-a166-b9f10339454e","html_url":"https://github.com/Beliavsky/Optimization-Codes-by-ChatGPT","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"16149213b363b990a511ff681c5613bb87b47506"},"previous_names":["beliavsky/optimization-codes-by-chatgpt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Beliavsky/Optimization-Codes-by-ChatGPT","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FOptimization-Codes-by-ChatGPT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FOptimization-Codes-by-ChatGPT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FOptimization-Codes-by-ChatGPT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FOptimization-Codes-by-ChatGPT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Beliavsky","download_url":"https://codeload.github.com/Beliavsky/Optimization-Codes-by-ChatGPT/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FOptimization-Codes-by-ChatGPT/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269922906,"owners_count":24496999,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["chatgpt","chatgpt4","conjugate-gradient","conjugate-gradient-descent","fortran","gradient-descent","hooke-jeeves","nelder-mead","numerical-optimization","simulated-annealing","unconstrained-optimization"],"created_at":"2024-12-03T00:18:13.810Z","updated_at":"2025-08-11T17:08:11.955Z","avatar_url":"https://github.com/Beliavsky.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Optimization Codes by ChatGPT\nThe prompts given to ChatGPT-4 are shown in the codes. Sometimes cleanup was required. This is an experiment in code generation by ChatGPT -- the codes should not be relied upon.\n\nCompile with \n\n`gfortran optim_util.f90 hooke_jeeves.f90 simulated_annealing.f90 adam.f90 nelder_mead.f90 conjugate_gradient_min.f90 bfgs_min.f90 luus_jaakola.f90 gradient_descent.f90 xminimize.f90`\n\nWorks with gfortran 12.0.1 20220213 and ifort version 2021.6.0.\n\n## Some ChatGPT-4 quirks\n\n* When ChatGPT-4 generates code, it often forgets the `import` statement that is needed in the interface below.\n```Fortran\n    interface\n        function funk(x)\n            import :: dp\n            real(kind=dp), dimension(:), intent(in) :: x\n            real(kind=dp) :: funk\n        end function funk\n    end interface`\n```\n* It can produce code with `implicit none` and undeclared variables that does not compile. It tends to declare a variable `i` as integer even in a procedure that does not use the variable `i`.\n\n* When ChatGPT-4 translated some algorithms from the literature with `g*g'` or equivalently `g*transpose(g)`, it erroneously translated this to `g**2` in Fortran instead of `sum(g**2)`.\n\n* ChatGPT-4 sometimes forgets that the `random_number()` intrinsic is a subroutine, not a function, so that you cannot write \n```\nx = random_number()\n```\n* ChatGPT-4 sometimes declares as `intent(in)` an argument that needs to be `intent(in out)`, since its initial value in changed in the procedure.\n\n* ChatGPT-4 can incorrectly use a procedure argument in what is supposed to be a constant expression, as in\n\n```Fortran\nmodule sv_mod\nuse kind_mod, only: dp\nuse random_mod, only: random_normal\nimplicit none\ncontains\nsubroutine ret(n, kappa, theta, eta, y, x)\ninteger      , intent(in)    :: n\nreal(kind=dp), intent(in)    :: kappa, theta, eta\nreal(kind=dp), intent(out)   :: y(n), x(n)\n! for line below, gfortran says 'Error: Parameter 'n' at (1) has not been declared or is a variable, which does not reduce to a constant expression'\nreal(kind=dp)                :: dt = 1.0_dp / n \ninteger                      :: i\nreal(kind=dp)                :: dW, dV\ny(1) = theta\ndo i=2,n\n   dW = sqrt(dt) * random_normal()\n   dV = sqrt(dt) * random_normal()\n   y(i) = y(i-1) + kappa * (theta - y(i-1)) * dt + eta * sqrt(max(0.0_dp, y(i-1))) * dV\n   x(i) = exp(y(i-1)) * dW\nend do\nend subroutine ret\nend module sv_mod\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeliavsky%2Foptimization-codes-by-chatgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeliavsky%2Foptimization-codes-by-chatgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeliavsky%2Foptimization-codes-by-chatgpt/lists"}