Skip to content

Commit ab9bc76

Browse files
devmotionzsteve
andauthored
Update examples and reduce dependencies (#128)
Co-authored-by: Stephen Zhang <[email protected]>
1 parent 59ff422 commit ab9bc76

File tree

5 files changed

+66
-80
lines changed

5 files changed

+66
-80
lines changed

examples/basic/Manifest.toml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ deps = ["Random", "Serialization", "Sockets"]
132132
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
133133

134134
[[Distributions]]
135-
deps = ["FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"]
136-
git-tree-sha1 = "f389cb8974e02d7eaa6ae2ccedbbfb43174cd8e8"
135+
deps = ["ChainRulesCore", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"]
136+
git-tree-sha1 = "c2dbc7e0495c3f956e4615b78d03c7aa10091d0c"
137137
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
138-
version = "0.25.14"
138+
version = "0.25.15"
139139

140140
[[DocStringExtensions]]
141141
deps = ["LibGit2"]
@@ -325,6 +325,12 @@ git-tree-sha1 = "d735490ac75c5cb9f1b00d8b5509c11984dc6943"
325325
uuid = "aacddb02-875f-59d6-b918-886e6ef4fbf8"
326326
version = "2.1.0+0"
327327

328+
[[Krylov]]
329+
deps = ["LinearAlgebra", "Printf", "SparseArrays"]
330+
git-tree-sha1 = "c5b01ca4fa9d09c17da742f67e321386a2557602"
331+
uuid = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
332+
version = "0.7.6"
333+
328334
[[LAME_jll]]
329335
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
330336
git-tree-sha1 = "f6250b16881adf048549549fba48b1161acdac8c"
@@ -586,15 +592,15 @@ version = "2.0.1"
586592

587593
[[PlotUtils]]
588594
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
589-
git-tree-sha1 = "c67334c786157d6ef091ce622b365d3d60b1e2c4"
595+
git-tree-sha1 = "9ff1c70190c1c30aebca35dc489f7411b256cd23"
590596
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
591-
version = "1.0.12"
597+
version = "1.0.13"
592598

593599
[[Plots]]
594600
deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"]
595-
git-tree-sha1 = "0036d433cacff4767ff622be3cb2c281b773a2b4"
601+
git-tree-sha1 = "9e1a400fb1f27b4146fe35dc1a22de6c793b8f20"
596602
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
597-
version = "1.21.1"
603+
version = "1.21.2"
598604

599605
[[Preferences]]
600606
deps = ["TOML"]
@@ -651,9 +657,9 @@ version = "1.1.2"
651657

652658
[[RecipesPipeline]]
653659
deps = ["Dates", "NaNMath", "PlotUtils", "RecipesBase"]
654-
git-tree-sha1 = "e377b29ebe56fadd8b40b04d8eb117c98d0a9960"
660+
git-tree-sha1 = "d4491becdc53580c6dadb0f6249f90caae888554"
655661
uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c"
656-
version = "0.3.6"
662+
version = "0.4.0"
657663

658664
[[Reexport]]
659665
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
@@ -736,15 +742,15 @@ version = "1.0.0"
736742

737743
[[StatsBase]]
738744
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
739-
git-tree-sha1 = "fed1ec1e65749c4d96fc20dd13bea72b55457e62"
745+
git-tree-sha1 = "8cbbc098554648c84f79a463c9ff0fd277144b6c"
740746
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
741-
version = "0.33.9"
747+
version = "0.33.10"
742748

743749
[[StatsFuns]]
744-
deps = ["IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"]
745-
git-tree-sha1 = "20d1bb720b9b27636280f751746ba4abb465f19d"
750+
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"]
751+
git-tree-sha1 = "46d7ccc7104860c38b11966dd1f72ff042f382e4"
746752
uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
747-
version = "0.9.9"
753+
version = "0.9.10"
748754

749755
[[StructArrays]]
750756
deps = ["Adapt", "DataAPI", "StaticArrays", "Tables"]
@@ -793,10 +799,10 @@ uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
793799
version = "0.9.6"
794800

795801
[[Tulip]]
796-
deps = ["CodecBzip2", "CodecZlib", "LDLFactorizations", "LinearAlgebra", "LinearOperators", "Logging", "MathOptInterface", "Printf", "QPSReader", "SparseArrays", "SuiteSparse", "Test", "TimerOutputs"]
797-
git-tree-sha1 = "e381662f7d351defc05ebbc75c228c38501901f4"
802+
deps = ["CodecBzip2", "CodecZlib", "Krylov", "LDLFactorizations", "LinearAlgebra", "LinearOperators", "Logging", "MathOptInterface", "Printf", "QPSReader", "SparseArrays", "SuiteSparse", "Test", "TimerOutputs"]
803+
git-tree-sha1 = "753c5bd161ca2a64da995a21900bcc177bd7d8e4"
798804
uuid = "6dd1b50a-3aae-11e9-10b5-ef983d2400fa"
799-
version = "0.7.5"
805+
version = "0.8.0"
800806

801807
[[URIs]]
802808
git-tree-sha1 = "97bbe755a53fe859669cd907f2d96aee8d2c1355"

examples/basic/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ Literate = "2.9"
1414
OptimalTransport = "0.3"
1515
Plots = "1"
1616
PythonOT = "0.1"
17-
Tulip = "0.7"
17+
Tulip = "0.8"
1818
julia = "1"

examples/variational/Manifest.toml

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
1111

1212
[[ArrayInterface]]
1313
deps = ["IfElse", "LinearAlgebra", "Requires", "SparseArrays", "Static"]
14-
git-tree-sha1 = "b6dec2ed4f10840e2cf836508525656450d4d289"
14+
git-tree-sha1 = "2cc636ec3015631b1c6ae1ccabb459fd9407997b"
1515
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
16-
version = "3.1.26"
16+
version = "3.1.29"
1717

1818
[[Artifacts]]
1919
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
@@ -144,10 +144,10 @@ deps = ["Random", "Serialization", "Sockets"]
144144
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
145145

146146
[[Distributions]]
147-
deps = ["FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"]
148-
git-tree-sha1 = "f389cb8974e02d7eaa6ae2ccedbbfb43174cd8e8"
147+
deps = ["ChainRulesCore", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"]
148+
git-tree-sha1 = "c2dbc7e0495c3f956e4615b78d03c7aa10091d0c"
149149
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
150-
version = "0.25.14"
150+
version = "0.25.15"
151151

152152
[[DocStringExtensions]]
153153
deps = ["LibGit2"]
@@ -231,11 +231,6 @@ git-tree-sha1 = "aa31987c2ba8704e23c6c8ba8a4f769d5d7e4f91"
231231
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
232232
version = "1.0.10+0"
233233

234-
[[FunctionWrappers]]
235-
git-tree-sha1 = "241552bc2209f0fa068b6415b1942cc0aa486bcc"
236-
uuid = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
237-
version = "1.1.2"
238-
239234
[[GLFW_jll]]
240235
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Pkg", "Xorg_libXcursor_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll"]
241236
git-tree-sha1 = "dba1e8614e98949abfa60480b13653813d8f0157"
@@ -622,15 +617,15 @@ version = "2.0.1"
622617

623618
[[PlotUtils]]
624619
deps = ["ColorSchemes", "Colors", "Dates", "Printf", "Random", "Reexport", "Statistics"]
625-
git-tree-sha1 = "c67334c786157d6ef091ce622b365d3d60b1e2c4"
620+
git-tree-sha1 = "9ff1c70190c1c30aebca35dc489f7411b256cd23"
626621
uuid = "995b91a9-d308-5afd-9ec6-746e21dbc043"
627-
version = "1.0.12"
622+
version = "1.0.13"
628623

629624
[[Plots]]
630625
deps = ["Base64", "Contour", "Dates", "Downloads", "FFMPEG", "FixedPointNumbers", "GR", "GeometryBasics", "JSON", "Latexify", "LinearAlgebra", "Measures", "NaNMath", "PlotThemes", "PlotUtils", "Printf", "REPL", "Random", "RecipesBase", "RecipesPipeline", "Reexport", "Requires", "Scratch", "Showoff", "SparseArrays", "Statistics", "StatsBase", "UUIDs"]
631-
git-tree-sha1 = "0036d433cacff4767ff622be3cb2c281b773a2b4"
626+
git-tree-sha1 = "9e1a400fb1f27b4146fe35dc1a22de6c793b8f20"
632627
uuid = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
633-
version = "1.21.1"
628+
version = "1.21.2"
634629

635630
[[PositiveFactorizations]]
636631
deps = ["LinearAlgebra"]
@@ -675,9 +670,9 @@ version = "1.1.2"
675670

676671
[[RecipesPipeline]]
677672
deps = ["Dates", "NaNMath", "PlotUtils", "RecipesBase"]
678-
git-tree-sha1 = "e377b29ebe56fadd8b40b04d8eb117c98d0a9960"
673+
git-tree-sha1 = "d4491becdc53580c6dadb0f6249f90caae888554"
679674
uuid = "01d81517-befc-4cb6-b9ec-a95719d0359c"
680-
version = "0.3.6"
675+
version = "0.4.0"
681676

682677
[[Reexport]]
683678
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
@@ -690,12 +685,6 @@ git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
690685
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
691686
version = "1.1.3"
692687

693-
[[ReverseDiff]]
694-
deps = ["DiffResults", "DiffRules", "ForwardDiff", "FunctionWrappers", "LinearAlgebra", "MacroTools", "NaNMath", "Random", "SpecialFunctions", "StaticArrays", "Statistics"]
695-
git-tree-sha1 = "63ee24ea0689157a1113dbdab10c6cb011d519c4"
696-
uuid = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
697-
version = "1.9.0"
698-
699688
[[Rmath]]
700689
deps = ["Random", "Rmath_jll"]
701690
git-tree-sha1 = "bf3188feca147ce108c76ad82c2792c57abe7b1f"
@@ -751,9 +740,9 @@ version = "1.6.1"
751740

752741
[[Static]]
753742
deps = ["IfElse"]
754-
git-tree-sha1 = "62701892d172a2fa41a1f829f66d2b0db94a9a63"
743+
git-tree-sha1 = "854b024a4a81b05c0792a4b45293b85db228bd27"
755744
uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
756-
version = "0.3.0"
745+
version = "0.3.1"
757746

758747
[[StaticArrays]]
759748
deps = ["LinearAlgebra", "Random", "Statistics"]
@@ -772,15 +761,15 @@ version = "1.0.0"
772761

773762
[[StatsBase]]
774763
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
775-
git-tree-sha1 = "fed1ec1e65749c4d96fc20dd13bea72b55457e62"
764+
git-tree-sha1 = "8cbbc098554648c84f79a463c9ff0fd277144b6c"
776765
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
777-
version = "0.33.9"
766+
version = "0.33.10"
778767

779768
[[StatsFuns]]
780-
deps = ["IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"]
781-
git-tree-sha1 = "20d1bb720b9b27636280f751746ba4abb465f19d"
769+
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"]
770+
git-tree-sha1 = "46d7ccc7104860c38b11966dd1f72ff042f382e4"
782771
uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
783-
version = "0.9.9"
772+
version = "0.9.10"
784773

785774
[[StructArrays]]
786775
deps = ["Adapt", "DataAPI", "StaticArrays", "Tables"]
@@ -792,11 +781,6 @@ version = "0.6.1"
792781
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"]
793782
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
794783

795-
[[Suppressor]]
796-
git-tree-sha1 = "a819d77f31f83e5792a76081eee1ea6342ab8787"
797-
uuid = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
798-
version = "0.2.0"
799-
800784
[[TOML]]
801785
deps = ["Dates"]
802786
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

examples/variational/Project.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
[deps]
22
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
3-
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
43
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
54
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
65
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
6+
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
77
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
88
OptimalTransport = "7e02d93a-ae51-4f58-b602-d97af76e3b33"
99
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
10-
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
1110
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
12-
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
1311

1412
[compat]
1513
Distances = "0.10"
16-
LaTeXStrings = "1.2"
1714
Literate = "2.9"
1815
LogExpFunctions = "0.3"
1916
Optim = "1.4"
2017
OptimalTransport = "0.3"
2118
Plots = "1"
22-
ReverseDiff = "1.9"
2319
StatsBase = "0.33"
24-
Suppressor = "0.2"
2520
julia = "1"

examples/variational/script.jl

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@
5959
# ## Problem setup
6060
#
6161
using OptimalTransport
62-
using StatsBase, Distances
63-
using ReverseDiff, Optim, LinearAlgebra
64-
using Plots
62+
using Distances
6563
using LogExpFunctions
66-
using LaTeXStrings
67-
using Suppressor
64+
using Optim
65+
using Plots
66+
using StatsBase
67+
68+
using LinearAlgebra
69+
using Logging
6870

6971
# Here, we set up the computational domain that we work on - we discretize the interval $[-1, 1]$.
7072
# The natural boundary conditions to use will be Neumann (zero flux), see e.g. [^Santam2017]
@@ -119,29 +121,30 @@ end;
119121

120122
# `step` solves the implicit step problem to produce $\rho_{t + \tau}$ from $\rho_t$.
121123
function step(ρ0, τ, ε, C, G)
122-
opt = optimize(
123-
u -> G(softmax(u), ρ0, τ, ε, C),
124-
ones(size(ρ0)),
125-
LBFGS(),
126-
Optim.Options(; iterations=50, g_tol=1e-6);
127-
autodiff=:forward,
128-
)
124+
## only print error messages
125+
opt = with_logger(SimpleLogger(stderr, Logging.Error)) do
126+
optimize(
127+
u -> G(softmax(u), ρ0, τ, ε, C),
128+
ones(size(ρ0)),
129+
LBFGS(),
130+
Optim.Options(; iterations=50, g_tol=1e-6);
131+
autodiff=:forward,
132+
)
133+
end
129134
return softmax(Optim.minimizer(opt))
130135
end
131136
# Now we simulate `N = 10` iterates of the gradient flow and plot the result.
132137
N = 10
133138
ρ = similar(ρ0, size(ρ0, 1), N)
134139
ρ[:, 1] = ρ0
135-
@suppress begin
136-
for i in 2:N
137-
ρ[:, i] = step(ρ[:, i - 1], τ, ε, C, G_fpe)
138-
end
140+
for i in 2:N
141+
ρ[:, i] = step(ρ[:, i - 1], τ, ε, C, G_fpe)
139142
end
140143
colors = range(colorant"red"; stop=colorant"blue", length=N)
141144
plot(
142145
support,
143146
ρ;
144-
title=L"F(\rho) = \langle \psi, \rho \rangle + \langle \rho, \log(\rho) \rangle",
147+
title=raw"$F(\rho) = \langle \psi, \rho \rangle + \langle \rho, \log(\rho) \rangle$",
145148
palette=colors,
146149
legend=nothing,
147150
)
@@ -164,15 +167,13 @@ end;
164167
N = 10
165168
ρ = similar(ρ0, size(ρ0, 1), N)
166169
ρ[:, 1] = ρ0
167-
@suppress begin
168-
for i in 2:N
169-
ρ[:, i] = step(ρ[:, i - 1], τ, ε, C, G_pme)
170-
end
170+
for i in 2:N
171+
ρ[:, i] = step(ρ[:, i - 1], τ, ε, C, G_pme)
171172
end
172173
plot(
173174
support,
174175
ρ;
175-
title=L"F(\rho) = \langle \psi, \rho \rangle + \langle \rho, \rho - 1\rangle",
176+
title=raw"$F(\rho) = \langle \psi, \rho \rangle + \langle \rho, \rho - 1\rangle$",
176177
palette=colors,
177178
legend=nothing,
178179
)

0 commit comments

Comments
 (0)