1
- # Jupyter notebooks to call the VTS using Python
1
+ # Using VTS in a Jupyter notebook
2
2
3
3
This is likely to change once ` python ` scripting is formally supported by ` VTS ` .
4
4
5
- ## Getting things working on a Mac
5
+ ## macOS installation details
6
6
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 ` .
8
8
9
9
### Step 1: Install .NET 6
10
10
@@ -14,7 +14,7 @@ https://dotnet.microsoft.com/en-us/download/dotnet/6.0
14
14
15
15
I saved everything to ` $HOME/Documents/Code/dotnet6 `
16
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 `
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
18
19
19
PATH=$PATH:$HOME/Documents/Code/dotnet6
20
20
@@ -26,9 +26,9 @@ Follow the guidelines at https://github.com/VirtualPhotonics/VTS/wiki/Getting-St
26
26
27
27
git clone https://github.com/VirtualPhotonics/vts.git
28
28
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
30
30
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 )
32
32
33
33
brew install powershell
34
34
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
39
39
cd vts
40
40
./BuildTestRelease.ps1
41
41
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
63
42
64
- ### Step 4 : Install pythonnet
43
+ ### Step 3 : Install pythonnet
65
44
66
45
pip install pythonnet
67
46
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`
69
48
70
49
export PYTHONNET_RUNTIME=coreclr
71
50
export PYTHONNET_PYDLL=/usr/local/bin/python3
72
51
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 )
74
53
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
76
55
77
56
import clr
78
57
79
58
clr.AddReference("System")
80
59
from System import Console
81
60
Console.WriteLine("Hello from .NET 6!")
82
61
83
- Once this works the next step will be to add the ` Vts.dll `
62
+ The final test is importing from ` Vts.dll `
84
63
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 *
90
67
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
92
69
93
- clr.AddReference("Newtonsoft.Json")
94
- clr.AddReference("Mathnet.Numerics")
95
- clr.AddReference("NLog")
96
- clr.AddReference("System.Reactive");
70
+ ### Step 4: Run programs
97
71
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
99
73
100
- import sys
101
- dll_directory = "/path/to/vts/src/Vts/bin/Release/net6.0"
102
- sys.path.append(dll_directory)
103
-
104
74
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")
110
76
111
77
from Vts import *
112
78
from Vts.Common import *
@@ -121,6 +87,4 @@ And now you should be able to run `VTS` programs in `python` with the header
121
87
from Vts.MonteCarlo.Factories import *
122
88
from Vts.MonteCarlo.PhotonData import *
123
89
from Vts.MonteCarlo.PostProcessing import *
124
- from System import Array, Double
125
-
126
-
90
+ from System import Array, Double
0 commit comments