LoginSignup
5
2

More than 1 year has passed since last update.

エコな環境でのNx勉強と久しぶりのPR(補足)

Last updated at Posted at 2022-07-23

0.はじめに

以下の補足記事です。

LT大会で@RyoWakabayashiさんが発表されていたExplorerがiMac Dockerでは動くのですが、MBP WSLでは動かない現象が発生したのでその対処です。
ただ、何故動かなかったのかの原因究明は出来ていないので、どなたか詳しい方にアドバイスいただけると嬉しいです。
原因判明、JoseさんのPRの反映待ちです(詳しくは最後に)。

1. Livebookでは動かないが・・・

1-1.Livebook Mix.Install

我が家のLivebookエコ環境で以下の13_explorer.livemdを実行すると、最初のMix.Installでこけます:sob:

MAC-18.jpg

== Compilation error in file lib/explorer/polars_backend/native.ex ==
** (FunctionClauseError) no function clause matching in String.to_charlist/1    
    
    The following arguments were given to String.to_charlist/1:
    
        # 1
        nil
    
    Attempted function clauses (showing 1 out of 1):
    
        def to_charlist(string) when is_binary(string)
    
    (elixir 1.13.2) lib/string.ex:2401: String.to_charlist/1
    (rustler_precompiled 0.5.1) lib/rustler_precompiled.ex:611: RustlerPrecompiled.download_nif_artifact/1
    (rustler_precompiled 0.5.1) lib/rustler_precompiled.ex:468: RustlerPrecompiled.download_or_reuse_nif_file/1
    (rustler_precompiled 0.5.1) lib/rustler_precompiled.ex:124: RustlerPrecompiled.__using__/2
    lib/explorer/polars_backend/native.ex:8: (module)
could not compile dependency :explorer, "mix compile" failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile explorer", update it with "mix deps.update explorer" or clean it with "mix deps.clean explorer"

iMac側のDockerでは動作確認していたのになんか変です。

1-2. iex -S mix

念のため iexで explorerが使えるかどうか確認します。
毎度おなじみの手順で、mix.exsに explorerを指定して実行します。

mix new my_app
cd my_app
vi mix.exs
mix desp.get

今回はWSLの/rootで実行しました。
PC-65.PNG

iex -S mix で 13_explorer.livemdの最初だけ実行してみます。

iex -S mix

PC-66.PNG
ちゃんと動きますね。。。
PC-67.PNG

1-3. NIFがダウンロードされていないみたい

動いている/root/my_appのキャッシュと/home/livebookのキャッシュを比較するとexplorerのNIFがmetadataには書き込まれているものの、実体がないことが分かります。
PC-64.PNG

2. Livebookで動くようにする

2-1. 無理やり動かせるが・・・

手動で/root/my_app/.cache配下にあるNIF (libexplorer-v0.2.0-nif-2.16-x86-64-unknown-linux-gnu.so.tar.gz)を/home/libebook/.cache配下にコピーすればキャッシュが効くのでMix.installから動くようになるんですが、イマイチです。

なんか手段はないかなーと思ってググっているとこんな記事がありました。

There are three kinds of runtime, but they all let you point to code and call it in any Elixir cell within your Livebook.
The three runtime options are:
Embedded
Attached node
Mix standalone

LivebookのRuntimeを指定できるようなので、デフォルトのEmbeddedからMix standaloneに変更してみます。

2-2. Livebook Runtime変更

Livebook画面左側上から4番目のボタンからRuntimeを変更します。
MAC-19.jpg
歯車マークを押して出てくるこの画面でMix standaloneを選択
MAC-21.jpg
iex -S mixで動作確認した /root/my_appを指定してConnectします。
MAC-22.jpg
接続成功メッセージが出ます。
MAC-23.jpg
この状態で Mix.installをスキップして残りを実行できるようになりました。
MAC-24.jpg

因みにRuntime指定のAttached NodeはErlangならではのやり方みたいで面白そうです。

The attached node runtime connects a Livebook to a running Elixir app via the usual Erlang magic that we use to connect two running nodes. 
As long as the app starts with a cookie that you know and a sname, you can give them to Livebook and connect. This is like getting a remote shell in a running app but with a more full-featured text-editing environment.

と・とりあえず、我が家のエコな環境では、Livebook Mix.Installでコケるけど iex -S mixでは動くようなケースはRuntimeをMix Standalone指定するやり方で対処したいと思います:sweat:

3. 原因判明と対処

3-1. 原因判明

LT会でご一緒した皆さんにSlackで共有したところ、LT会主催の@zacky1972先生が開発グループに質問してくださいました。
image.png
でその日のうちにこんな情報が
image.png
image.png

実はNIF DL不具合発見時にHTTP_PROXY環境変数は疑っていたのですが、何も設定されていない状態だったので影響ないと思っていました。何のことはない、起動スクリプトのHTTP_PROXY環境変数部分をコメントアウトすることであっさりMix.installが動きました:sweat:

root@MBP2-WIN:/home/livebook# cat boot_for_wsl.sh
#!/bin/bash

# export HTTP_PROXY="$(wslvar HTTP_PROXY)" ← コメントアウト
# export HTTPS_PROXY=$HTTP_PROXY      ← コメントアウト
export HOME=/home/livebook
export EVISION_PREFER_PRECOMPILED=true

export LIVEBOOK_PASSWORD=$(wslvar LIVEBOOK_PASSWORD)
export LIVEBOOK_IP=$(wslvar LIVEBOOK_IP)

/app/bin/livebook start
root@MBP2-WIN:/home/livebook#

こちらがJoseさんが出したPR

環境変数が空っぽなのと、その環境変数が存在しないのは異なっていて、前者はproxy処理で HTTP_PROXY環境変数として正しくない値がセットされてると見做されたって感じです(後者はHTTP_PROXY環境変数が存在しないのでproxy処理を通らない)。

残念ながら本日(7/23 14:00JST)時点では以下PRはElixir1.13.2(我が家の環境)のCICDがパスしていないようなので、パスしたらキャッシュを消して、空のHTTP_PROXY環境変数設定して試してみたいと思います。

おしまい。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2