Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint and Format

on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-24.04
name: ubuntu-24.04-3.12-examples
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11' # Update to your project's version

- name: Run pre-commit hooks
uses: pre-commit/[email protected]
6 changes: 0 additions & 6 deletions .github/workflows/generic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ jobs:
pip install --upgrade pip setuptools pkg-info wheel
pip3 install torch --index-url https://download.pytorch.org/whl/cpu

- name: Black Format Check
if: ${{ matrix.OS == 'ubuntu-24.04' && matrix.PYTHON_VERSION == '3.12' && matrix.GS_BACKEND == 'cpu' && matrix.GS_ENABLE_NDARRAY == '1' }}
run: |
pip install black
black --line-length 120 --check .

- name: Install Genesis
shell: bash
run: |
Expand Down
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
repos:
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.11
hooks:
# Run the formatter.
- id: ruff-format
8 changes: 4 additions & 4 deletions examples/IPC_Solver/genesis_ipc_motion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def compute_total_linear_momentum():
rigid_v = np.asarray(rigid_v).flatten()
fem_v = np.asarray(fem_v).flatten()

print(f"\n{'='*70}")
print(f"\n{'=' * 70}")
print(f"Step {i_step:4d}: t = {i_step * dt:.3f}s")
print(f"{'-'*70}")
print(f"{'-' * 70}")
print(f"Rigid mass: {rigid_m:8.4f} kg")
print(f"Rigid vel: [{rigid_v[0]:9.5f}, {rigid_v[1]:9.5f}, {rigid_v[2]:9.5f}] m/s")
print(f"Rigid mom: [{rigid_p[0]:9.5f}, {rigid_p[1]:9.5f}, {rigid_p[2]:9.5f}] kg·m/s")
Expand Down Expand Up @@ -297,9 +297,9 @@ def compute_total_linear_momentum():

plt.tight_layout()
plt.savefig("momentum_conservation_test.png", dpi=150)
print(f"\n{'='*70}")
print(f"\n{'=' * 70}")
print("Plot saved to: momentum_conservation_test.png")
print(f"{'='*70}")
print(f"{'=' * 70}")
plt.show()


Expand Down
11 changes: 6 additions & 5 deletions examples/IPC_Solver/ipc_twist_cloth_band.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,12 @@ def main():

# Progress reporting
if frame % 100 == 0:
phase = (
"Gripping"
if total_t < grip_duration
else "Twisting" if total_t < twist_start_time + twist_duration else "Settling"
)
if total_t < grip_duration:
phase = "Gripping"
elif total_t < twist_start_time + twist_duration:
phase = "Twisting"
else:
phase = "Settling"
print(f" Frame {frame}/{total_frames} (t={total_t:.2f}s) - {phase}")


Expand Down
1 change: 0 additions & 1 deletion examples/rigid/diffik_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
parser.add_argument("-c", "--cpu", action="store_true", default=False)
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/gravity_compensation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
parser.add_argument("-c", "--cpu", action="store_true", default=False)
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/ik_duck.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
args = parser.parse_args()
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/ik_franka.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
args = parser.parse_args()
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/ik_franka_batched.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
args = parser.parse_args()
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/multi_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
args = parser.parse_args()
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/nonconvex_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
parser.add_argument("-c", "--cpu", action="store_true", default=False)
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/single_franka.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
parser.add_argument("-c", "--cpu", action="store_true", default=False)
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/suction_cup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
parser.add_argument("-c", "--cpu", action="store_true", default=False)
Expand Down
1 change: 0 additions & 1 deletion examples/rigid/terrain_height_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


def main():

parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vis", action="store_true", default=False)
parser.add_argument("-c", "--cpu", action="store_true", default=False)
Expand Down
1 change: 0 additions & 1 deletion examples/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def main():
scene.build()

for i in range(args.num_steps):

scalars = scene.sim.solvers[-1].grid.q.to_numpy().astype(np.float32) # (res, res, res, 3)
scalars[scalars < 1e-4] = 0
layer = scalars[:, res // 2, :]
Expand Down
4 changes: 2 additions & 2 deletions genesis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def init(
wave_width = max(0, min(38, wave_width))
bar_width = wave_width * 2 + 9
wave = ("┈┉" * wave_width)[:wave_width]
logger.info(f"~<╭{'─'*(bar_width)}╮>~")
logger.info(f"~<╭{'─' * (bar_width)}╮>~")
logger.info(f"~<│{wave}>~ ~~~~<Genesis>~~~~ ~<{wave}│>~")
logger.info(f"~<╰{'─'*(bar_width)}╯>~")
logger.info(f"~<╰{'─' * (bar_width)}╯>~")

# Get concrete device and backend
global device
Expand Down
4 changes: 2 additions & 2 deletions genesis/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def _repr_elem(self, elem, common_length=0):
def _repr_elem_colorized(self, elem, common_length=0):
content = self._repr_elem(elem, common_length)
idx = content.find(">")
formatted_content = f"{colors.BLUE}{formats.ITALIC}{content[:idx + 1]}{formats.RESET}{content[idx + 1:]}"
formatted_content = f"{colors.BLUE}{formats.ITALIC}{content[: idx + 1]}{formats.RESET}{content[idx + 1 :]}"
idx = formatted_content.find(":")
if idx >= 0:
formatted_content = f"{formatted_content[:idx]}{colors.GRAY}:{colors.MINT}{formatted_content[idx + 1:]}"
formatted_content = f"{formatted_content[:idx]}{colors.GRAY}:{colors.MINT}{formatted_content[idx + 1 :]}"
formatted_content += formats.RESET
return formatted_content

Expand Down
2 changes: 1 addition & 1 deletion genesis/engine/boundaries/boundaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def impose_pos(self, pos):
return pos

def __repr__(self):
return f"{brief(self)}\n" f"height : {brief(self.height)}\n" f"restitution : {brief(self.restitution)}"
return f"{brief(self)}\nheight : {brief(self.height)}\nrestitution : {brief(self.restitution)}"
2 changes: 1 addition & 1 deletion genesis/engine/couplers/ipc_coupler.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def _scale_genesis_rigid_link_masses(self, link_geoms_dict):
rigid_solver.links_info.inertial_i[link_idx] = original_inertia / 2.0

gs.logger.debug(
f" Link {link_idx}: mass {original_mass:.6f} -> {original_mass/2.0:.6f} kg, " f"inertia scaled by 0.5"
f" Link {link_idx}: mass {original_mass:.6f} -> {original_mass / 2.0:.6f} kg, inertia scaled by 0.5"
)

# After scaling inertial_mass and inertial_i, we need to recompute derived quantities:
Expand Down
2 changes: 0 additions & 2 deletions genesis/engine/couplers/legacy_coupler.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,6 @@ def kernel_pbd_rigid_solve_animate_particles_by_link(self, clamped_inv_dt: ti.f3
pdb = self.pbd_solver
for i_p, i_env in ti.ndrange(pdb._n_particles, pdb._B):
if self.particle_attach_info[i_p, i_env].link_idx >= 0:

# read link state
link_idx = self.particle_attach_info[i_p, i_env].link_idx
link_pos = links_state.pos[link_idx, i_env]
Expand Down Expand Up @@ -940,7 +939,6 @@ def preprocess(self, f):
def couple(self, f):
# MPM <-> all others
if self.mpm_solver.is_active:

self.mpm_grid_op(
f,
self.sim.cur_t,
Expand Down
3 changes: 1 addition & 2 deletions genesis/engine/couplers/sap_coupler.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ def __init__(
self._rigid_rigid_contact_type = RigidRigidContactType.NONE
else:
gs.raise_exception(
f"Invalid rigid-rigid contact type: {options.rigid_rigid_contact_type}. "
"Must be one of 'tet' or 'none'."
f"Invalid rigid-rigid contact type: {options.rigid_rigid_contact_type}. Must be one of 'tet' or 'none'."
)

self._rigid_compliant = False
Expand Down
1 change: 0 additions & 1 deletion genesis/engine/sensors/depth_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

@register_sensor(DepthCameraOptions, RaycasterSharedMetadata, RaycasterData)
class DepthCameraSensor(RaycasterSensor):

def build(self):
super().build()
batch_shape = (self._manager._sim._B,) if self._manager._sim.n_envs > 0 else ()
Expand Down
1 change: 0 additions & 1 deletion genesis/engine/sensors/raycaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class RaycasterData(NamedTuple):
@register_sensor(RaycasterOptions, RaycasterSharedMetadata, RaycasterData)
@ti.data_oriented
class RaycasterSensor(RigidSensorMixin, Sensor):

def __init__(
self,
options: RaycasterOptions,
Expand Down
1 change: 0 additions & 1 deletion genesis/engine/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ def step(self, in_backward=False):

def _step_grad(self):
for _ in range(self._substeps - 1, -1, -1):

if self.cur_substep_local == 0:
self.load_ckpt()
self._cur_substep_global -= 1
Expand Down
3 changes: 0 additions & 3 deletions genesis/engine/solvers/rigid/collider_decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ def func_contact_edge_sdf(
for i_e in range(geoms_info.edge_start[i_ga], geoms_info.edge_end[i_ga]):
cur_length = edges_info.length[i_e]
if cur_length > ga_sdf_cell_size:

i_v0 = edges_info.v0[i_e]
i_v1 = edges_info.v1[i_e]

Expand Down Expand Up @@ -891,10 +890,8 @@ def func_contact_edge_sdf(
normal_edge_1 = sdf_grad_1_a - sdf_grad_1_a.dot(vec_01) * vec_01

if normal_edge_0.dot(sdf_grad_0_b) < 0 or normal_edge_1.dot(sdf_grad_1_b) < 0:

# check if closest point is between the two points
if sdf_grad_0_b.dot(vec_01) < 0 and sdf_grad_1_b.dot(vec_01) > 0:

while cur_length > ga_sdf_cell_size:
p_mid = 0.5 * (p_0 + p_1)
if (
Expand Down
1 change: 0 additions & 1 deletion genesis/engine/solvers/rigid/constraint_solver_decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,6 @@ def func_ls_init(
rigid_global_info: array_class.RigidGlobalInfo,
static_rigid_sim_config: ti.template(),
):

n_dofs = constraint_state.search.shape[0]
n_entities = entities_info.dof_start.shape[0]
# mv and jv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ def add_collision_constraints_and_wakeup_entities(self, i_island: int, i_b: int)
@ti.func
def add_joint_limit_constraints(self, i_island: int, i_b: int):
for i_island_entity in range(self.contact_island.island_entity[i_island, i_b].n):

i_e_ = self.contact_island.island_entity[i_island, i_b].start + i_island_entity
i_e = self.contact_island.entity_id[i_e_, i_b]

Expand Down Expand Up @@ -448,7 +447,6 @@ def _func_nt_chol_factor(self, island, i_b):
for j_d in range(
ti.max(i_d + 1, self.entities_info.dof_start[j_e]), self.entities_info.dof_end[j_e]
):

dot = gs.ti_float(0.0)

for k_island_entity in range(i_island_entity + 1):
Expand All @@ -473,7 +471,6 @@ def _func_nt_chol_solve(self, island, i_b):
i_e_ = self.contact_island.island_entity[island, i_b].start + i_island_entity
i_e = self.contact_island.entity_id[i_e_, i_b]
for i_d in range(self.entities_info.dof_start[i_e], self.entities_info.dof_end[i_e]):

for j_island_entity in range(i_island_entity + 1):
j_e_ = self.contact_island.island_entity[island, i_b].start + j_island_entity
j_e = self.contact_island.entity_id[j_e_, i_b]
Expand Down Expand Up @@ -715,7 +712,6 @@ def _func_linesearch(self, island, i_b):
done = True
break
if not done:

if self.ls_it[i_b] >= self.ls_iterations:
self.ls_result[i_b] = 3
ls_slope = ti.abs(p1_deriv_0) * slopescl
Expand Down Expand Up @@ -780,7 +776,6 @@ def _func_linesearch(self, island, i_b):
res_alpha = self.candidates[4 * best_i + 0, i_b]
done = True
else:

(
b1,
p1_alpha,
Expand Down Expand Up @@ -816,7 +811,6 @@ def _func_linesearch(self, island, i_b):
done = True

if not done:

if p1_cost <= p2_cost and p1_cost < p0_cost:
self.ls_result[i_b] = 4
ls_slope = ti.abs(p1_deriv_0) * slopescl
Expand Down Expand Up @@ -958,7 +952,6 @@ def _func_update_constraint(self, island, i_b, qacc, Ma, cost):
i_e_ = self.contact_island.island_entity[island, i_b].start + i_island_entity
i_e = self.contact_island.entity_id[i_e_, i_b]
for i_d in range(self.entities_info.dof_start[i_e], self.entities_info.dof_end[i_e]):

v = (
0.5
* (Ma[i_d, i_b] - self._solver.dofs_state.force[i_d, i_b])
Expand Down
Loading