Skip to content

Commit

Permalink
fix(jupyter): more support
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Jul 21, 2022
1 parent 5bfd076 commit c8450dc
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DS_Store
node_modules
.venv*

.ipynb_checkpoints

# local env files
.env.local
Expand Down
31 changes: 31 additions & 0 deletions documentation/jupyter/README-osx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Running ParaView within Jupyter

### Install packages

```bash
python3.9 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install pv-visualizer
pip install jupyterlab
```

### Run example

```bash
export PYTHONPATH=/Applications/ParaView-5.10.1.app/Contents/Python
export DYLD_LIBRARY_PATH=/Applications/ParaView-5.10.1.app/Contents/Libraries
source .venv/bin/activate
jupyter-lab
```

Then in a cell

```python
from pv_visualizer.app.jupyter import show
show()
```

## Running Jupyter within ParaView

This path is not yet working.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "97651108-21d4-48dc-a322-4af0b0c8790a",
"metadata": {},
"source": [
"Only run next cell to get the ENV variable to set before starting Jupyterlab after having defined TRAME_PARAVIEW=/ParaView.app/"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "383795b4-4603-4732-90a8-d2f2edbf5537",
"metadata": {},
"outputs": [],
"source": [
"import trame.env.paraview"
]
},
{
"cell_type": "markdown",
"id": "e9d1072c-9326-48f1-bdab-26fe3331c658",
"metadata": {},
"source": [
"Just run the following section once you've exported __PYTHONPATH__ and __DYLD_LIBRARY_PATH__ for mac"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ae9f4e67-b4ab-4ea0-98e1-6c4958957b06",
"metadata": {},
"outputs": [],
"source": [
"from pv_visualizer.app.jupyter import show\n",
"\n",
"show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file added documentation/jupyter/example/pv-in-jupyter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions documentation/jupyter/example/test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "97651108-21d4-48dc-a322-4af0b0c8790a",
"metadata": {},
"source": [
"Only run next cell to get the ENV variable to set before starting Jupyterlab after having defined TRAME_PARAVIEW=/ParaView.app/"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "383795b4-4603-4732-90a8-d2f2edbf5537",
"metadata": {},
"outputs": [],
"source": [
"import trame.env.paraview"
]
},
{
"cell_type": "markdown",
"id": "e9d1072c-9326-48f1-bdab-26fe3331c658",
"metadata": {},
"source": [
"Just run the following section once you've exported __PYTHONPATH__ and __DYLD_LIBRARY_PATH__ for mac"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ae9f4e67-b4ab-4ea0-98e1-6c4958957b06",
"metadata": {},
"outputs": [],
"source": [
"from pv_visualizer.app.jupyter import show\n",
"\n",
"show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
14 changes: 7 additions & 7 deletions pv_visualizer/app/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
r"""
Define your classes and create the instances that you need to expose
"""
import logging
from .reactions import register_reactions
from .proxymanager import ParaviewProxyManager
from paraview import simple

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# ---------------------------------------------------------
# Methods
# ---------------------------------------------------------


def initialize(server):
args, _ = server.cli.parse_known_args()
#
def initialize(server, plugins=None):
pxm = ParaviewProxyManager()
pxm.set_server(server)

plugins = args.plugins.split(",") if args.plugins else []
if plugins:
print("\nLoading ParaView plugins:")
logger.info("\nLoading ParaView plugins:")
for plugin in plugins:
print(f" - {plugin}")
logger.info(f" - {plugin}")
simple.LoadDistributedPlugin(plugin)
print()

# Bind methods to controller + trigger name
register_reactions(server)
14 changes: 9 additions & 5 deletions pv_visualizer/app/engine/proxymanager/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import logging
from pathlib import Path

from trame.app.singleton import Singleton
Expand All @@ -15,6 +16,9 @@

PENDING = True

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# -----------------------------------------------------------------------------
# PV <=> Simput proxy state exchange
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -80,7 +84,7 @@ def fetch(simput_proxy):
pv_property = paraview.unwrap(pv_proxy.GetProperty(name))

if pv_property is None:
# print(f"No property {name} for proxy {pv_proxy.GetXMLName()}")
# logger.info(f"No property {name} for proxy {pv_proxy.GetXMLName()}")
continue

# Custom handling for proxy
Expand Down Expand Up @@ -108,7 +112,7 @@ def fetch(simput_proxy):
else:
value = pv_property.GetElement(0)

# print(f"{property_class}({size})::{name} = {value} ({type(value)})")
# logger.info(f"{property_class}({size})::{name} = {value} ({type(value)})")
simput_proxy.set_property(name, value)

simput_proxy.commit()
Expand Down Expand Up @@ -148,14 +152,14 @@ def update(simput_proxy, *property_names):
@staticmethod
def before_delete(simput_proxy):
pv_proxy = simput_proxy.object
print(
logger.info(
"Deleting PV proxy",
simput_proxy.id,
pv_proxy.GetGlobalIDAsString(),
pv_proxy.GetReferenceCount(),
)
simple.Delete(pv_proxy)
print("simple.Delete() => done", pv_proxy.GetReferenceCount())
logger.info("simple.Delete() => done", pv_proxy.GetReferenceCount())


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -345,7 +349,7 @@ def _proxy_extract_sub(
for i in range(size):
s_proxy = prop.GetProxy(i)
if s_proxy is not None:
# print("add sub proxy", s_proxy.GetClassName())
# logger.info("add sub proxy", s_proxy.GetClassName())
list_to_fill.append(s_proxy)

return list_to_fill
Expand Down
6 changes: 5 additions & 1 deletion pv_visualizer/app/engine/proxymanager/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
./Qt/ApplicationComponents/pqSpreadSheetViewDecorator.cxx
./Qt/ApplicationComponents/pqAnimationShortcutDecorator.cxx
"""
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


class AdvancedDecorator:
Expand Down Expand Up @@ -406,4 +410,4 @@ def get_decorator(proxy, config):
if _type in globals():
return globals()[_type](proxy, config)

print(f"~~~ no decorator for {_type} ~~~")
logger.info(f"~~~ no decorator for {_type} ~~~")
11 changes: 7 additions & 4 deletions pv_visualizer/app/engine/proxymanager/definitions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import yaml
import json
import base64
Expand All @@ -8,6 +9,8 @@

from paraview import servermanager

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# -----------------------------------------------------------------------------
# Spec key
Expand Down Expand Up @@ -184,7 +187,7 @@ def property_yaml(property):
# currently simput don't properly manage list of proxy as property...
# i.e. views.RenderView.Representations
if property_definition["type"] == "proxy" and size != 1:
print(
logger.info(
"Skip multi-proxy property",
property.GetParent().GetXMLName(),
property.GetXMLName(),
Expand Down Expand Up @@ -246,12 +249,12 @@ def should_skip(property):
# return True

if property.GetIsInternal():
# print("skip internal")
# logger.info("skip internal")
return True

visibility = property.GetPanelVisibility()
if visibility in ["never"]:
# print("skip visibility", visibility)
# logger.info("skip visibility", visibility)
return True

if property.IsA("vtkSMProxyProperty"):
Expand Down Expand Up @@ -357,7 +360,7 @@ def proxy_ui(proxy):
# Skip custom widget until they get implemented
if domains.PANEL_WIDGETS.get(group.GetPanelWidget()) == "skip":
group_key = "skip"
# print(f"> Skip {group.GetPanelWidget()}")
# logger.info(f"> Skip {group.GetPanelWidget()}")

# Create group
xml_group = xml_groups.get(group_key)
Expand Down
6 changes: 5 additions & 1 deletion pv_visualizer/app/engine/proxymanager/domain_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import sys
from . import paraview
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# -----------------------------------------------------------------------------
# General util functions
Expand Down Expand Up @@ -153,6 +157,6 @@ def domain_unknown(domain):

if class_name not in UNKNOWN_DOMAINS:
UNKNOWN_DOMAINS.add(class_name)
print("domain_unknown::class", class_name)
logger.info("domain_unknown::class", class_name)

return {}
Loading

0 comments on commit c8450dc

Please sign in to comment.