Skip to content

Commit

Permalink
fix(julia-version): обновлена версия Julia до 1.10
Browse files Browse the repository at this point in the history
modified:   Dockerfile
  Установка с juliaup.

modified:   book/**/*.md
  Обновлены версии ядра для исполнения кода.

new file:   book/change-kernel.py
  Скрипт для обновления ядер исполнения кода.

new file:   julia-requirements-exact-for-reference.txt
new file:   python-requirements-exact-for-reference.txt
  Снэпшоты точных версий пакетов Python и Julia для сборки книги.

Closes #78
  • Loading branch information
stepanzh committed Aug 4, 2024
1 parent 2552837 commit f20822c
Show file tree
Hide file tree
Showing 30 changed files with 289 additions and 98 deletions.
25 changes: 12 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,30 @@ RUN <<EOF
apt update

# python 3 and wget
apt install -y python3 wget
apt install -y python3 curl

# pip
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
rm get-pip.py
curl -fsSL https://bootstrap.pypa.io/get-pip.py | python3

# Python packages
pip install -r python-requirements.txt

# Julia 1.9.4
wget https://julialang-s3.julialang.org/bin/linux/x64/1.9/julia-1.9.4-linux-x86_64.tar.gz
tar zxvf julia-1.9.4-linux-x86_64.tar.gz
rm julia-1.9.4-linux-x86_64.tar.gz
mv julia-1.9.4 /usr/local/bin/
## доступ к julia внутри контейнера по `julia`
ln -s /usr/local/bin/julia-1.9.4/bin/julia /usr/local/bin/julia

# Julia 1.10+
## Juliaup
curl -fsSL https://install.julialang.org | sh -s -- --yes --default-channel 1.10
## Экспорт команд julia и juliaup
. ~/.bashrc
# Julia пакеты из Project.toml

## Инициализация глобального окружения julia (/root/.julia директория).
julia -e "using Pkg; Pkg.instantiate()"
## Проставляем глобальное окружение Julia в контейнере.
## Не оставляйте `/root/Project.toml`!!! Иначе jupyter-book будет ссылаться на него, а не глобальное окружение.
cp julia-requirements.toml /root/.julia/environments/v1.9/Project.toml
## Не оставляйте `/root/Project.toml`!!! Иначе jupyter-book будет (неявно) ссылаться на него, а не на глобальное окружение.
## Именно с этой целью файл с зависимостями Julia назван julia-requirements.toml, а не Project.toml.

cp julia-requirements.toml ~/.julia/environments/v1.10/Project.toml

## Грузим и устанавливаем пакеты, перечисленные в Project.toml.
julia -e "using Pkg; Pkg.resolve(); Pkg.instantiate(); Pkg.precompile()"

Expand Down
6 changes: 3 additions & 3 deletions book/autodiff/compgraph.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/autodiff/complexstep.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
7 changes: 4 additions & 3 deletions book/autodiff/dualnumbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down Expand Up @@ -237,6 +237,7 @@ f'(x) = \log{x^2} + 2, \quad x \neq 0,

```{code-cell}
:tags: [remove-output]
f(x) = 3 + x * log(x^2)
df(x) = log(x^2) + 2
```
Expand Down
94 changes: 94 additions & 0 deletions book/change-kernel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Обновление julia kernel для MyST файлов.
# Скрипт итерируется по файлам книге, отыскивая Markdown файлы с заголовком от MyST.
#
# ПРЕДУПРЕЖДЕНИЕ
# ПЕРЕД ЗАПУСКОМ ПРОВЕРЬТЕ ПЕРЕМЕННЫЕ JUPYTER_KERNELSPEC_FOR_JULIA и BOOK_LOCATION_INSIDE_CONTAINER.
#
# Подразумевается, что должен менять эту часть файла
# ---
# jupytext:
# formats: md:myst
# text_representation:
# extension: .md
# format_name: myst
# format_version: 0.13 --> (автоматически)
# jupytext_version: 1.16.4 --> (автоматически)
# kernelspec:
# display_name: Julia 1.10.4 --> (автоматически)
# language: julia
# name: julia-1.10 --> JUPYTER_KERNELSPEC_FOR_JULIA
# ---
#
# Степан Захаров [email protected]
# 2024


import os
import subprocess

# Название ядра jupyter, созданного IJulia
JUPYTER_KERNELSPEC_FOR_JULIA = 'julia-1.10'
BOOK_LOCATION_INSIDE_CONTAINER = '/root/book/'


def show_container_warning():
print('Обнаружен запуск из-под пользовательской машины')
print('Запустите этот скрипт из docker-контейнера')




# Проверка на то, что скрипт исполняется в контейнере

# Пытаемся прочесть содержание /run/systemd/container
# На моём компе в контейнере прописано 'docker'
_container_file = '/run/systemd/container'
if not os.path.exists(_container_file):
show_container_warning()
exit(1)

_container_file_content = ''
with open(_container_file) as io:
_container_file_content = io.read()

if not _container_file_content.startswith('docker'):
show_container_warning()
exit(1)




root = BOOK_LOCATION_INSIDE_CONTAINER
files_for_update = []

# Фильтруем файлы с расширением .md и содержащие jupytext
# настройки для исполнения кода
for (dirpath, dirnames, filenames) in os.walk(root):
for filename in filenames:
filepath = os.path.join(dirpath, filename)
_, suffix = os.path.splitext(filepath)

if suffix != '.md':
continue

with open(filepath) as io:
content = io.read()
if content.startswith('---\njupytext'):
files_for_update.append(filepath)


print('Следующие файлы будут обновлены')
for x in files_for_update:
print('', x)

# Здесь полагаемся на встроенную утилиту jupyter-book myst init.

for x in files_for_update:
subprocess.run([
'jupyter-book',
'myst',
'init',
'--kernel',
JUPYTER_KERNELSPEC_FOR_JULIA,
x,
])
6 changes: 3 additions & 3 deletions book/integration/adaptive.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/integration/newton_cotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/interpolation/cubic_spline.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
10 changes: 3 additions & 7 deletions book/interpolation/ex.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
myst:
substitutions:
url_omega22_table: "<a href=\"https://raw.githubusercontent.com/stepanzh/computational_thermodynamics/main/book/static/golubev1971_omega22.pdf\" target=\"_blank\">pdf</a>"
url_feta_table: "<a href=\"https://raw.githubusercontent.com/stepanzh/computational_thermodynamics/main/book/static/golubev1971_feta.pdf\" target=\"_blank\">pdf</a>"
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/interpolation/polynomial.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/interpolation/pwlinear.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/intro/cond.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/intro/float.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
9 changes: 3 additions & 6 deletions book/julia/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
myst:
substitutions:
julia_logo: "<img src=\"https://raw.githubusercontent.com/JuliaLang/julia-logo-graphics/master/images/julia-dots.svg\" style=\"height: 1em;\">"
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/nlroot/bisection_regula_falsi.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{code-cell}
Expand Down
6 changes: 3 additions & 3 deletions book/nlroot/ex.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/nlroot/itp.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
6 changes: 3 additions & 3 deletions book/nlroot/newton_secant.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.0
jupytext_version: 1.16.4
kernelspec:
display_name: Julia 1.9.4
display_name: Julia 1.10.4
language: julia
name: julia-1.9
name: julia-1.10
---

```{eval-rst}
Expand Down
Loading

0 comments on commit f20822c

Please sign in to comment.