english translation started
This commit is contained in:
@@ -2,7 +2,18 @@
|
||||
engine: julia
|
||||
---
|
||||
|
||||
# Arbeit mit Julia: REPL, Pakete, Introspection
|
||||
```{julia}
|
||||
#| error: false
|
||||
#| echo: false
|
||||
#| output: false
|
||||
using InteractiveUtils
|
||||
import QuartoNotebookWorker
|
||||
Base.stdout = QuartoNotebookWorker.with_context(stdout)
|
||||
myactive_module() = Main.Notebook
|
||||
Base.active_module() = myactive_module()
|
||||
```
|
||||
|
||||
# Working with Julia: REPL, Packages, Introspection
|
||||
|
||||
```{julia}
|
||||
#| error: false
|
||||
@@ -17,37 +28,36 @@ Base.active_module() = myactive_module()
|
||||
# https://github.com/JuliaLang/julia/blob/master/base/show.jl#L3073-L3077
|
||||
```
|
||||
|
||||
## Dokumentation
|
||||
## Documentation
|
||||
|
||||
Die offizielle Julia-Dokumentation [https://docs.julialang.org/](https://docs.julialang.org/) enthält zahlreiche Übersichten, darunter:
|
||||
|
||||
- [https://docs.julialang.org/en/v1/base/punctuation/](https://docs.julialang.org/en/v1/base/punctuation/) Verzeichnis der Symbole
|
||||
- [https://docs.julialang.org/en/v1/manual/unicode-input/](https://docs.julialang.org/en/v1/manual/unicode-input/) Verzeichnis spezieller Unicode-Symbole und deren Eingabe in Julia via Tab-Vervollständigung
|
||||
- [https://docs.julialang.org/en/v1/manual/mathematical-operations/#Rounding-functions](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Rounding-functions) Liste mathematischer Funktionen
|
||||
The official Julia documentation [https://docs.julialang.org/](https://docs.julialang.org/) contains numerous overviews, including:
|
||||
|
||||
- [https://docs.julialang.org/en/v1/base/punctuation/](https://docs.julialang.org/en/v1/base/punctuation/) List of symbols
|
||||
- [https://docs.julialang.org/en/v1/manual/unicode-input/](https://docs.julialang.org/en/v1/manual/unicode-input/) List of special Unicode symbols and their input methods via tab completion in Julia
|
||||
- [https://docs.julialang.org/en/v1/manual/mathematical-operations/#Rounding-functions](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Rounding-functions) List of mathematical functions
|
||||
|
||||
|
||||
|
||||
## Julia REPL (Read - Eval - Print - Loop)
|
||||
|
||||
Nach dem Start von Julia in einem Terminal kann man neben Julia-Code auch verschiedene Kommandos eingeben
|
||||
After starting Julia in a terminal, you can enter both Julia code and various commands:
|
||||
|
||||
:::{.narrow}
|
||||
| Kommando | Wirkung |
|
||||
| Command | Effect |
|
||||
| :----------------------------| :------------------------ |
|
||||
| `exit()` oder `Ctrl-d` | exit Julia |
|
||||
| `exit()` or `Ctrl-d` | exit Julia |
|
||||
| `Ctrl-c` | interrupt |
|
||||
| `Ctrl-l` | clear screen |
|
||||
| Kommando mit `;` beenden | Ausgabe unterdrückt |
|
||||
| `include("filename.jl")` | Datei mit Julia-Code einlesen und ausführen |
|
||||
| End command with `;` | suppress output |
|
||||
| `include("filename.jl")` | read and execute file with Julia code |
|
||||
|
||||
|
||||
|
||||
The REPL has several modes:
|
||||
|
||||
Der REPL hat verschiedene Modi:
|
||||
|
||||
| Modus | Prompt | Modus starten | Modus verlassen |
|
||||
| Mode | Prompt | Start mode | Exit mode |
|
||||
| :- | :- | :- | :- |
|
||||
| default| `julia>` | | `Ctrl-d` (beendet Julia) |
|
||||
| default| `julia>` | | `Ctrl-d` (exits Julia) |
|
||||
| Package manager | `pkg>` | `]` | `backspace` |
|
||||
| Help | `help?>` | `?`| `backspace `|
|
||||
|Shell | `shell>` | `;` | `backspace`|
|
||||
@@ -55,12 +65,12 @@ Der REPL hat verschiedene Modi:
|
||||
:::
|
||||
|
||||
|
||||
## Jupyter-Notebooks (IJulia)
|
||||
## Jupyter Notebooks (IJulia)
|
||||
|
||||
|
||||
In einem Jupyter-Notebook sind die Modi sind als Einzeiler in einer eigenen Input-Zelle nutzbar:
|
||||
In a Jupyter notebook, the modes are usable as single-line commands in their own input cells:
|
||||
|
||||
(i) ein Kommando des Paket-Managers:
|
||||
(i) a package manager command:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -68,7 +78,7 @@ In einem Jupyter-Notebook sind die Modi sind als Einzeiler in einer eigenen Inpu
|
||||
] status
|
||||
```
|
||||
|
||||
(ii) eine Help-Abfrage:
|
||||
(ii) a help query:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -76,7 +86,7 @@ In einem Jupyter-Notebook sind die Modi sind als Einzeiler in einer eigenen Inpu
|
||||
?sin
|
||||
```
|
||||
|
||||
(iii) Ein Shell-Kommando:
|
||||
(iii) a shell command:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -84,33 +94,33 @@ In einem Jupyter-Notebook sind die Modi sind als Einzeiler in einer eigenen Inpu
|
||||
;ls
|
||||
```
|
||||
|
||||
## Der Paketmanager
|
||||
## The Package Manager
|
||||
|
||||
Wichtiger Teil des _Julia Ecosystems_ sind die zahlreichen Pakete, die Julia erweitern.
|
||||
An important part of the _Julia ecosystem_ is the numerous packages that extend Julia.
|
||||
|
||||
- Einige Pakete sind Teil jeder Julia-Installation und müssen nur mit einer `using Paketname`-Anweisung aktiviert werden.
|
||||
- Sie bilden die sogenannte _Standard Library_ und dazu gehören
|
||||
- `LinearAlgebra`, `Statistics`, `SparseArrays`, `Printf`, `Pkg` und andere.
|
||||
- Über 9000 Pakete sind offiziell registriert, siehe [https://julialang.org/packages/](https://julialang.org/packages/).
|
||||
- Diese können mit wenigen Tastendrücken heruntergeladen und installiert werden.
|
||||
- Dazu dient der _package manager_ `Pkg`.
|
||||
- Man kann ihn auf zwei Arten verwenden:
|
||||
- als normale Julia-Anweisungen, die auch in einer `.jl`-Programmdatei stehen können:
|
||||
- Some packages are part of every Julia installation and only need to be activated with a `using Packagename` statement.
|
||||
- They form the so-called _standard library_, which includes
|
||||
- `LinearAlgebra`, `Statistics`, `SparseArrays`, `Printf`, `Pkg`, and others.
|
||||
- Over 9000 packages are officially registered, see [https://julialang.org/packages/](https://julialang.org/packages/).
|
||||
- These can be downloaded and installed with just a few keystrokes.
|
||||
- The _package manager_ `Pkg` is used for this purpose.
|
||||
- It can be used in two ways:
|
||||
- as normal Julia statements that can also be in a `.jl` program file:
|
||||
```
|
||||
using Pkg
|
||||
Pkg.add("PaketXY")
|
||||
Pkg.add("PackageXY")
|
||||
```
|
||||
- im speziellen pkg-Modus des Julia-REPLs:
|
||||
- in the special pkg-mode of the Julia REPL:
|
||||
```
|
||||
] add PaketXY
|
||||
] add PackageXY
|
||||
```
|
||||
- Anschließend kann das Paket mit `using PaketXY` verwendet werden.
|
||||
- Man kann auch Pakete aus anderen Quellen und selbstgeschriebene Pakete installieren.
|
||||
- Afterward, the package can be used with `using PackageXY`.
|
||||
- You can also install packages from other sources and self-written packages.
|
||||
|
||||
|
||||
### Einige Funktionen des Paketmanagers
|
||||
|
||||
### Some Package Manager Functions
|
||||
|
||||
| Funktion | `pkg` - Mode | Erklärung |
|
||||
| Function | `pkg` - Mode | Explanation |
|
||||
|:------------------------|:--------------------------| :-------------------------------------------------------|
|
||||
| `Pkg.add("MyPack")` | `pkg> add MyPack` | add `MyPack.jl` to current environment |
|
||||
| `Pkg.rm("MyPack")` | `pkg> remove MyPack` | remove `MyPack.jl` from current environment |
|
||||
@@ -120,13 +130,13 @@ Wichtiger Teil des _Julia Ecosystems_ sind die zahlreichen Pakete, die Julia erw
|
||||
| `Pkg.instantiate()` | `pg> instantiate` | install all packages according to `Project.toml` |
|
||||
|
||||
|
||||
### Installierte Pakete und Environments
|
||||
### Installed Packages and Environments
|
||||
|
||||
- Julia und der Paketmanager verwalten
|
||||
1. eine Liste der mit dem Kommando `Pkg.add()` bzw. `]add` explizit installierten Pakete mit genauer Versionsbezeichnung in einer Datei `Project.toml` und
|
||||
2. eine Liste aller dabei auch als implizite Abhängigkeiten installierten Pakete in der Datei `Manifest.toml`.
|
||||
- Das Verzeichnis, in dem diese Dateien stehen, ist das `environment` und wird mit `Pkg.status()` bzw. `]status` angezeigt.
|
||||
- Im Normalfall sieht das so aus:
|
||||
- Julia and the package manager maintain
|
||||
1. a list of packages explicitly installed with the command `Pkg.add()` or `]add` with exact version specifications in a file `Project.toml` and
|
||||
2. a list of all packages installed as implicit dependencies in the file `Manifest.toml`.
|
||||
- The directory in which these files are located is the `environment` and is displayed with `Pkg.status()` or `]status`.
|
||||
- In the normal case, this looks like this:
|
||||
|
||||
```
|
||||
(@v1.10) pkg> status
|
||||
@@ -137,18 +147,18 @@ Wichtiger Teil des _Julia Ecosystems_ sind die zahlreichen Pakete, die Julia erw
|
||||
[295af30f] Revise v3.5.14
|
||||
```
|
||||
|
||||
- Man kann für verschiedene Projekte eigene `environments` benutzen. Dazu kann man entweder Julia mit
|
||||
- You can use separate `environments` for different projects. You can either start Julia with
|
||||
```shell
|
||||
julia --project=path/to/myproject
|
||||
```
|
||||
starten oder in Julia das environment mit `Pkg.activate("path/to/myproject")` aktivieren. Dann werden `Project.toml, Manifest.toml` dort angelegt und verwaltet. (Die Installation der Paketdateien erfolgt weiterhin irgendwo unter `$HOME/.julia`)
|
||||
or activate the environment in Julia with `Pkg.activate("path/to/myproject")`. Then `Project.toml, Manifest.toml` are created and managed there. (The installation of package files still takes place somewhere under `$HOME/.julia`)
|
||||
|
||||
|
||||
### Zum Installieren von Paketen auf unserem Jupyter-Server `misun103`:
|
||||
### For Installing Packages on Our Jupyter Server `misun103`:
|
||||
|
||||
- Es gibt ein zentrales Repository, in dem alle in diesem Kurs erwähnten Pakete bereits installiert sind.
|
||||
- Dort haben Sie keine Schreibrechte.
|
||||
- Sie können aber zusätzliche Pakete in Ihrem `HOME` installieren. Dazu ist als erster Befehl nötig, das aktuelle Verzeichnis zu aktivieren:
|
||||
- There is a central repository in which all packages mentioned in this course are already installed.
|
||||
- There you have no write permissions.
|
||||
- However, you can install additional packages in your `HOME`. As a first command, you need to activate the current directory:
|
||||
|
||||
|
||||
```{julia}
|
||||
@@ -156,26 +166,27 @@ starten oder in Julia das environment mit `Pkg.activate("path/to/myproject")` ak
|
||||
] activate .
|
||||
```
|
||||
|
||||
(Man beachte den Punkt!)
|
||||
(Note the dot!)
|
||||
|
||||
|
||||
Danach können Sie mit `add` im Pkg-Modus auch Pakete installieren:
|
||||
|
||||
|
||||
After that, you can install packages with `add` in the pkg-mode:
|
||||
|
||||
```{julia}
|
||||
#| eval: false
|
||||
] add PaketXY
|
||||
] add PackageXY
|
||||
```
|
||||
|
||||
|
||||
Achtung! Das kann dauern! Viele Pakete haben komplexe Abhängigkeiten und lösen die Installation von weiteren Paketen aus. Viele Pakete werden beim Installieren vorkompiliert. Im REPL sieht man den Installationsfortschritt, im Jupyter-Notebook leider nicht.
|
||||
Warning! This can take a long time! Many packages have complex dependencies and trigger the installation of further packages. Many packages are precompiled during installation. You can see the installation progress in the REPL, but unfortunately not in the Jupyter notebook.
|
||||
|
||||
|
||||
|
||||
|
||||
## The Julia JIT _(just in time)_ Compiler: Introspection
|
||||
|
||||
## Der Julia JIT _(just in time)_ Compiler: Introspection
|
||||
|
||||
Julia baut auf die Werkzeuge des _LLVM Compiler Infrastructure Projects_ auf.
|
||||
Julia is built on the tools of the _LLVM Compiler Infrastructure Project_.
|
||||
|
||||
:::{.narrow}
|
||||
Stages of Compilation
|
||||
@@ -235,5 +246,3 @@ walk_tree(p)
|
||||
```{julia}
|
||||
@code_native f(2,4)
|
||||
```
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user