1- # Jupyter notebooks to call the VTS using Python
1+ # Using VTS in a Jupyter notebook
22
33This is likely to change once ` python ` scripting is formally supported by ` VTS ` .
44
5- ## Getting things working on a Mac
5+ ## macOS installation details
66
7- I did not have a .NET installation and do most things from the command line. This is a record of how I got ` vts ` working in ` JupyterLab ` .
7+ This is a record of how I got ` vts ` working in ` JupyterLab ` .
88
99### Step 1: Install .NET 6
1010
@@ -14,7 +14,7 @@ https://dotnet.microsoft.com/en-us/download/dotnet/6.0
1414
1515I saved everything to ` $HOME/Documents/Code/dotnet6 `
1616
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 `
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 `
1818
1919 PATH=$PATH:$HOME/Documents/Code/dotnet6
2020
@@ -26,9 +26,9 @@ Follow the guidelines at https://github.com/VirtualPhotonics/VTS/wiki/Getting-St
2626
2727 git clone https://github.com/VirtualPhotonics/vts.git
2828
29- This will create the director ` vts ` that we will use in the next step
29+ This will create the directory ` vts ` that is needed for the next step
3030
31- When you are using ` brew ` you might as well install ` nuget ` at the same time
31+ Install both ` powershell ` and ` nuget ` using [ Homebrew ] ( https://brew.sh )
3232
3333 brew install powershell
3434 brew install nuget
@@ -39,74 +39,40 @@ Now build VTS. If you don't have `matlab` don't worry, it seemed to work fine w
3939 cd vts
4040 ./BuildTestRelease.ps1
4141 exit
42-
43- ### Step 3: Install .NET dlls
44-
45- Navigate to the release version of vts.dll
46-
47- cd vts/src/Vts/bin/Release/net6.0
48-
49- Now use ` nuget ` to install the extra required libraries
50-
51- nuget install MathNet.Numerics.dll
52- nuget install Newtonsoft.Json.dll
53- nuget install Nlog.dll
54- nuget install System.Reactive.dll
55-
56- rummage through all the folders and move the net6.0 ` *.dll ` to ` vts/src/Vts/bin/Release/net6.0 ` . Doing ` ls ` in this directory should show
57-
58- MathNet.Numerics.dll
59- Newtonsoft.Json.dll
60- Nlog.dll
61- System.Reactive.dll
62- Vts.dll
6342
64- ### Step 4 : Install pythonnet
43+ ### Step 3 : Install pythonnet
6544
6645 pip install pythonnet
6746
68- Now because ` pythonnet ` assumes that you're using ` mono ` and not ` .NET ` , we need to update a few more things in .bash_profile
47+ Because ` pythonnet ` under macOS (or linux) defaults to ` mono ` , two more things need to added to ` ~/ .bash_profile`
6948
7049 export PYTHONNET_RUNTIME=coreclr
7150 export PYTHONNET_PYDLL=/usr/local/bin/python3
7251
73- Change the path for python to that for your system (try ` which python3 ` if you don't know )
52+ Obviously use the path for python on your system (` which python3 ` will tell you )
7453
75- Start a ` JupyterLab ` notebook and verify that things are installed correctly
54+ Next start a ` JupyterLab ` notebook to verify that things are installed correctly
7655
7756 import clr
7857
7958 clr.AddReference("System")
8059 from System import Console
8160 Console.WriteLine("Hello from .NET 6!")
8261
83- Once this works the next step will be to add the ` Vts.dll `
62+ The final test is importing from ` Vts.dll `
8463
85- import sys
86-
87- dll_directory = "/path/to/vts/src/Vts/bin/Release/net6.0"
88- sys.path.append(dll_directory)
89- clr.AddReference("Vts")
64+ import clr
65+ clr.AddReference("/path/to/vts/src/Vts/publish/local/Vts.dll")
66+ from Vts import *
9067
91- Once this is working, verify that the other dlls you downloaded load properly
68+ where, of course, "/path/to" above has been adapted to your system
9269
93- clr.AddReference("Newtonsoft.Json")
94- clr.AddReference("Mathnet.Numerics")
95- clr.AddReference("NLog")
96- clr.AddReference("System.Reactive");
70+ ### Step 4: Run programs
9771
98- And now you should be able to run ` VTS ` programs in ` python ` with the header
72+ To run ` VTS ` programs in ` python ` include the following the header
9973
100- import sys
101- dll_directory = "/path/to/vts/src/Vts/bin/Release/net6.0"
102- sys.path.append(dll_directory)
103-
10474 import clr
105- clr.AddReference("Vts")
106- clr.AddReference("Newtonsoft.Json")
107- clr.AddReference("Mathnet.Numerics")
108- clr.AddReference("NLog")
109- clr.AddReference("System.Reactive")
75+ clr.AddReference("/path/to/vts/src/Vts/publish/local/Vts.dll")
11076
11177 from Vts import *
11278 from Vts.Common import *
@@ -121,6 +87,4 @@ And now you should be able to run `VTS` programs in `python` with the header
12187 from Vts.MonteCarlo.Factories import *
12288 from Vts.MonteCarlo.PhotonData import *
12389 from Vts.MonteCarlo.PostProcessing import *
124- from System import Array, Double
125-
126-
90+ from System import Array, Double
0 commit comments