diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 793d8d7..ebfebdb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: os: - windows-2022 - ubuntu-20.04 - - macos-11 + #- macos-11 arch: - x64 steps: @@ -32,7 +32,21 @@ jobs: julia --startup-file=no --project=. -e 'using Pkg; Pkg.instantiate()' julia --startup-file=no --project=compiler -e 'using Pkg; Pkg.instantiate()' julia --startup-file=no --project=compiler compiler/build.jl foo + # Upload as release asset + - name: build archives + run: | + zip -rq foo.zip foo --exclude '.*' --exclude '*/.*' --exclude 'appveyor.yml' + + - name: Upload files to a GitHub release + uses: svenstaro/upload-release-action@2.9.0 + with: + overwrite: true + tag: v0.1 + file: foo.zip + asset_name: madnlp-jl${{ matrix.version}}-${{ matrix.os }}-${{ matrix.arch }}.zip + prerelease: true + - uses: actions/upload-artifact@v4.3.1 with: - name: foo-${{ matrix.version}}-${{ matrix.os }}-${{ matrix.arch }} + name: madnlp-jl${{ matrix.version}}-${{ matrix.os }}-${{ matrix.arch }} path: foo diff --git a/Manifest.toml b/Manifest.toml index ed983fe..0199a30 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.10.3" manifest_format = "2.0" -project_hash = "8c5c79262baf543532624ed08426ecdc0b09688c" +project_hash = "2dcfd936fdff6ca235a0071d4470e333b9cac885" [[deps.AMD]] deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse_jll"] @@ -10,6 +10,30 @@ git-tree-sha1 = "45a1272e3f809d36431e57ab22703c6896b8908f" uuid = "14f7f29c-3bd6-536c-9a0b-7339e30b5a3e" version = "0.5.3" +[[deps.AbstractFFTs]] +deps = ["LinearAlgebra"] +git-tree-sha1 = "d92ad398961a3ed262d8bf04a1a2b8340f915fef" +uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c" +version = "1.5.0" + + [deps.AbstractFFTs.extensions] + AbstractFFTsChainRulesCoreExt = "ChainRulesCore" + AbstractFFTsTestExt = "Test" + + [deps.AbstractFFTs.weakdeps] + ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" + Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[deps.Adapt]] +deps = ["LinearAlgebra", "Requires"] +git-tree-sha1 = "6a55b747d1812e699320963ffde36f1ebdda4099" +uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" +version = "4.0.4" +weakdeps = ["StaticArrays"] + + [deps.Adapt.extensions] + AdaptStaticArraysExt = "StaticArrays" + [[deps.ArgTools]] uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" version = "1.1.1" @@ -17,6 +41,18 @@ version = "1.1.1" [[deps.Artifacts]] uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" +[[deps.Atomix]] +deps = ["UnsafeAtomics"] +git-tree-sha1 = "c06a868224ecba914baa6942988e2f2aade419be" +uuid = "a9b6321e-bd34-4604-b9c9-b65b8de01458" +version = "0.1.0" + +[[deps.BFloat16s]] +deps = ["LinearAlgebra", "Printf", "Random", "Test"] +git-tree-sha1 = "2c7cc21e8678eff479978a0a2ef5ce2f51b63dff" +uuid = "ab4f0b2a-ad5b-11e8-123f-65d77653426b" +version = "0.5.0" + [[deps.Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -32,17 +68,86 @@ git-tree-sha1 = "9e2a6b69137e6969bab0152632dcb3bc108c8bdd" uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" version = "1.0.8+1" +[[deps.CEnum]] +git-tree-sha1 = "389ad5c84de1ae7cf0e28e381131c98ea87d54fc" +uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82" +version = "0.5.0" + +[[deps.CUDA]] +deps = ["AbstractFFTs", "Adapt", "BFloat16s", "CEnum", "CUDA_Driver_jll", "CUDA_Runtime_Discovery", "CUDA_Runtime_jll", "Crayons", "DataFrames", "ExprTools", "GPUArrays", "GPUCompiler", "KernelAbstractions", "LLVM", "LLVMLoopInfo", "LazyArtifacts", "Libdl", "LinearAlgebra", "Logging", "NVTX", "Preferences", "PrettyTables", "Printf", "Random", "Random123", "RandomNumbers", "Reexport", "Requires", "SparseArrays", "StaticArrays", "Statistics"] +git-tree-sha1 = "fdd9dfb67dfefd548f51000cc400bb51003de247" +uuid = "052768ef-5323-5732-b1bb-66c8b64840ba" +version = "5.4.3" + + [deps.CUDA.extensions] + ChainRulesCoreExt = "ChainRulesCore" + EnzymeCoreExt = "EnzymeCore" + SpecialFunctionsExt = "SpecialFunctions" + + [deps.CUDA.weakdeps] + ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" + EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869" + SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" + +[[deps.CUDA_Driver_jll]] +deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"] +git-tree-sha1 = "97df9d4d6be8ac6270cb8fd3b8fc413690820cbd" +uuid = "4ee394cb-3365-5eb0-8335-949819d2adfc" +version = "0.9.1+1" + +[[deps.CUDA_Runtime_Discovery]] +deps = ["Libdl"] +git-tree-sha1 = "f3b237289a5a77c759b2dd5d4c2ff641d67c4030" +uuid = "1af6417a-86b4-443c-805f-a4643ffb695f" +version = "0.3.4" + +[[deps.CUDA_Runtime_jll]] +deps = ["Artifacts", "CUDA_Driver_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"] +git-tree-sha1 = "afea94249b821dc754a8ca6695d3daed851e1f5a" +uuid = "76a88914-d11a-5bdc-97e0-2f5a05c973a2" +version = "0.14.1+0" + +[[deps.CUDSS]] +deps = ["CEnum", "CUDA", "CUDSS_jll", "LinearAlgebra", "SparseArrays"] +git-tree-sha1 = "2ddfb9e1bab8cd6a049c4bd0bc0f5f7d91640e9c" +uuid = "45b445bb-4962-46a0-9369-b4df9d0f772e" +version = "0.1.6" + +[[deps.CUDSS_jll]] +deps = ["Artifacts", "CUDA_Runtime_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"] +git-tree-sha1 = "7d82cd3ec956d1dc36bdb1887561112fa1b10df7" +uuid = "4889d778-9329-5762-9fec-0578a5d30366" +version = "0.1.0+0" + +[[deps.CUSOLVERRF]] +deps = ["CUDA", "KLU", "LinearAlgebra", "SparseArrays"] +git-tree-sha1 = "3475fe1155f79768727a5a00c8d4d6a7a632f556" +uuid = "a8cc9031-bad2-4722-94f5-40deabb4245c" +version = "0.2.4" + [[deps.CodecBzip2]] deps = ["Bzip2_jll", "Libdl", "TranscodingStreams"] -git-tree-sha1 = "9b1ca1aa6ce3f71b3d1840c538a8210a043625eb" +git-tree-sha1 = "f8889d1770addf59d0a015c49a473fa2bdb9f809" uuid = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd" -version = "0.8.2" +version = "0.8.3" [[deps.CodecZlib]] deps = ["TranscodingStreams", "Zlib_jll"] -git-tree-sha1 = "59939d8a997469ee05c4b4944560a820f9ba0d73" +git-tree-sha1 = "b8fe8546d52ca154ac556809e10c75e6e7430ac8" uuid = "944b1d66-785c-5afd-91f1-9de20f533193" -version = "0.7.4" +version = "0.7.5" + +[[deps.ColorTypes]] +deps = ["FixedPointNumbers", "Random"] +git-tree-sha1 = "b10d0b65641d57b8b4d5e234446582de5047050d" +uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" +version = "0.11.5" + +[[deps.Colors]] +deps = ["ColorTypes", "FixedPointNumbers", "Reexport"] +git-tree-sha1 = "362a287c3aa50601b0bc359053d5c2468f0e7ce0" +uuid = "5ae59095-9a9b-59fe-a467-6f913c188581" +version = "0.12.11" [[deps.CommonSubexpressions]] deps = ["MacroTools", "Test"] @@ -65,12 +170,33 @@ deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" version = "1.1.1+0" +[[deps.Crayons]] +git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15" +uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" +version = "4.1.1" + +[[deps.DataAPI]] +git-tree-sha1 = "abe83f3a2f1b857aac70ef8b269080af17764bbe" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.16.0" + +[[deps.DataFrames]] +deps = ["Compat", "DataAPI", "DataStructures", "Future", "InlineStrings", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrecompileTools", "PrettyTables", "Printf", "REPL", "Random", "Reexport", "SentinelArrays", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] +git-tree-sha1 = "04c738083f29f86e62c8afc341f0967d8717bdb8" +uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +version = "1.6.1" + [[deps.DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] git-tree-sha1 = "1d0a14036acb104d9e89698bd408f63ab58cdc82" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" version = "0.18.20" +[[deps.DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + [[deps.Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -111,27 +237,75 @@ version = "0.3.2" [[deps.FileWatching]] uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" +[[deps.FixedPointNumbers]] +deps = ["Statistics"] +git-tree-sha1 = "05882d6995ae5c12bb5f36dd2ed3f61c98cbb172" +uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" +version = "0.8.5" + [[deps.ForwardDiff]] deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "LogExpFunctions", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions"] git-tree-sha1 = "cf0fe81336da9fb90944683b8c41984b08793dad" uuid = "f6369f11-7733-5829-9624-2563aa707210" version = "0.10.36" +weakdeps = ["StaticArrays"] [deps.ForwardDiff.extensions] ForwardDiffStaticArraysExt = "StaticArrays" - [deps.ForwardDiff.weakdeps] - StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" +[[deps.Future]] +deps = ["Random"] +uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" + +[[deps.GPUArrays]] +deps = ["Adapt", "GPUArraysCore", "LLVM", "LinearAlgebra", "Printf", "Random", "Reexport", "Serialization", "Statistics"] +git-tree-sha1 = "04661708f5301394a1f1be86a07a89e835900db6" +uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" +version = "10.2.3" + +[[deps.GPUArraysCore]] +deps = ["Adapt"] +git-tree-sha1 = "ec632f177c0d990e64d955ccc1b8c04c485a0950" +uuid = "46192b85-c4d5-4398-a991-12ede77f4527" +version = "0.1.6" + +[[deps.GPUCompiler]] +deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Preferences", "Scratch", "Serialization", "TOML", "TimerOutputs", "UUIDs"] +git-tree-sha1 = "ab29216184312f99ff957b32cd63c2fe9c928b91" +uuid = "61eb1bfa-7361-4325-ad38-22787b887f55" +version = "0.26.7" + +[[deps.InlineStrings]] +deps = ["Parsers"] +git-tree-sha1 = "86356004f30f8e737eff143d57d41bd580e437aa" +uuid = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48" +version = "1.4.1" + + [deps.InlineStrings.extensions] + ArrowTypesExt = "ArrowTypes" + + [deps.InlineStrings.weakdeps] + ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd" [[deps.InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[deps.InvertedIndices]] +git-tree-sha1 = "0dc7b50b8d436461be01300fd8cd45aa0274b038" +uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" +version = "1.3.0" + [[deps.IrrationalConstants]] git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2" uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" version = "0.2.2" +[[deps.IteratorInterfaceExtensions]] +git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" +uuid = "82899510-4779-5014-852e-03e436cf321d" +version = "1.0.0" + [[deps.JLLWrappers]] deps = ["Artifacts", "Preferences"] git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca" @@ -146,9 +320,9 @@ version = "0.21.4" [[deps.JuMP]] deps = ["LinearAlgebra", "MacroTools", "MathOptInterface", "MutableArithmetics", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays"] -git-tree-sha1 = "28f9313ba6603e0d2850fc3eae617e769c99bf83" +git-tree-sha1 = "7e10a0d8b534f2d8e9f712b33488584254624fb1" uuid = "4076af6c-e467-56ae-b986-b466b2749572" -version = "1.22.1" +version = "1.22.2" [deps.JuMP.extensions] JuMPDimensionalDataExt = "DimensionalData" @@ -156,12 +330,66 @@ version = "1.22.1" [deps.JuMP.weakdeps] DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0" +[[deps.JuliaNVTXCallbacks_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "af433a10f3942e882d3c671aacb203e006a5808f" +uuid = "9c1d0b0a-7046-5b2e-a33f-ea22f176ac7e" +version = "0.2.1+0" + +[[deps.KLU]] +deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse_jll"] +git-tree-sha1 = "884c2968c2e8e7e6bf5956af88cb46aa745c854b" +uuid = "ef3ab10e-7fda-4108-b977-705223b18434" +version = "0.4.1" + +[[deps.KernelAbstractions]] +deps = ["Adapt", "Atomix", "InteractiveUtils", "LinearAlgebra", "MacroTools", "PrecompileTools", "Requires", "SparseArrays", "StaticArrays", "UUIDs", "UnsafeAtomics", "UnsafeAtomicsLLVM"] +git-tree-sha1 = "d0448cebd5919e06ca5edc7a264631790de810ec" +uuid = "63c18a36-062a-441e-b654-da1e3ab1ce7c" +version = "0.9.22" + + [deps.KernelAbstractions.extensions] + EnzymeExt = "EnzymeCore" + + [deps.KernelAbstractions.weakdeps] + EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869" + [[deps.LDLFactorizations]] deps = ["AMD", "LinearAlgebra", "SparseArrays", "Test"] git-tree-sha1 = "70f582b446a1c3ad82cf87e62b878668beef9d13" uuid = "40e66cde-538c-5869-a4ad-c39174c6795b" version = "0.10.1" +[[deps.LLVM]] +deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Preferences", "Printf", "Requires", "Unicode"] +git-tree-sha1 = "020abd49586480c1be84f57da0017b5d3db73f7c" +uuid = "929cbde3-209d-540e-8aea-75f648917ca0" +version = "8.0.0" +weakdeps = ["BFloat16s"] + + [deps.LLVM.extensions] + BFloat16sExt = "BFloat16s" + +[[deps.LLVMExtra_jll]] +deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"] +git-tree-sha1 = "c2636c264861edc6d305e6b4d528f09566d24c5e" +uuid = "dad2f222-ce93-54a1-a47d-0025e8a3acab" +version = "0.0.30+0" + +[[deps.LLVMLoopInfo]] +git-tree-sha1 = "2e5c102cfc41f48ae4740c7eca7743cc7e7b75ea" +uuid = "8b046642-f1f6-4319-8d3c-209ddc03c586" +version = "1.0.0" + +[[deps.LaTeXStrings]] +git-tree-sha1 = "50901ebc375ed41dbf8058da26f9de442febbbec" +uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +version = "1.3.1" + +[[deps.LazyArtifacts]] +deps = ["Artifacts", "Pkg"] +uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3" + [[deps.LibCURL]] deps = ["LibCURL_jll", "MozillaCACerts_jll"] uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" @@ -211,9 +439,9 @@ version = "2.8.0" [[deps.LogExpFunctions]] deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"] -git-tree-sha1 = "18144f3e9cbe9b15b070288eef858f71b291ce37" +git-tree-sha1 = "a2d09619db4e765091ee5c6ffe8872849de0feea" uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" -version = "0.3.27" +version = "0.3.28" [deps.LogExpFunctions.extensions] LogExpFunctionsChainRulesCoreExt = "ChainRulesCore" @@ -228,6 +456,18 @@ version = "0.3.27" [[deps.Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" +[[deps.METIS_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "1fd0a97409e418b78c53fac671cf4622efdf0f21" +uuid = "d00139f3-1899-568f-a2f0-47f597d42d70" +version = "5.1.2+0" + +[[deps.MUMPS_seq_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "METIS_jll", "libblastrampoline_jll"] +git-tree-sha1 = "840b83c65b27e308095c139a457373850b2f5977" +uuid = "d7ed1dd3-d0ae-5e8e-bfb4-87a502085b8d" +version = "500.600.201+0" + [[deps.MacroTools]] deps = ["Markdown", "Random"] git-tree-sha1 = "2fa9ee3e63fd3a4f7a9a4f4744a52f4856de82df" @@ -244,21 +484,61 @@ weakdeps = ["MathOptInterface"] [deps.MadNLP.extensions] MadNLPMOI = "MathOptInterface" +[[deps.MadNLPGPU]] +deps = ["AMD", "CUDA", "CUDSS", "CUSOLVERRF", "KernelAbstractions", "LinearAlgebra", "MadNLP", "MadNLPTests", "Metis", "SparseArrays"] +git-tree-sha1 = "ddb1981f1c7a2ba78e480d4d210353133b013d98" +uuid = "d72a61cc-809d-412f-99be-fd81f4b8a598" +version = "0.7.2" + +[[deps.MadNLPMumps]] +deps = ["LinearAlgebra", "MUMPS_seq_jll", "MadNLP", "OpenBLAS32_jll"] +git-tree-sha1 = "a32f32cbd0ee36becf88368ce9d1e84e9bc6a0c1" +uuid = "3b83494e-c0a4-4895-918b-9157a7a085a1" +version = "0.4.1" + +[[deps.MadNLPTests]] +deps = ["JuMP", "LinearAlgebra", "MadNLP", "NLPModels", "NLPModelsJuMP", "Random", "SparseArrays", "Test"] +git-tree-sha1 = "06f46773a08a3b88779a76dd1eb08a5d829dc084" +uuid = "b52a2a03-04ab-4a5f-9698-6a2deff93217" +version = "0.5.1" + [[deps.Markdown]] deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" [[deps.MathOptInterface]] deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "DataStructures", "ForwardDiff", "JSON", "LinearAlgebra", "MutableArithmetics", "NaNMath", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays", "SpecialFunctions", "Test", "Unicode"] -git-tree-sha1 = "9cc5acd6b76174da7503d1de3a6f8cf639b6e5cb" +git-tree-sha1 = "91b08d27a27d83cf1e63e50837403e7f53a0fd74" uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" -version = "1.29.0" +version = "1.31.0" [[deps.MbedTLS_jll]] deps = ["Artifacts", "Libdl"] uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" version = "2.28.2+1" +[[deps.Metis]] +deps = ["CEnum", "LinearAlgebra", "METIS_jll", "SparseArrays"] +git-tree-sha1 = "5582d3b0d794280c9b818ba56ce2b35b108aca41" +uuid = "2679e427-3c69-5b7f-982b-ece356f1e94b" +version = "1.4.1" + + [deps.Metis.extensions] + MetisGraphs = "Graphs" + MetisLightGraphs = "LightGraphs" + MetisSimpleWeightedGraphs = ["SimpleWeightedGraphs", "Graphs"] + + [deps.Metis.weakdeps] + Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" + LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" + SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622" + +[[deps.Missings]] +deps = ["DataAPI"] +git-tree-sha1 = "ec4f7fbeab05d7747bdf98eb74d130a2a2ed298d" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "1.2.0" + [[deps.Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" @@ -268,9 +548,9 @@ version = "2023.1.10" [[deps.MutableArithmetics]] deps = ["LinearAlgebra", "SparseArrays", "Test"] -git-tree-sha1 = "a3589efe0005fc4718775d8641b2de9060d23f73" +git-tree-sha1 = "898c56fbf8bf71afb0c02146ef26f3a454e88873" uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0" -version = "1.4.4" +version = "1.4.5" [[deps.NLPModels]] deps = ["FastClosures", "LinearAlgebra", "LinearOperators", "Printf", "SparseArrays"] @@ -278,6 +558,24 @@ git-tree-sha1 = "51b458add76a938917772ee661ffb9d59b4c7e5d" uuid = "a4795742-8479-5a88-8948-cc11e1c8c1a6" version = "0.20.0" +[[deps.NLPModelsJuMP]] +deps = ["JuMP", "LinearAlgebra", "MathOptInterface", "NLPModels", "Printf", "SolverCore", "SparseArrays"] +git-tree-sha1 = "5186da6e38d5dbf2b4b4691e52197d65cca362a1" +uuid = "792afdf1-32c1-5681-94e0-d7bf7a5df49e" +version = "0.12.7" + +[[deps.NVTX]] +deps = ["Colors", "JuliaNVTXCallbacks_jll", "Libdl", "NVTX_jll"] +git-tree-sha1 = "53046f0483375e3ed78e49190f1154fa0a4083a1" +uuid = "5da4648a-3479-48b8-97b9-01cb529c0a1f" +version = "0.3.4" + +[[deps.NVTX_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "ce3269ed42816bf18d500c9f63418d4b0d9f5a3b" +uuid = "e98f9f5b-d649-5603-91fd-7774390e6439" +version = "3.1.0+2" + [[deps.NaNMath]] deps = ["OpenLibm_jll"] git-tree-sha1 = "0877504529a3e5c3343c6f8b4c0381e57e4387e4" @@ -288,6 +586,12 @@ version = "1.0.2" uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" version = "1.2.0" +[[deps.OpenBLAS32_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl"] +git-tree-sha1 = "6065c4cff8fee6c6770b277af45d5082baacdba1" +uuid = "656ef2d0-ae68-5445-9ca0-591084a874a2" +version = "0.3.24+0" + [[deps.OpenBLAS_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" @@ -320,6 +624,12 @@ deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", " uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" version = "1.10.0" +[[deps.PooledArrays]] +deps = ["DataAPI", "Future"] +git-tree-sha1 = "36d8b4b899628fb92c2749eb488d884a926614d3" +uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" +version = "1.4.3" + [[deps.PrecompileTools]] deps = ["Preferences"] git-tree-sha1 = "5aa36f7049a63a1528fe8f7c3f2113413ffd4e1f" @@ -332,6 +642,12 @@ git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6" uuid = "21216c6a-2e73-6563-6e65-726566657250" version = "1.4.3" +[[deps.PrettyTables]] +deps = ["Crayons", "LaTeXStrings", "Markdown", "PrecompileTools", "Printf", "Reexport", "StringManipulation", "Tables"] +git-tree-sha1 = "66b20dd35966a748321d3b2537c4584cf40387c7" +uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" +version = "2.3.2" + [[deps.Printf]] deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" @@ -348,6 +664,23 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" deps = ["SHA"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +[[deps.Random123]] +deps = ["Random", "RandomNumbers"] +git-tree-sha1 = "4743b43e5a9c4a2ede372de7061eed81795b12e7" +uuid = "74087812-796a-5b5d-8853-05524746bad3" +version = "1.7.0" + +[[deps.RandomNumbers]] +deps = ["Random", "Requires"] +git-tree-sha1 = "043da614cc7e95c703498a491e2c21f58a2b8111" +uuid = "e6cf234a-135c-5ec9-84dd-332b85af5143" +version = "1.5.3" + +[[deps.Reexport]] +git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" +uuid = "189a3867-3050-52da-a836-e630ba90ab69" +version = "1.2.2" + [[deps.Requires]] deps = ["UUIDs"] git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7" @@ -358,6 +691,18 @@ version = "1.3.0" uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" version = "0.7.0" +[[deps.Scratch]] +deps = ["Dates"] +git-tree-sha1 = "3bac05bc7e74a75fd9cba4295cde4045d9fe2386" +uuid = "6c6a2e73-6563-6170-7368-637461726353" +version = "1.2.1" + +[[deps.SentinelArrays]] +deps = ["Dates", "Random"] +git-tree-sha1 = "ff11acffdb082493657550959d4feb4b6149e73a" +uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c" +version = "1.4.5" + [[deps.Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" @@ -370,6 +715,12 @@ git-tree-sha1 = "03a1e0d2d39b9ebc9510f2452c0adfbe887b9cb2" uuid = "ff4d7338-4cf1-434d-91df-b86cb86fb843" version = "0.3.8" +[[deps.SortingAlgorithms]] +deps = ["DataStructures"] +git-tree-sha1 = "66e0a8e672a0bdfca2c3f5937efb8538b9ddc085" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "1.2.1" + [[deps.SparseArrays]] deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" @@ -387,16 +738,36 @@ version = "2.4.0" [deps.SpecialFunctions.weakdeps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +[[deps.StaticArrays]] +deps = ["LinearAlgebra", "PrecompileTools", "Random", "StaticArraysCore"] +git-tree-sha1 = "eeafab08ae20c62c44c8399ccb9354a04b80db50" +uuid = "90137ffa-7385-5640-81b9-e52037218182" +version = "1.9.7" + + [deps.StaticArrays.extensions] + StaticArraysChainRulesCoreExt = "ChainRulesCore" + StaticArraysStatisticsExt = "Statistics" + + [deps.StaticArrays.weakdeps] + ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" + Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + [[deps.StaticArraysCore]] -git-tree-sha1 = "36b3d696ce6366023a0ea192b4cd442268995a0d" +git-tree-sha1 = "192954ef1208c7019899fbf8049e717f92959682" uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" -version = "1.4.2" +version = "1.4.3" [[deps.Statistics]] deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" version = "1.10.0" +[[deps.StringManipulation]] +deps = ["PrecompileTools"] +git-tree-sha1 = "a04cabe79c5f01f4d723cc6704070ada0b9d46d5" +uuid = "892a3eda-7b42-436c-8928-eab12a02cf0e" +version = "0.3.4" + [[deps.SuiteSparse]] deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" @@ -411,6 +782,18 @@ deps = ["Dates"] uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" version = "1.0.3" +[[deps.TableTraits]] +deps = ["IteratorInterfaceExtensions"] +git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39" +uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +version = "1.0.1" + +[[deps.Tables]] +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "OrderedCollections", "TableTraits"] +git-tree-sha1 = "cb76cf677714c095e535e3501ac7954732aeea2d" +uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +version = "1.11.1" + [[deps.Tar]] deps = ["ArgTools", "SHA"] uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" @@ -427,9 +810,9 @@ uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" version = "0.5.24" [[deps.TranscodingStreams]] -git-tree-sha1 = "5d54d076465da49d6746c647022f3b3674e64156" +git-tree-sha1 = "60df3f8126263c0d6b357b9a1017bb94f53e3582" uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" -version = "0.10.8" +version = "0.11.0" weakdeps = ["Random", "Test"] [deps.TranscodingStreams.extensions] @@ -442,6 +825,22 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[deps.Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" +[[deps.UnsafeAtomics]] +git-tree-sha1 = "6331ac3440856ea1988316b46045303bef658278" +uuid = "013be700-e6cd-48c3-b4a1-df204f14c38f" +version = "0.2.1" + +[[deps.UnsafeAtomicsLLVM]] +deps = ["LLVM", "UnsafeAtomics"] +git-tree-sha1 = "bf2c553f25e954a9b38c9c0593a59bb13113f9e5" +uuid = "d80eeb9a-aca5-4d75-85e5-170c8b632249" +version = "0.1.5" + +[[deps.UnsafePointers]] +git-tree-sha1 = "c81331b3b2e60a982be57c046ec91f599ede674a" +uuid = "e17b2a0c-0bdf-430a-bd0c-3a23cae4ff39" +version = "1.0.0" + [[deps.Zlib_jll]] deps = ["Libdl"] uuid = "83775a58-1f1d-513f-b197-d71354ab007a" diff --git a/Project.toml b/Project.toml index e5b5a65..2224802 100644 --- a/Project.toml +++ b/Project.toml @@ -1,8 +1,13 @@ name = "MadNLP_C" uuid = "809fdad6-fa7d-470e-b0f3-59f70ed6c6e6" -authors = ["Joris Gillis "] +authors = ["Tommaso Sartor ", "Joris Gillis "] version = "0.1.0" [deps] -JuMP = "4076af6c-e467-56ae-b986-b466b2749572" +CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" MadNLP = "2621e9c9-9eb4-46b1-8089-e8c72242dfb6" +MadNLPGPU = "d72a61cc-809d-412f-99be-fd81f4b8a598" +MadNLPMumps = "3b83494e-c0a4-4895-918b-9157a7a085a1" +NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6" +UnsafePointers = "e17b2a0c-0bdf-430a-bd0c-3a23cae4ff39" diff --git a/compiler/additional_precompile.jl b/compiler/additional_precompile.jl index b819f6b..e69de29 100644 --- a/compiler/additional_precompile.jl +++ b/compiler/additional_precompile.jl @@ -1 +0,0 @@ -precompile(Tuple{typeof(MadNLP_C.madnlp_c), Float64, Float64, Float64, UInt64}) diff --git a/compiler/generate_precompile.jl b/compiler/generate_precompile.jl index 71109e7..74cea1c 100644 --- a/compiler/generate_precompile.jl +++ b/compiler/generate_precompile.jl @@ -1,8 +1,201 @@ using MadNLP_C +using Base +using Logging -MadNLP_C.madnlp_c( - convert(Cdouble,0.0), - convert(Cdouble,0.0), - convert(Cdouble,0.0), - convert(Csize_t,100) +logger = ConsoleLogger(stderr, Logging.Warn) +global_logger(logger) + + +const nvar::UInt64 = 2 +const ncon::UInt64 = 1 + +a::Float64 = 1.0 +b::Float64 = 100.0 + +const x0::Vector{Float64} = [1.0, 1.0] +const y0::Vector{Float64} = ones(ncon) + +Cx0::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble},x0) +Cy0::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble},y0) + +function _eval_f!(w::Vector{T}, f::Vector{T}) where T + f[1] = (a-w[1])^2 + b*(w[2]-w[1]^2)^2 +end + +function _eval_g!(w::Vector{T}, g::Vector{T}) where T + g[1] = w[1]^2 + w[2]^2 - 1 +end + +function _eval_jac_g!(w::Vector{T}, jac_g::Vector{T}) where T + jac_g[1] = 2*w[1] + jac_g[2] = 2*w[2] +end + +function _eval_grad_f!(w::Vector{T}, g::Vector{T}) where T + g[1] = -4*b*w[1]*(w[2]-w[1]^2)-2*(a-w[1]) + g[2] = b*2*(w[2]-w[1]^2) +end + +function _eval_h!(w::Vector{T},l::Vector{T}, h::Vector{T}) where T + h[1] = (+2 -4*b*w[2] +12*b*w[1]^2) + h[2] = (-4*b*w[1]) + h[3] = (2*b) +end + +function eval_f(Cw::Ptr{Cdouble},Cf::Ptr{Cdouble}, d::Ptr{Cvoid})::Cint + w::Vector{Float64} = unsafe_wrap(Array, Cw, nvar) + f::Vector{Float64} = unsafe_wrap(Array, Cf, 1) + _eval_f!(w,f) + return 0 +end + +function eval_g(w::Ptr{Cdouble},Ccons::Ptr{Cdouble}, d::Ptr{Cvoid})::Cint + w::Vector{Float64} = unsafe_wrap(Array, w, nvar) + cons::Vector{Float64} = unsafe_wrap(Array, Ccons, ncon) + _eval_g!(w,cons) + return 0 +end + +function eval_grad_f(Cw::Ptr{Cdouble},Cgrad::Ptr{Cdouble}, d::Ptr{Cvoid})::Cint + w::Vector{Float64} = unsafe_wrap(Array, Cw, nvar) + grad::Vector{Float64} = unsafe_wrap(Array, Cgrad, nnzo) + _eval_grad_f!(w,grad) + @debug "grad-callback" grad + # Cgrad::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, grad) + return 0 +end + +function eval_jac_g(w::Ptr{Cdouble}, Cjac_q::Ptr{Cdouble}, d::Ptr{Cvoid})::Cint + w::Vector{Float64} = unsafe_wrap(Array, w, nvar) + jac_g::Vector{Float64} = unsafe_wrap(Array, Cjac_q, nnzj) + _eval_jac_g!(w,jac_g) + return 0 +end + +function eval_h(obj_scale::Cdouble, Cw::Ptr{Cdouble}, Cl::Ptr{Cdouble}, Chess::Ptr{Cdouble}, d::Ptr{Cvoid})::Cint + w::Vector{Float64} = unsafe_wrap(Array, Cw, nvar) + l::Vector{Float64} = unsafe_wrap(Array, Cl, ncon) + hess::Vector{Float64} = unsafe_wrap(Array, Chess, nnzh) + _eval_h!(w,l,hess) + return 0 +end + +nnzo::Csize_t = 2 +nnzj::Csize_t = 2 +nnzh::Csize_t = 3 +nzj_i = Csize_t[1,1] +nzj_j = Csize_t[1,2] +nzh_i = Csize_t[1,1,2] +nzh_j = Csize_t[1,2,2] +lbx = Cdouble[-Inf, -Inf] +ubx = Cdouble[ Inf, Inf] +lbg = Cdouble[0.0] +ubg = Cdouble[0.0] + +Cnzj_i::Ptr{Csize_t} = Base.unsafe_convert(Ptr{Csize_t}, nzj_i) +Cnzj_j::Ptr{Csize_t} = Base.unsafe_convert(Ptr{Csize_t}, nzj_j) +Cnzh_i::Ptr{Csize_t} = Base.unsafe_convert(Ptr{Csize_t}, nzh_i) +Cnzh_j::Ptr{Csize_t} = Base.unsafe_convert(Ptr{Csize_t}, nzh_j) +Clbx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, lbx) +Cubx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, ubx) +Clbg::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, lbg) +Cubg::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, ubg) + +max_iters::Csize_t = 1000 +print_level::Csize_t = 3 +minimize::Bool = true +user_data::Ptr{Cvoid} = 0 + +sol = zeros(nvar) +Csol::Ptr{Cdouble} = pointer(sol) +obj = zeros(1) +Cobj::Ptr{Cdouble} = pointer(obj) +con = zeros(ncon) +Ccon::Ptr{Cdouble} = pointer(con) + +primal_feas = zeros(1) +Cprimal_feas::Ptr{Cdouble} = pointer(primal_feas) + +dual_feas = zeros(1) +Cdual_feas::Ptr{Cdouble} = pointer(dual_feas) + +mul = zeros(ncon) +Cmul::Ptr{Cdouble} = pointer(mul) + +mul_L = zeros(nvar) +mul_U = zeros(nvar) +Cmul_L::Ptr{Cdouble} = pointer(mul_L) +Cmul_U::Ptr{Cdouble} = pointer(mul_U) + +iter::Vector{Int} = [1,] +Citer::Ptr{Csize_t} = pointer(iter) + +# pre compile for different solvers + +lin_solver_names = Dict( + 0=>"mumps", + 1=>"ufpack", + 2=>"lapackCPUsolver", + 3=>"CSSDU", + 4=>"LapackGPUSolver", + 5=>"CuCholeskySolver", ) +cases::Vector{Pair{UInt64,Csize_t}} = [0=>3,1=>3,5=>3,3=>0] +for (lin_solver_id,print_level) in cases + + nlp_interface = MadnlpCInterface( + @cfunction(eval_f,Cint,(Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid})), + @cfunction(eval_g,Cint,(Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid})), + @cfunction(eval_grad_f,Cint,(Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid})), + @cfunction(eval_jac_g,Cint,(Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid})), + @cfunction(eval_h,Cint,(Cdouble, Ptr{Cdouble},Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid})), + nvar, + ncon, + Cnzj_i, + Cnzj_j, + Cnzh_i, + Cnzh_j, + nnzj, + nnzh, + nnzo, + user_data + ) + + s = madnlp_c_create(Base.unsafe_convert(Ptr{MadnlpCInterface}, pointer_from_objref(nlp_interface))) + + inp = MadnlpCNumericIn(Cx0,Cy0,Clbx,Cubx,Clbg,Cubg) + + @info "lbx" inp.lbx + out = MadnlpCNumericOut() + + println(out.sol) + + #madnlp_c_set_option_int(s, "lin_solver_id", lin_solver_id) + #madnlp_c_set_option_int(s, "max_iters", max_iters) + #madnlp_c_set_option_int(s, "print_level", print_level) + #madnlp_c_set_option_bool(s, "minimize", minimize) + + Cret = madnlp_c_solve(s, + Base.unsafe_convert(Ptr{MadnlpCNumericIn}, pointer_from_objref(inp)), + Base.unsafe_convert(Ptr{MadnlpCNumericOut}, pointer_from_objref(out))) + + + @info "sol" out.sol + sol_out::Vector{Float64} = unsafe_wrap(Array, out.sol, nvar) + obj_out::Vector{Float64} = unsafe_wrap(Array, out.obj, ncon) + con_out::Vector{Float64} = unsafe_wrap(Array, out.con, ncon) + mul_out::Vector{Float64} = unsafe_wrap(Array, out.mul, ncon) + mull_out::Vector{Float64} = unsafe_wrap(Array, out.mul_L, nvar) + mulu_out::Vector{Float64} = unsafe_wrap(Array, out.mul_U, nvar) + + println("ret_code: ", Cret) + + println("linear_solver: ", lin_solver_names[lin_solver_id]) + println("sol: ", sol_out) + println("con: ", con_out) + println("obj: ", obj_out[1]) + println("mul: ", mul_out) + println("mul_L: ", mull_out) + println("mul_U: ", mulu_out) + +end diff --git a/compiler/madnlp_c.h b/compiler/madnlp_c.h index 0e3f78a..9deba4c 100644 --- a/compiler/madnlp_c.h +++ b/compiler/madnlp_c.h @@ -1,7 +1,108 @@ -// Julia headers (for initialization and gc commands) -#include "uv.h" -#include "julia.h" +#ifndef _MADNLP_C_H +#define _MADNLP_C_H +#ifdef __cplusplus +extern "C" { +#endif -// prototype of the C entry points in our application -int madnlp_c(double x0, double y0, double z0, size_t iters); +#include + +/* Symbol visibility in DLLs */ +#ifndef MADNLP_SYMBOL_EXPORT +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +#if defined(STATIC_LINKED) +#define MADNLP_SYMBOL_EXPORT +#else +#define MADNLP_SYMBOL_EXPORT __declspec(dllexport) +#endif +#elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +#define MADNLP_SYMBOL_EXPORT __attribute__((visibility("default"))) +#else +#define MADNLP_SYMBOL_EXPORT +#endif +#endif + + +#define madnlp_int int +#define madnlp_real double + +// structs +struct MadnlpCStats; +struct MadnlpCDims; +struct MadnlpCInterface; + +// Opaque types +typedef struct MadnlpCSolver MadnlpCSolver; + +// function pointer types +typedef madnlp_int (*MadnlpCEvalObj)(const double*, double *, void*); +typedef madnlp_int (*MadnlpCEvalConstr)(const double*, double *, void*); +typedef madnlp_int (*MadnlpCEvalObjGrad)(const double*, double*, void*); +typedef madnlp_int (*MadnlpCEvalConstrJac)(const double*, double*, void*); +typedef madnlp_int (*MadnlpCEvalLagHess)(double, const double*, const double*, double*, void*); + +struct MadnlpCStats { + madnlp_int iter; +}; + +struct MadnlpCInterface { + MadnlpCEvalObj eval_obj; + MadnlpCEvalConstr eval_constr; + MadnlpCEvalObjGrad eval_obj_grad; + MadnlpCEvalConstrJac eval_constr_jac; + MadnlpCEvalLagHess eval_lag_hess; + + /// @brief number of variables + size_t nw; + /// @brief number of equality constraints + size_t nc; + + size_t* nzj_i; // 1-based + size_t* nzj_j; + size_t* nzh_i; + size_t* nzh_j; + + size_t nnzj; + size_t nnzh; + size_t nnzo; + + void* user_data; +}; + +struct MadnlpCNumericIn { + const double* x0; + const double* l0; + const double* ubx; + const double* lbx; + const double* ubg; + const double* lbg; +}; + +struct MadnlpCNumericOut { + double* sol; + double* con; + double* obj; + double* mul; + double* mul_L; + double* mul_U; + +}; + +MADNLP_SYMBOL_EXPORT struct MadnlpCSolver* madnlp_c_create(struct MadnlpCInterface* nlp_interface); +MADNLP_SYMBOL_EXPORT madnlp_int madnlp_c_solve(struct MadnlpCSolver*, struct MadnlpCNumericIn* in, struct MadnlpCNumericOut* out); + +/* -1 for not found, 0 for double, 1 for int, 2 for bool, 3 for string */ +MADNLP_SYMBOL_EXPORT int madnlp_c_option_type(const char* name); +MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_double(struct MadnlpCSolver* s, const char* name, double val); +MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_bool(struct MadnlpCSolver* s, const char* name, int val); +MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_int(struct MadnlpCSolver* s, const char* name, int val); +MADNLP_SYMBOL_EXPORT int madnlp_c_set_option_string(struct MadnlpCSolver* s, const char* name, const char* val); + +MADNLP_SYMBOL_EXPORT const struct MadnlpCStats* madnlp_c_get_stats(struct MadnlpCSolver* s); +MADNLP_SYMBOL_EXPORT void madnlp_c_destroy(struct MadnlpCSolver*); + +#ifdef __cplusplus +} +#endif + +#endif // _MADNLP_C_H diff --git a/src/MadNLP_C.jl b/src/MadNLP_C.jl index 8c9054d..f058139 100644 --- a/src/MadNLP_C.jl +++ b/src/MadNLP_C.jl @@ -1,21 +1,550 @@ module MadNLP_C +""" +Solve Generic formulated as the NLP: -using MadNLP, JuMP +minimize f(x1,x2,..,xN) +subject to g1(x1,...,xN) == 0 +subject to ... +subject to g2(x1,...,xN) == 0 +""" -Base.@ccallable function madnlp_c(x0::Cdouble, y0::Cdouble, z0::Cdouble, iters::Csize_t)::Cint - model = Model(()->MadNLP.Optimizer(print_level=MadNLP.INFO, max_iter=convert(Int64,iters))) - @variable(model, x, start = x0) - @variable(model, y, start = y0) - @variable(model, z, start = z0) - @NLobjective(model, Min, x^2 + 100*z^2) - @NLconstraint(model, z + (1-x)^2 - y == 0) - optimize!(model) +using Logging +using Base - println(value(x)) - println(value(y)) - println(value(z)) +# using MadNLP +using NLPModels - return 0 +using MadNLPMumps +using MadNLPGPU +using CUDA +using UnsafePointers + +export MadnlpCSolver, MadnlpCInterface, MadnlpCNumericIn, MadnlpCNumericOut, madnlp_c_get_stats, madnlp_c_startup, madnlp_c_shutdown, madnlp_c_create, madnlp_c_option_type, madnlp_c_set_option_double, madnlp_c_set_option_bool, madnlp_c_set_option_int, madnlp_c_set_option_string, madnlp_c_solve, madnlp_c_destroy + +struct CPUBuffers + x::Vector{Float64} + grad_f::Vector{Float64} + l::Vector{Float64} + cons::Vector{Float64} + jac_g::Vector{Float64} + hess_l::Vector{Float64} +end + +struct GenericModel{T, VT, IVT, FT} <: AbstractNLPModel{T,VT} + meta::NLPModelMeta{T, VT} + counters::NLPModels.Counters + bf::Union{CPUBuffers,Nothing} + obj::Vector{Float64} + nzj_i::IVT + nzj_j::IVT + nzh_i::IVT + nzh_j::IVT + eval_f::FT + eval_g::FT + eval_grad_f::FT + eval_jac_g::FT + eval_h::FT + user_data::FT +end + +mutable struct MadnlpCInterface + eval_obj::Ptr{Cvoid} + eval_constr::Ptr{Cvoid} + eval_obj_grad::Ptr{Cvoid} + eval_constr_jac::Ptr{Cvoid} + eval_lag_hess::Ptr{Cvoid} + + nw::Csize_t + nc::Csize_t + + nzj_i::Ptr{Csize_t} + nzj_j::Ptr{Csize_t} + nzh_i::Ptr{Csize_t} + nzh_j::Ptr{Csize_t} + + nnzj::Csize_t + nnzh::Csize_t + nnzo::Csize_t + + user_data::Ptr{Cvoid} +end + +mutable struct MadnlpCSolver + nlp_interface::MadnlpCInterface + lin_solver_id::Int64 + max_iters::Int64 + print_level::Int64 + minimize::Bool + res::MadNLP.MadNLPExecutionStats{Float64, Vector{Float64}} + MadnlpCSolver() = new() +end + +struct MadnlpCStats + iter::Int64 +end + +mutable struct MadnlpCNumericIn + x0::Ptr{Cdouble} + l0::Ptr{Cdouble} + lbx::Ptr{Cdouble} + ubx::Ptr{Cdouble} + lbg::Ptr{Cdouble} + ubg::Ptr{Cdouble} +end + +mutable struct MadnlpCNumericOut + sol::Ptr{Cdouble} + con::Ptr{Cdouble} + obj::Ptr{Cdouble} + mul::Ptr{Cdouble} + mul_L::Ptr{Cdouble} + mul_U::Ptr{Cdouble} + MadnlpCNumericOut() = new() +end + +function NLPModels.jac_structure!(nlp::GenericModel, I::AbstractVector{T}, J::AbstractVector{T}) where T + @info "jac_strc" + @info "nzj_i" nlp.nzj_i + @info "nzj_j" nlp.nzj_j + copyto!(I, nlp.nzj_i) + copyto!(J, nlp.nzj_j) + @info "I" I + @info "J" J +end + +function NLPModels.hess_structure!(nlp::GenericModel, I::AbstractVector{T}, J::AbstractVector{T}) where T + @info "hess_strc" + @info "nzh_i" nlp.nzh_i + @info "nzh_j" nlp.nzh_j + copyto!(I, nlp.nzh_i) + copyto!(J, nlp.nzh_j) + @info "I" I + @info "J" J +end + +function NLPModels.obj(nlp::GenericModel, x::AbstractVector) + @info "obj x=" x + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, x) + Cf::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.obj) + ret::Cint = ccall(nlp.eval_f, Cint, (Ptr{Cdouble},Ptr{Cdouble}, Ptr{Cvoid}), Cx, Cf, nlp.user_data) + if Bool(ret) @error "function call failed" end + #WARNING unsafe_wrap pointer must be 8-aligned! + @info "obj = " nlp.obj + return nlp.obj[1] +end + +function NLPModels.obj(nlp::GenericModel, x::CuArray) + copyto!(nlp.bf.x, x) + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.x) + # f::Vector{Float64} = Vector{Float64}(undef,1) + @info "obj-in" nlp.bf.x + Cf::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.obj) + ret::Cint = ccall(nlp.eval_f, Cint, (Ptr{Cdouble},Ptr{Cdouble}, Ptr{Cvoid}), Cx, Cf, nlp.user_data) + if Bool(ret) @error "function call failed" end + @info "obj-out" nlp.obj + return nlp.obj[1] +end + +function NLPModels.cons!(nlp::GenericModel, x::AbstractVector, c::AbstractVector) + @info "cons x = " x + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, x) + Cc::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, c) + ret::Cint = ccall(nlp.eval_g, Cint, (Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid}), Cx, Cc, nlp.user_data) + if Bool(ret) @error "function call failed" end + @info "cons = " c + return c +end + +function NLPModels.cons!(nlp::GenericModel, x::CuArray, c::CuArray) + copyto!(nlp.bf.x, x) + @info "GPU cons in" nlp.bf.x + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.x) + Cc::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.cons) + ret::Cint = ccall(nlp.eval_g, Cint, (Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid}), Cx, Cc, nlp.user_data) + if Bool(ret) @error "GPU cons failed" end + @info "GPU cons out" nlp.bf.cons + copyto!(c, nlp.bf.cons) + return c +end + +function NLPModels.grad!(nlp::GenericModel, x::AbstractVector, g::AbstractVector) + @info "grad-in" + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, x) + Cg::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, g) + @info "grad-in" x + ret::Cint = ccall(nlp.eval_grad_f, Cint, (Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid}), Cx, Cg, nlp.user_data) + if Bool(ret) @error "function call failed" end + @info "grad-out" g + # g = unsafe_wrap(Array, Cg, nlp.meta.nnzo) + return g +end + +function NLPModels.grad!(nlp::GenericModel, x::CuArray, g::CuArray) + copyto!(nlp.bf.x, x) + @info "GPU grad in" nlp.bf.x + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.x) + Cg::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.grad_f) + ret::Cint = ccall(nlp.eval_grad_f, Cint, (Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid}), Cx, Cg, nlp.user_data) + if Bool(ret) @error "GPU grad failed" end + @info "GPU grad out" nlp.bf.grad_f + copyto!(g, nlp.bf.grad_f) + return g +end + +function NLPModels.jac_coord!(nlp::GenericModel, x::AbstractVector, J::AbstractVector) + @info "jac_g" + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, x) + CJ::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, J) + ret::Cint = ccall(nlp.eval_jac_g, Cint, (Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid}), Cx, CJ, nlp.user_data) + if Bool(ret) @error "function call failed" end + J = unsafe_wrap(Array, CJ, nlp.meta.nnzj) + @info "jac_g" + return J +end + +function NLPModels.jac_coord!(nlp::GenericModel, x::CuArray, J::CuArray) + copyto!(nlp.bf.x, x) + @info "GPU jac in" nlp.bf.x + # copyto!(nlp.bf.jac_g, J) + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.x) + CJ::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.jac_g) + ret::Cint = ccall(nlp.eval_jac_g, Cint, (Ptr{Cdouble},Ptr{Cdouble},Ptr{Cvoid}), Cx, CJ, nlp.user_data) + if Bool(ret) @error "GPU jac failed" end + # J = unsafe_wrap(Array, CJ, nlp.meta.nnzj) + @info "GPU jac out" nlp.bf.jac_g + copyto!(J, nlp.bf.jac_g) + return J +end + +function NLPModels.hess_coord!(nlp::GenericModel, x::AbstractVector, y::AbstractVector, H::AbstractVector; + obj_weight::Float64=1.0) + @info "hess" + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, x) + Cy::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, y) + CH::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, H) + ret::Cint = ccall(nlp.eval_h, Cint, + (Float64, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cvoid}), + obj_weight, Cx, Cy, CH, nlp.user_data) + if Bool(ret) @error "function call failed" end + H = unsafe_wrap(Array, CH, nlp.meta.nnzh) + @info "hess" x H + return H +end + +function NLPModels.hess_coord!(nlp::GenericModel, x::CuArray, y::CuArray, H::CuArray; + obj_weight::Cdouble=1.0) + copyto!(nlp.bf.x, x) + copyto!(nlp.bf.l, y) + # copyto!(nlp.bf.hess_l, H) + @info "GPU hess x.in" nlp.bf.x + @info "GPU hess l.in" nlp.bf.l + Cx::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.x) + Cy::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.l) + CH::Ptr{Cdouble} = Base.unsafe_convert(Ptr{Cdouble}, nlp.bf.hess_l) + ret::Cint = ccall(nlp.eval_h, Cint, + (Float64, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cdouble}, Ptr{Cvoid}), + obj_weight, Cx, Cy, CH, nlp.user_data) + if Bool(ret) @error "GPU hess failed" end + @info "GPU hess out" nlp.bf.grad_f + copyto!(H, nlp.bf.hess_l) + # H = unsafe_wrap(Array, CH, nlp.meta.nnzh) + return H +end + + +function set_option(s::Ptr{MadnlpCSolver}, name::String, value::Any) + if name == "print_level" + s.print_level = Int(value) + if s.print_level > 5 s.print_level = 5 end + if s.print_level < 0 s.print_level = 0 end + elseif name == "lin_solver_id" + s.lin_solver_id = Int(value) + if s.lin_solver_id > 5 s.lin_solver_id = 5 end + if s.lin_solver_id < 0 s.lin_solver_id = 0 end + else + @warn "Unknown option $name" + end +end + +Base.@ccallable function madnlp_c_startup(argc::Cint, argv::Ptr{Ptr{Cchar}})::Cvoid + init_julia(argc, argv) +end + +Base.@ccallable function madnlp_c_shutdown()::Cvoid + shutdown_julia(1) +end + +Base.@ccallable function madnlp_c_create(nlp_interface::Ptr{MadnlpCInterface})::Ptr{MadnlpCSolver} + # Allocate memory for the solver + solver_ptr = Ptr{MadnlpCSolver}(Libc.malloc(sizeof(MadnlpCSolver))) + + # Create the solver object + solver = MadnlpCSolver() + solver.nlp_interface = unsafe_load(nlp_interface) + solver.lin_solver_id = 0 + solver.max_iters = 1000 + solver.print_level = 5 + solver.minimize = true + + # Copy the solver object to the allocated memory + unsafe_store!(solver_ptr, solver) + + # Return the pointer to the solver object + return solver_ptr +end + +Base.@ccallable function madnlp_c_option_type(name::Ptr{Cchar})::Cint + n = unsafe_string(name) + if n == "acceptable_tol" return 0 end + if n == "bound_frac" return 0 end + if n == "bound_push" return 0 end + if n == "bound_relax_factor" return 0 end + if n == "constr_viol_tol" return 0 end + if n == "lammax" return 0 end + if n == "mu_init" return 0 end + if n == "recalc_y_feas_tol" return 0 end + if n == "tol" return 0 end + if n == "warm_start_mult_bound_push" return 0 end + if n == "acceptable_iter" return 1 end + if n == "max_iter" return 1 end + if n == "print_level" return 1 end + if n == "lin_solver_id" return 1 end + if n == "iterative_refinement" return 2 end + if n == "ls_scaling" return 2 end + if n == "recalc_y" return 2 end + if n == "warm_start_init_point" return 2 end + return -1 +end + +Base.@ccallable function madnlp_c_set_option_double(s::Ptr{MadnlpCSolver}, name::Ptr{Cchar}, val::Cdouble)::Cint + try + set_option(s, unsafe_string(name), val) + catch e + return 1 + end + return 0 +end + +Base.@ccallable function madnlp_c_set_option_bool(s::Ptr{MadnlpCSolver}, name::Ptr{Cchar}, val::Cint)::Cint + try + set_option(s, unsafe_string(name), Bool(val)) + catch e + return 1 + end + return 0 +end + +Base.@ccallable function madnlp_c_set_option_int(s::Ptr{MadnlpCSolver}, name::Ptr{Cchar}, val::Cint)::Cint + try + set_option(s, unsafe_string(name), val) + catch e + return 1 + end + return 0 +end + +Base.@ccallable function madnlp_c_set_option_string(s::Ptr{MadnlpCSolver}, name::Ptr{Cchar}, val::Ptr{Cchar})::Cint + try + set_option(s, unsafe_string(name), unsafe_string(val)) + catch e + return 1 + end + return 0 +end + +Base.@ccallable function madnlp_c_get_stats(s::Ptr{MadnlpCSolver})::Ptr{MadnlpCStats} + return 0 +end + +Base.@ccallable function madnlp_c_solve(s::Ptr{MadnlpCSolver},in::Ptr{MadnlpCNumericIn},out::Ptr{MadnlpCNumericOut})::Cint + + solver = unsafe_load(s) + nlp_interface = solver.nlp_interface + nvar = nlp_interface.nw + ncon = nlp_interface.nc + + out_backup = out + + in = unsafe_load(in) + out = UnsafePtr(out) + + # default values + main_log_level = Logging.Warn + madnlp_log = MadNLP.NOTICE + + if solver.print_level == 1 + main_log_level = Logging.Error + madnlp_log = MadNLP.ERROR + elseif solver.print_level == 2 + main_log_level = Logging.Warn + madnlp_log = MadNLP.WARN + elseif solver.print_level == 3 + main_log_level = Logging.Warn + madnlp_log = MadNLP.NOTICE + elseif solver.print_level == 4 + main_log_level = Logging.Info + madnlp_log = MadNLP.INFO + elseif solver.print_level == 5 + main_log_level = Logging.Debug + madnlp_log = MadNLP.DEBUG + elseif solver.print_level == 6 + main_log_level = Logging.Debug + madnlp_log = MadNLP.TRACE + end + + logger = ConsoleLogger(stderr, main_log_level) + global_logger(logger) + + GPU_DEVICE::Bool = false + + stuff = in.lbx + + @info "in lbx" stuff + + x0 = unsafe_wrap(Array, in.x0, (nvar,)) + y0 = unsafe_wrap(Array, in.l0, (ncon,)) + lvar = unsafe_wrap(Array, in.lbx, (nvar,)) + uvar = unsafe_wrap(Array, in.ubx, (nvar,)) + lcon = unsafe_wrap(Array, in.lbg, (ncon,)) + ucon = unsafe_wrap(Array, in.ubg, (ncon,)) + + nzj_i = unsafe_wrap(Array, nlp_interface.nzj_i, (nlp_interface.nnzj,)) + nzj_j = unsafe_wrap(Array, nlp_interface.nzj_j, (nlp_interface.nnzj,)) + nzh_i = unsafe_wrap(Array, nlp_interface.nzh_i, (nlp_interface.nnzh,)) + nzh_j = unsafe_wrap(Array, nlp_interface.nzh_j, (nlp_interface.nnzh,)) + + @info "x0 julia" x0 + @info "lvar julia" lvar + + lin_solver_name = "none" + if solver.lin_solver_id == 0 + lin_solver_name = "mumps" + linear_solver = MadNLPMumps.MumpsSolver + elseif solver.lin_solver_id == 1 + lin_solver_name = "umfpack" + linear_solver = UmfpackSolver + elseif solver.lin_solver_id == 2 + lin_solver_name = "lapackCPU" + linear_solver = LapackCPUSolver + elseif solver.lin_solver_id == 3 + lin_solver_name = "CUDSSS" + linear_solver = MadNLPGPU.CUDSSSolver + GPU_DEVICE = true + elseif solver.lin_solver_id == 4 + lin_solver_name = "lapackGPU" + linear_solver = MadNLPGPU.LapackGPUSolver + GPU_DEVICE = true + elseif solver.lin_solver_id == 5 + lin_solver_name = "CuCholesky" + linear_solver = MadNLPGPU.CuCholeskySolver + GPU_DEVICE = true + end + @info "Using linear solver $(lin_solver_name)" + + + buffers = nothing + if GPU_DEVICE + Gx0 = CuArray{Float64}(undef, nvar) + Gy0 = CuArray{Float64}(undef, ncon) + Glvar = CuArray{Float64}(undef, nvar) + Guvar = CuArray{Float64}(undef, nvar) + Glcon = CuArray{Float64}(undef, ncon) + Gucon = CuArray{Float64}(undef, ncon) + Gnzj_i = CuArray{UInt64}(undef, nnzj) + Gnzj_j = CuArray{UInt64}(undef, nnzj) + Gnzh_i = CuArray{UInt64}(undef, nnzh) + Gnzh_j = CuArray{UInt64}(undef, nnzh) + + copyto!(Gx0, x0) + copyto!(Gy0, y0) + copyto!(Glvar, lvar) + copyto!(Guvar, uvar) + copyto!(Glcon, lcon) + copyto!(Gucon, ucon) + copyto!(Gnzj_i, nzj_i) + copyto!(Gnzj_j, nzj_j) + copyto!(Gnzh_i, nzh_i) + copyto!(Gnzh_j, nzh_j) + + x0 = Gx0 + y0 = Gy0 + lvar = Glvar + uvar = Guvar + lcon = Glcon + ucon = Gucon + nzj_i = Gnzj_i + nzj_j = Gnzj_j + nzh_i = Gnzh_i + nzh_j = Gnzh_j + + buffers = CPUBuffers( + Vector{Float64}(undef, nvar), + Vector{Float64}(undef, nlp_interface.nnzo), + Vector{Float64}(undef, ncon), + Vector{Float64}(undef, ncon), + Vector{Float64}(undef, nlp_interface.nnzj), + Vector{Float64}(undef, nlp_interface.nnzh) + ) + end + + @info "x0" x0 + @info "y0" y0 + @info "lvar" lvar + @info "uvar" uvar + @info "lcon" lcon + @info "ucon" ucon + + nlp = GenericModel( + NLPModelMeta( + Int64(nvar), + ncon = Int64(ncon), + nnzo = nlp_interface.nnzo, + nnzj = nlp_interface.nnzj, + nnzh = nlp_interface.nnzh, + x0 = x0, + y0 = y0, + lvar = lvar, + uvar = uvar, + lcon = lcon, + ucon = ucon, + name = "Generic", + minimize = solver.minimize + ), + Counters(), + buffers, + Vector{Float64}(undef, 1), + nzj_i, + nzj_j, + nzh_i, + nzh_j, + nlp_interface.eval_obj, + nlp_interface.eval_constr, + nlp_interface.eval_obj_grad, + nlp_interface.eval_constr_jac, + nlp_interface.eval_lag_hess, + nlp_interface.user_data + ) + + madnlp_solver = MadNLPSolver(nlp; print_level = madnlp_log, linear_solver = linear_solver) + solver.res = MadNLP.solve!(madnlp_solver, max_iter = Int(solver.max_iters)) + + # Make results available to C + out.sol[] = Base.unsafe_convert(Ptr{Cdouble},solver.res.solution) + out.obj[] = Base.unsafe_convert(Ptr{Cdouble},Ref(solver.res.objective)) + out.con[] = Base.unsafe_convert(Ptr{Cdouble},solver.res.constraints) + out.mul[] = Base.unsafe_convert(Ptr{Cdouble},solver.res.multipliers) + out.mul_L[] = Base.unsafe_convert(Ptr{Cdouble},solver.res.multipliers_L) + out.mul_U[] = Base.unsafe_convert(Ptr{Cdouble},solver.res.multipliers_U) + + return 0 + +end + + +Base.@ccallable function madnlp_c_destroy(s::Ptr{MadnlpCSolver})::Cvoid + # Free the allocated memory + Libc.free(s) end end # module MadNLP_C +