Skip to content

Commit

Permalink
skip mesh export CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ryichando committed Jan 5, 2025
1 parent 4edd8d3 commit 6a61f78
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cancel_all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

gh run list --json status,workflowName,databaseId --jq '.[] | select(.status=="in_progress")' |
gh run list --json status,workflowName,databaseId --jq '.[] | select(.status=="in_progress" or .status=="queued")' |
while read -r run; do
id=$(echo "$run" | jq -r '.databaseId')
workflow_name=$(echo "$run" | jq -r '.workflowName')
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vast/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ elif [ "$ARG" = "build" ]; then
$SSH "cd ppf-contact-solver && /root/.cargo/bin/cargo build --release"
elif [ "$ARG" = "convert" ]; then
$SSH "cd ppf-contact-solver/examples && jupyter nbconvert --to script *.ipynb"
$SSH "touch /root/ppf-contact-solver/examples/.CLI"
$SSH "touch /root/ppf-contact-solver/frontend/.CI"
elif [ "$ARG" = "run" ]; then
EXAMPLE=$2
$SSH "PYTHONPATH=/root/ppf-contact-solver python3 ppf-contact-solver/examples/$EXAMPLE"
Expand Down
3 changes: 2 additions & 1 deletion examples/cards.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
}
],
Expand Down
6 changes: 4 additions & 2 deletions examples/curtain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
},
{
Expand Down Expand Up @@ -161,7 +162,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
}
],
Expand Down
3 changes: 2 additions & 1 deletion examples/drape.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
},
{
Expand Down
12 changes: 12 additions & 0 deletions examples/friction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
"# this is for CI\n",
"assert session_051.finished()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b6528c86-0218-4ea9-98ec-033ba1a28f17",
"metadata": {},
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"if not app.CI:\n",
" session_051.export.animation(f\"export/{scene.info.name}/{session_051.info.name}\").zip()"
]
}
],
"metadata": {
Expand Down
66 changes: 64 additions & 2 deletions examples/hang.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"outputs": [],
"source": [
"# export all simulated frames\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
},
{
Expand Down Expand Up @@ -133,7 +134,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
},
{
Expand All @@ -146,6 +148,66 @@
"# this is for CI\n",
"assert session.finished()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0cd13835-e4ed-4d1a-a661-3c98a62a628e",
"metadata": {},
"outputs": [],
"source": [
"# create a new scene\n",
"scene = app.scene.create(\"pinch-sheet\")\n",
"\n",
"# pinch two points inward\n",
"move_dist, strength = 0.95, 1e4\n",
"sheet = scene.add(\"sheet\").direction([1, 0, 0], [0, 1, 0])\n",
"sheet.pin(sheet.grab([-1, 1, 0])).pull(strength).move_by([move_dist, 0, 0], 1)\n",
"sheet.pin(sheet.grab([1, 1, 0])).pull(strength).move_by([-move_dist, 0, 0], 1)\n",
"\n",
"# clear dynamic gravity\n",
"param.clear(\"gravity\").set(\"frames\", 100)\n",
"\n",
"# build this scene and start simulation\n",
"fixed = scene.build()\n",
"session = app.session.create(fixed)\n",
"session.start(param).preview()\n",
"session.stream()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5edd10c0-706b-46d5-bf60-c3a1834afee8",
"metadata": {},
"outputs": [],
"source": [
"# run this cell after sufficnt frames are simulated\n",
"session.animate()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3926406c-016c-44ad-91ed-09816c1fabfc",
"metadata": {},
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "98284b82-774b-4fd5-be0e-7968fc24b8ba",
"metadata": {},
"outputs": [],
"source": [
"# this is for CI\n",
"assert session.finished()"
]
}
],
"metadata": {
Expand Down
9 changes: 5 additions & 4 deletions examples/needle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
"V, F = app.mesh.square(res=129)\n",
"app.asset.add.tri(\"sheet\", V, F)\n",
"\n",
"V, F = app.mesh.cone(height=5, Nr=24, Ny=24, Nb=8, radius=1)\n",
"V, F = app.mesh.cone(height=5, Nr=40, Ny=64, Nb=12, radius=1)\n",
"app.asset.add.tri(\"cone\", V, F)\n",
"\n",
"V, F, T = app.mesh.icosphere(r=0.25, subdiv_count=4).tetrahedralize()\n",
"app.asset.add.tet(\"sphere\", V, F, T)\n",
"\n",
"scene = app.scene.create(\"needle-sphere\")\n",
"scene.add(\"cone\").scale(0.2).rotate(90, \"x\").at(0, -0.25, 0).jitter().pin()\n",
"scene.add(\"sphere\").at(0, 1, 0).jitter().pull_pin().hold(1.0).unpin()\n",
"scene.add(\"sphere\").at(0, 1, 0).jitter().pin().pull().hold(1.0).unpin()\n",
"\n",
"n, space = 5, 0.05\n",
"for i in range(n):\n",
Expand All @@ -44,7 +44,7 @@
"source": [
"session = app.session.create(fixed)\n",
"param = app.session.param()\n",
"param.set(\"frames\", 180)\n",
"param.set(\"frames\", 120)\n",
"param.set(\"area-density\", 1e3).set(\"volume-density\", 1e5)\n",
"\n",
"session.start(param).preview()\n",
Expand Down Expand Up @@ -81,7 +81,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
}
],
Expand Down
3 changes: 2 additions & 1 deletion examples/stack.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
}
],
Expand Down
3 changes: 2 additions & 1 deletion examples/trampoline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
}
],
Expand Down
3 changes: 2 additions & 1 deletion examples/trapped.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
}
],
Expand Down
12 changes: 12 additions & 0 deletions examples/twist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
"# this is for CI\n",
"assert session.finished()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14add6cd-d224-497e-881c-888ca731c72b",
"metadata": {},
"outputs": [],
"source": [
"# export all simulated frames and make a zip file\n",
"if not app.CI:\n",
" session.export.animation(f\"export/{scene.info.name}/{session.info.name}\").zip()"
]
}
],
"metadata": {
Expand Down
2 changes: 2 additions & 0 deletions frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"SessionGet",
"CppRustDocStringParser",
"Param",
"Utils",
]

from ._app_ import App
Expand Down Expand Up @@ -66,3 +67,4 @@
Param,
)
from ._parse_ import CppRustDocStringParser
from ._utils_ import Utils
10 changes: 10 additions & 0 deletions frontend/_app_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ._mesh_ import MeshManager
from ._session_ import SessionManager, Param
from ._plot_ import PlotManager
from ._utils_ import Utils
import pickle
import os
import shutil
Expand Down Expand Up @@ -95,6 +96,15 @@ def __init__(self, name: str, renew: bool, cache_dir: str = ""):
self._scene = SceneManager(self._plot, self.asset, self.save)
self.mesh = MeshManager(self.cache_dir) #: MeshManager: The mesh manager.

@property
def CI(self) -> bool:
"""Determine if the code is running in a CI environment.
Returns:
bool: True if the code is running in a CI environment, False otherwise.
"""
return Utils.in_CI()

@property
def plot(self) -> PlotManager:
"""Get the plot manager.
Expand Down
4 changes: 3 additions & 1 deletion frontend/_mesh_.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def cone(
Nb: int = 4,
radius: float = 0.5,
height: float = 2,
sharpen: float = 1.0,
) -> "TriMesh":
"""Create a cone mesh with a given number of radial, vertical, and bottom resolution, radius, and height.
Expand All @@ -231,6 +232,7 @@ def cone(
Nb (int): number of bottom resolution
radius (float): radius of the cone
height (float): height of the cone
sharpen (float): sharpening subdivision factor at the top
Returns:
TriMesh: a cone mesh, a pair of vertices and triangles
Expand All @@ -245,7 +247,7 @@ def cone(
for k in reversed(range(Ny)):
if k > 0:
r = k / (Ny - 1)
r = r * r
r = r**sharpen
offset.append(len(V))
for i in range(Nr):
t = 2 * np.pi * i / Nr
Expand Down
27 changes: 4 additions & 23 deletions frontend/_plot_.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# License: Apache v2.0

from meshplot import plot
import os
from meshplot.Viewer import Viewer
from frontend._utils_ import Utils
import pythreejs as p3s
import numpy as np
from IPython.display import display
Expand All @@ -29,32 +29,13 @@
}


def in_jupyter_notebook():
"""Determine if the code is running in a Jupyter notebook."""
dirpath = os.path.dirname(os.path.abspath(__file__))
if os.path.exists(os.path.join(dirpath, ".CLI")):
return False
try:
from IPython import get_ipython # type: ignore

shell = get_ipython().__class__.__name__
if shell == "ZMQInteractiveShell":
return True
elif shell == "TerminalInteractiveShell":
return False
else:
return False
except (NameError, ImportError):
return False


class PlotManager:
"""PlotManager class. Use this to create a plot."""

def __init__(self) -> None:
"""Initialize the plot manager."""
self._darkmode = True
self._in_jupyter_notebook = in_jupyter_notebook()
self._in_jupyter_notebook = Utils.in_jupyter_notebook()

def darkmode(self, darkmode: bool) -> None:
"""Turn on or off dark mode.
Expand All @@ -79,7 +60,7 @@ class PlotAdder:
def __init__(self, parent: "Plot") -> None:
"""Initialize the plot adder."""
self._parent = parent
self._in_jupyter_notebook = in_jupyter_notebook()
self._in_jupyter_notebook = Utils.in_jupyter_notebook()

def tri(self, vert: np.ndarray, tri: np.ndarray, color: np.ndarray) -> "Plot":
"""Add a triangle mesh to the plot.
Expand Down Expand Up @@ -170,7 +151,7 @@ def __init__(self, _darkmode: bool):
Args:
_darkmode (bool): True to turn on dark mode, False otherwise.
"""
self._in_jupyter_notebook = in_jupyter_notebook()
self._in_jupyter_notebook = Utils.in_jupyter_notebook()
self._darkmode = _darkmode
self._viewer = None
self._shading = {}
Expand Down
Loading

0 comments on commit 6a61f78

Please sign in to comment.