Skip to content

Commit 7cf94ef

Browse files
authored
Merge branch 'main' into feature/jacobian
2 parents dcd779d + 4a7ec67 commit 7cf94ef

File tree

22 files changed

+274
-193
lines changed

22 files changed

+274
-193
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Generic - CPU only
1+
name: Generic
22

33
on:
44
pull_request:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Linux x86 - Nvidia GPU
1+
name: Production
22

33
on:
44
# Trigger the workflow on push on the master branch, or for any pull request

.pre-commit-config.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 25.1.0 # Use the latest version or specify the version you prefer
3+
rev: 25.1.0
44
hooks:
55
- id: black
6-
args:
7-
- --line-length=120
8-
- .

examples/rigid/suction_cup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def main():
9696

9797
# add suction / weld constraint
9898
rigid = scene.sim.rigid_solver
99-
link_cube = np.array([cube.get_link("box_baselink").idx], dtype=gs.np_int)
100-
link_franka = np.array([franka.get_link("hand").idx], dtype=gs.np_int)
99+
link_cube = cube.get_link("box_baselink").idx
100+
link_franka = franka.get_link("hand").idx
101101
rigid.add_weld_constraint(link_cube, link_franka)
102102

103103
# lift

genesis/engine/entities/emitter.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def emit(
150150
positions = gu.transform_by_trans_R(
151151
positions,
152152
pos,
153-
gu.z_up_to_R(direction) @ gu.axis_angle_to_R(np.array([0, 0, 1]), theta),
153+
gu.z_up_to_R(direction) @ gu.axis_angle_to_R(np.array([0.0, 0.0, 1.0], dtype=gs.np_float), theta),
154154
).astype(gs.np_float)
155155

156156
positions = np.tile(positions[np.newaxis], (self._sim._B, 1, 1))
@@ -206,17 +206,21 @@ def emit_omni(self, source_radius=0.1, pos=(0.5, 0.5, 1.0), speed=1.0, particle_
206206
Parameters:
207207
----------
208208
source_radius: float, optional
209-
The radius of the sphere source. Particles will be emitted from a shell with inner radius using 0.8 * source_radius and outer radius using source_radius.
209+
The radius of the sphere source. Particles will be emitted from a shell with inner radius using
210+
'0.8 * source_radius' and outer radius using source_radius.
210211
pos: array_like, shape=(3,)
211212
The center of the sphere source.
212213
speed: float
213214
The speed of the emitted particles.
214215
particle_size: float | None
215-
The size (diameter) of the emitted particles. The actual number of particles emitted is determined by the volume of the sphere source and the size of the particles. If None, the solver's particle size is used. Note that this particle size only affects computation for number of particles emitted, not the actual size of the particles in simulation and rendering.
216+
The size (diameter) of the emitted particles. The actual number of particles emitted is determined by the
217+
volume of the sphere source and the size of the particles. If None, the solver's particle size is used.
218+
Note that this particle size only affects computation for number of particles emitted, not the actual size
219+
of the particles in simulation and rendering.
216220
"""
217221
assert self._entity is not None
218222

219-
pos = np.array(pos)
223+
pos = np.asarray(pos, dtype=gs.np_float)
220224

221225
if particle_size is None:
222226
particle_size = self._solver.particle_size
@@ -227,20 +231,20 @@ def emit_omni(self, source_radius=0.1, pos=(0.5, 0.5, 1.0), speed=1.0, particle_
227231
inner_radius=source_radius * 0.4,
228232
sampler=self._entity.sampler,
229233
)
230-
231-
positions = gu.transform_by_T(positions_, gu.trans_to_T(pos)).astype(gs.np_float)
234+
positions = pos + positions_
232235

233236
if not self._solver.boundary.is_inside(positions):
234237
gs.raise_exception("Emitted particles are outside the boundary.")
235238

236-
n_particles = len(positions)
237-
dists = np.linalg.norm(positions_, axis=1, keepdims=True)
238-
positions[np.where(dists < gs.EPS)[0]] = np.array([gs.EPS, gs.EPS, gs.EPS])
239-
vels = (positions_ / dists * speed).astype(gs.np_float)
239+
dists = np.linalg.norm(positions_, axis=1)
240+
positions[dists < gs.EPS] = gs.EPS
241+
vels = (speed / (dists + gs.EPS)) * positions_
240242

243+
n_particles = len(positions)
241244
if n_particles > self._entity.n_particles:
242245
gs.logger.warning(
243-
f"Number of particles to emit ({n_particles}) at the current step is larger than the maximum number of particles ({self._entity.n_particles})."
246+
f"Number of particles to emit ({n_particles}) at the current step is larger than the maximum number "
247+
f"of particles ({self._entity.n_particles})."
244248
)
245249

246250
self._solver._kernel_set_particles_pos(

genesis/engine/entities/mpm_entity.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,9 @@ def set_pos(self, f, pos):
8989
f : int
9090
The current substep index.
9191
pos : gs.Tensor
92-
A tensor of shape (n_particles, 3) representing particle positions.
92+
A tensor of shape (n_envs, n_particles, 3) representing particle positions.
9393
"""
94-
self.solver._kernel_set_particles_pos(
95-
f,
96-
self._particle_start,
97-
self._n_particles,
98-
pos,
99-
)
94+
self.solver._kernel_set_particles_pos(f, self._particle_start, self._n_particles, pos)
10095

10196
def set_pos_grad(self, f, pos_grad):
10297
"""

genesis/engine/entities/rigid_entity/rigid_link.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,24 @@ def __init__(
5555
self._entity_idx_in_solver = entity.idx
5656

5757
self._uid = gs.UID()
58-
self._idx = idx
59-
self._parent_idx = parent_idx
60-
self._root_idx = root_idx
61-
self._child_idxs = list()
62-
self._invweight = invweight
63-
64-
self._joint_start = joint_start
65-
self._n_joints = n_joints
66-
67-
self._geom_start = geom_start
68-
self._cell_start = cell_start
69-
self._vert_start = vert_start
70-
self._face_start = face_start
71-
self._edge_start = edge_start
72-
self._verts_state_start = verts_state_start
73-
self._vgeom_start = vgeom_start
74-
self._vvert_start = vvert_start
75-
self._vface_start = vface_start
58+
self._idx: int = idx
59+
self._parent_idx: int = parent_idx # -1 if no parent
60+
self._root_idx: int | None = root_idx # None if no root
61+
self._child_idxs: list[int] = list()
62+
self._invweight: float | None = invweight
63+
64+
self._joint_start: int = joint_start
65+
self._n_joints: int = n_joints
66+
67+
self._geom_start: int = geom_start
68+
self._cell_start: int = cell_start
69+
self._vert_start: int = vert_start
70+
self._face_start: int = face_start
71+
self._edge_start: int = edge_start
72+
self._verts_state_start: int = verts_state_start
73+
self._vgeom_start: int = vgeom_start
74+
self._vvert_start: int = vvert_start
75+
self._vface_start: int = vface_start
7676

7777
# Link position & rotation at creation time:
7878
self._pos: ArrayLike = pos

genesis/engine/entities/sph_entity.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ def set_pos(self, f, pos):
9292
pos : ndarray
9393
Array of particle positions of shape (n_envs, n_particles, 3).
9494
"""
95-
self.solver._kernel_set_particles_pos(
96-
f,
97-
self._particle_start,
98-
self._n_particles,
99-
pos,
100-
)
95+
self.solver._kernel_set_particles_pos(f, self._particle_start, self._n_particles, pos)
10196

10297
def set_pos_grad(self, f: ti.i32, pos_grad: ti.types.ndarray()):
10398
"""

genesis/engine/solvers/mpm_solver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,9 @@ def _kernel_set_particles_pos(
720720
self.particles[f, i_global, i_b].pos[k] = pos[i_b, i_p, k]
721721

722722
# we restore these whenever directly setting positions
723-
self.particles[f, i_global, i_b].vel = ti.Vector.zero(gs.ti_float, 3)
723+
self.particles[f, i_global, i_b].vel.fill(0.0)
724724
self.particles[f, i_global, i_b].F = ti.Matrix.identity(gs.ti_float, 3)
725-
self.particles[f, i_global, i_b].C = ti.Matrix.zero(gs.ti_float, 3, 3)
725+
self.particles[f, i_global, i_b].C.fill(0.0)
726726
self.particles[f, i_global, i_b].Jp = self.particles_info[i_global].default_Jp
727727

728728
@ti.kernel

genesis/engine/solvers/pbd_solver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,8 @@ def _kernel_set_particles_pos(
840840
for i_p, i_b in ti.ndrange(n_particles, self._B):
841841
i_global = i_p + particle_start
842842
for k in ti.static(range(3)):
843-
self.particles[i_global, i_b].pos[k] = pos[i_p, k]
844-
self.particles[i_global, i_b].vel = ti.Vector.zero(gs.ti_float, 3)
843+
self.particles[i_global, i_b].pos[k] = pos[i_b, i_p, k]
844+
self.particles[i_global, i_b].vel.fill(0.0)
845845

846846
@ti.kernel
847847
def _kernel_set_particles_vel(

0 commit comments

Comments
 (0)