Memory leak with pyplot
まだ誰も着手していません。
評価
調査の方向性
提供された Julia MWE と pyplot への PyCall 呼び出しから始め、プロットの作成とガベージコレクションの有無でメモリ使用量を比較します。PyCall を通じて返される fig オブジェクトと plot オブジェクトを追跡します。保持されている参照を特定して修正し、プロットを繰り返してもメモリが無制限に増加しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
When I create matplotlib.pyplot plots, the memory keeps increasing and is not released by the garbage collector. The following is the case I'm interested in (with subplots) and bellow I include a more basic MWE.
Example with subplots
using PyCall
plt = pyimport("matplotlib.pyplot")
function test_pyplot()
for i in 1:10000
@info i
z = rand(4, 50)
ẑ = rand(4, 50)
fig, axs = plot_pyplot(z, ẑ)
end
end
function plot_pyplot(z, ẑ)
# plt = pyimport("matplotlib.pyplot")
N = Int(size(z, 1)/2)
fig, axs = plt.subplots(2, N)
for i in 1:N
axs[1,i].plot(z[i,:], label = "true")
axs[1,i].plot(ẑ[i,:], label = "model")
axs[2,i].plot(z[i+N,:], label = "true")
axs[2,i].plot(ẑ[i+N,:], label = "predicted")
axs[2,i].set_xlabel("time steps")
axs[i].grid(true)
axs[i+N].grid(true)
axs[i+N].label_outer()
axs[i].label_outer()
end
# plt.close()
return fig, axs
end
test_pyplot()
I tried defining plt and closing it inside the plot_pyplot function (commented lines) but it doesn't solve the memory leak.
Here you have a simpler MWE:
using PyCall
plt = pyimport("matplotlib.pyplot")
plot_pyplot(z) = plt.plot(z)
function test_pyplot()
for i in 1:1000000
@info i
z = rand(50)
fig = plot_pyplot(z)
end
end
Version info and status
julia> versioninfo()
Julia Version 1.8.2
Commit 36034abf260 (2022-09-29 15:21 UTC)
Platform Info:
OS: macOS (arm64-apple-darwin21.3.0)
CPU: 8 × Apple M1 Pro
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
Threads: 1 on 6 virtual cores
(memory_leak) pkg> st
Status `~/Documents/issues/memory_leak/Project.toml`
[438e738f] PyCall v1.94.1
I need to use pyplot directly from PyCall.jl and not through PyPlot.jl because I need to pass the fig object to Wandb.jl. Actually, maybe I could get that object from PyPlot.jl, I didn't try that yet. But since I found the bug here, I think it can be helpful to report it anyway.
- 主要言語
- Julia
- スター
- 1.5k
- フォーク
- 186
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaPy/PyCall.jl のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
Meta-Issue: Mutli-threading leads to segfaults対応中かも @topolarity が 211 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
-
Crashes with Julia 1.12 and Revise.jl対応中かも @topolarity が 211 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
JuliaPy/PyCall.jl の issue をすべて見る
似ている issue
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up steps対応中かも @thevolatilebit が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
found-by-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
exanauts/SparseDirectSolver.jl#92 ·
メンテナーはふだん 1 日以内に返信
-
`inv` of a dense matrix fails for arrays whose `parent` is not an array of the same kind対応中かも @devmotion が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
JuliaLang/LinearAlgebra.jl#1740 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
NumericalEarth/Breeze.jl#1051 ·
メンテナーはふだん 1 日以内に返信