VirtualPhotonics / Vts.Scripting.Python

Jupyter notebooks to call the VTS using Python
Other
0 stars 1 forks source link

alternate notebook implementation #5

Closed scottprahl closed 5 months ago

scottprahl commented 5 months ago

This is how I needed to add all the dlls to get things to work. It also illustrates how to change tissue properties. It was not at all obvious how to do most of this stuff.

scottprahl commented 5 months ago

New version of my notebook uploaded. No rush to check this in. Let's wait to see if the nuget install vts solution works when I try it tomorrow.

lmalenfant commented 5 months ago

Sounds good! Thank you again for working on this, it's great to have someone else to work with!

scottprahl commented 5 months ago

The last update clarifies the header somewhat. Once this has been committed (along with the .svg image) then we will need to update the url to the image in the last cell. Otherwise this should be good to go.

scottprahl commented 5 months ago

Well, it seems that I did not realize quite how pull requests and forks worked.

This pull request seems to also include updates to README.md that improves language and includes all of your suggestions (except using nuget to install vts). I was intending to make these a separate pull request.

lmalenfant commented 5 months ago

@scottprahl I merged your pull request for the readme updates yesterday, did you merge these changes back in to your fork before making changes? If not you should be able to resolve the conflicts so the newer version can be merged.

We didn't have a readme yet so don't worry about overwriting anything that was there previously.

scottprahl commented 5 months ago

Conflicts addressed.

lmalenfant commented 5 months ago

I am not able to get your samples to work, I was using Jupyter Notebook as opposed to JupyterLab, I have now switched to JupyterLab also. I'm thinking there might be slight differences between Windows and Mac (like '/' in place of '\') but even with those changes, I cannot bring in the Vts.

In my sample (written for Jupyter notebooks), I copy the dlls to a folder named "libraries" at the same level as "monte_carlo" and use import os to get the file path, but that code doesn't work in the JupyterLab version.

Do you know what the differences are between Jupyter Notebook and JupyterLab?

lmalenfant commented 5 months ago

I was able to import the Vts by adding these lines before import clr:

from pythonnet import set_runtime
set_runtime("coreclr")

Now I am getting this error because plt is undefined: image

Are you using plotly? I could not get this work with either of the imports that I am using:

import plotly.graph_objects as go
import plotly.express as px

I found it, you are using pyplot, I also needed to add this line:

import matplotlib.pyplot as plt
scottprahl commented 5 months ago

Getting clr set up correctly was a nightmare for me too. I did it through setting environment variables. It looks like you’re doing it manually

Sorry!! I inadvertently deleted the line

import matplotlib.pyplot as plt 

from the start of the notebook. Just add it and things should work.

scottprahl commented 5 months ago

The differences between JupyterLab and Jupyter Notebook are getting smaller. I used Notebook for a long time because JupyterLab had many small problems. Nowdays, they both work well.

FWIW, I also ran the code (with the above import) in a python REPR shell and it worked.

lmalenfant commented 5 months ago

It works now for me too, would you be able to add pyplot and the 2 lines at the top:

from pythonnet import set_runtime
set_runtime("coreclr")

to see if it still works? If it does then we should have a working version for Mac and Windows.

I don't want to break if for you. Then we can merge this PR in also.

scottprahl commented 5 months ago

I made the changes suggested. Hope this works.