|
1 |
| -Jupyter notebooks to call the VTS using Python |
| 1 | +# Using VTS in a Jupyter notebook |
| 2 | + |
| 3 | +This is likely to change once `python` scripting is formally supported by `VTS`. |
| 4 | + |
| 5 | +## macOS installation details |
| 6 | + |
| 7 | +This is a record of how I got `vts` working in `JupyterLab`. |
| 8 | + |
| 9 | +### Step 1: Install .NET 6 |
| 10 | + |
| 11 | +You will need version 6 of .NET which is available from Microsoft below |
| 12 | + |
| 13 | +https://dotnet.microsoft.com/en-us/download/dotnet/6.0 |
| 14 | + |
| 15 | +I saved everything to `$HOME/Documents/Code/dotnet6` |
| 16 | + |
| 17 | +Do not forget to update your `~/.bash_profile` or whatever you use so that this directory is in your path. Also define `DOTNET_ROOT` |
| 18 | + |
| 19 | + PATH=$PATH:$HOME/Documents/Code/dotnet6 |
| 20 | + |
| 21 | + export DOTNET_ROOT=$HOME/Documents/Code/dotnet6 |
| 22 | + |
| 23 | +### Step 2: Install VTS |
| 24 | + |
| 25 | +Follow the guidelines at https://github.com/VirtualPhotonics/VTS/wiki/Getting-Started-on-Mac Briefly, clone the `.git` repo |
| 26 | + |
| 27 | + git clone https://github.com/VirtualPhotonics/vts.git |
| 28 | + |
| 29 | +This will create the directory `vts` that is needed for the next step |
| 30 | + |
| 31 | +Install both `powershell` and `nuget` using [Homebrew](https://brew.sh) |
| 32 | + |
| 33 | + brew install powershell |
| 34 | + brew install nuget |
| 35 | + |
| 36 | +Now build VTS. If you don't have `matlab` don't worry, it seemed to work fine without completing the `matlab` tests |
| 37 | + |
| 38 | + pwsh |
| 39 | + cd vts |
| 40 | + ./BuildTestRelease.ps1 |
| 41 | + exit |
| 42 | + |
| 43 | +### Step 3: Install pythonnet |
| 44 | + |
| 45 | + pip install pythonnet |
| 46 | + |
| 47 | +Because `pythonnet` under macOS (or linux) defaults to `mono`, two more things need to added to `~/.bash_profile` |
| 48 | + |
| 49 | + export PYTHONNET_RUNTIME=coreclr |
| 50 | + export PYTHONNET_PYDLL=/usr/local/bin/python3 |
| 51 | + |
| 52 | +Obviously use the path for python on your system (`which python3` will tell you) |
| 53 | + |
| 54 | +Next start a `JupyterLab` notebook to verify that things are installed correctly |
| 55 | + |
| 56 | + import clr |
| 57 | + |
| 58 | + clr.AddReference("System") |
| 59 | + from System import Console |
| 60 | + Console.WriteLine("Hello from .NET 6!") |
| 61 | + |
| 62 | +The final test is importing from `Vts.dll` |
| 63 | + |
| 64 | + import clr |
| 65 | + clr.AddReference("/path/to/vts/src/Vts/publish/local/Vts.dll") |
| 66 | + from Vts import * |
| 67 | + |
| 68 | +where, of course, "/path/to" above has been adapted to your system |
| 69 | + |
| 70 | +### Step 4: Run programs |
| 71 | + |
| 72 | +To run `VTS` programs in `python` include the following the header |
| 73 | + |
| 74 | + import clr |
| 75 | + clr.AddReference("/path/to/vts/src/Vts/publish/local/Vts.dll") |
| 76 | + |
| 77 | + from Vts import * |
| 78 | + from Vts.Common import * |
| 79 | + from Vts.Extensions import * |
| 80 | + from Vts.Modeling.Optimizers import * |
| 81 | + from Vts.Modeling.ForwardSolvers import * |
| 82 | + from Vts.Factories import * |
| 83 | + from Vts.MonteCarlo import * |
| 84 | + from Vts.MonteCarlo.Sources import * |
| 85 | + from Vts.MonteCarlo.Tissues import * |
| 86 | + from Vts.MonteCarlo.Detectors import * |
| 87 | + from Vts.MonteCarlo.Factories import * |
| 88 | + from Vts.MonteCarlo.PhotonData import * |
| 89 | + from Vts.MonteCarlo.PostProcessing import * |
| 90 | + from System import Array, Double |
0 commit comments