Skip to content

Commit c552908

Browse files
committed
Changes in demos to accomodate colab
1 parent 4046298 commit c552908

3 files changed

Lines changed: 38 additions & 28 deletions

File tree

notebooks/demo.ipynb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
},
1313
{
1414
"cell_type": "code",
15-
"execution_count": 2,
15+
"execution_count": null,
16+
"id": "93482e50",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from google.colab import output\n",
21+
"output.enable_custom_widget_manager()"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
1627
"id": "973e71b6",
1728
"metadata": {},
1829
"outputs": [
@@ -4430,29 +4441,24 @@
44304441
"from nbody_sim.api import Simulation, ureg\n",
44314442
"from nbody_sim.render import create_plotly_animation\n",
44324443
"\n",
4433-
"print(\"Initializing N-Body Physics Engine...\")\n",
4444+
"print(\"Initializing n-body physics engine\")\n",
44344445
"sim = Simulation()\n",
44354446
"\n",
4436-
"# 1. Generate 500 procedural asteroids\n",
44374447
"np.random.seed(42)\n",
44384448
"n_bodies = 500\n",
44394449
"\n",
4440-
"# Using your Pint unit registry for strict physical definitions\n",
44414450
"positions = np.random.uniform(-5.0, 5.0, (n_bodies, 3)) * ureg.astronomical_unit\n",
44424451
"velocities = np.random.uniform(-0.5, 0.5, (n_bodies, 3)) * (ureg.astronomical_unit / ureg.nbody_time)\n",
44434452
"masses = np.random.uniform(0.1, 2.0, n_bodies) * ureg.solar_mass\n",
44444453
"\n",
4445-
"# Add them to the Barnes-Hut tree\n",
44464454
"sim.add_bodies(positions, velocities, masses)\n",
44474455
"\n",
4448-
"# Generate procedural colours (RGBA floats) and sizes for the renderer\n",
44494456
"colours = np.random.uniform(0.4, 1.0, (n_bodies, 4))\n",
44504457
"colours[:, 3] = 1.0 # Set full opacity\n",
44514458
"sizes = np.random.uniform(0.5, 2.0, n_bodies)\n",
44524459
"\n",
4453-
"print(\"Baking 3D WebGL animation. Please wait...\")\n",
4460+
"print(\"Preparing animation\")\n",
44544461
"\n",
4455-
"# 2. Render the interactive K3D plot\n",
44564462
"plot = create_plotly_animation(\n",
44574463
" sim,\n",
44584464
" dt=0.01,\n",
@@ -4461,7 +4467,6 @@
44614467
" steps=150\n",
44624468
")\n",
44634469
"\n",
4464-
"# Display the widget!\n",
44654470
"plot.show()"
44664471
]
44674472
}

notebooks/demo2.ipynb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
"!pip install --pre --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ \"nbody-sim-RO[vis]==1.0.4.dev0\""
3030
]
3131
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"id": "e0a76d28",
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"from google.colab import output\n",
40+
"output.enable_custom_widget_manager()"
41+
]
42+
},
3243
{
3344
"cell_type": "code",
3445
"execution_count": null,
@@ -71,29 +82,24 @@
7182
"from nbody_sim.api import Simulation, ureg\n",
7283
"from nbody_sim.render import create_k3d_animation\n",
7384
"\n",
74-
"print(\"Initializing N-Body Physics Engine...\")\n",
85+
"print(\"Initializing n-body physics engine\")\n",
7586
"sim = Simulation()\n",
7687
"\n",
77-
"# 1. Generate 500 procedural asteroids\n",
7888
"np.random.seed(42)\n",
7989
"n_bodies = 500\n",
8090
"\n",
81-
"# Using your Pint unit registry for strict physical definitions\n",
8291
"positions = np.random.uniform(-5.0, 5.0, (n_bodies, 3)) * ureg.astronomical_unit\n",
8392
"velocities = np.random.uniform(-0.5, 0.5, (n_bodies, 3)) * (ureg.astronomical_unit / ureg.nbody_time)\n",
8493
"masses = np.random.uniform(0.1, 2.0, n_bodies) * ureg.solar_mass\n",
8594
"\n",
86-
"# Add them to the Barnes-Hut tree\n",
8795
"sim.add_bodies(positions, velocities, masses)\n",
8896
"\n",
89-
"# Generate procedural colours (RGBA floats) and sizes for the renderer\n",
9097
"colours = np.random.uniform(0.4, 1.0, (n_bodies, 4))\n",
9198
"colours[:, 3] = 1.0 # Set full opacity\n",
9299
"sizes = np.random.uniform(0.5, 2.0, n_bodies)\n",
93100
"\n",
94-
"print(\"Baking 3D WebGL animation. Please wait...\")\n",
101+
"print(\"Preparing animation\")\n",
95102
"\n",
96-
"# 2. Render the interactive K3D plot\n",
97103
"plot = create_k3d_animation(\n",
98104
" sim,\n",
99105
" dt=0.01,\n",
@@ -102,7 +108,6 @@
102108
" steps=150\n",
103109
")\n",
104110
"\n",
105-
"# Display the widget!\n",
106111
"plot.display()"
107112
]
108113
}

pyproject.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ authors = [
1313
{name = "orzel320", email = "orzellll320@gmail.com"}
1414
]
1515
dependencies = [
16-
"numpy>=1.22.0",
17-
"numba>=0.57.0",
18-
"pint>=0.22"
16+
"numpy",
17+
"numba",
18+
"pint"
1919
]
2020

2121
[project.optional-dependencies]
2222
vis = [
23-
"matplotlib>=3.10.8",
24-
"ipympl>=0.9.3",
25-
"k3d>=2.16.0",
26-
"jupyter>=1.1.1"
23+
"matplotlib",
24+
"ipympl",
25+
"k3d",
26+
"jupyter"
2727
]
2828

2929
test = [
30-
"pytest>=9.0.3",
31-
"pytest-cov>=7.1.0"
30+
"pytest",
31+
"pytest-cov"
3232
]
3333

3434
docs = [
35-
"mkdocs>=1.6.1",
36-
"mkdocs-material>=9.7.6"
35+
"mkdocs",
36+
"mkdocs-material"
3737
]
3838

3939
dev = [

0 commit comments

Comments
 (0)