Skip to content

Instantly share code, notes, and snippets.

View richardrl's full-sized avatar
🦧
Focusing

richardrl

🦧
Focusing
View GitHub Profile
if args.enable_torques:
print("ASSUMING THE WITNESS POINTS ARE DEFINED WITH RESPECT TO THE CENTER OF MASS!!! CHANGE BODY FRAME ORIGIN IF THIS IS NOT TRUE")
# for each contact point, setup the product of binary-continuous for w*b
# sum all the torques for a single object
# setup obj-obj first
for i in range(config.num_internal_bodies):
net_torque_to_object_i = np.zeros(3)
for j in range(config.num_internal_bodies):
net_torque_to_i_from_j = np.zeros(3)
@richardrl
richardrl / occupy-memory.py
Created July 2, 2022 23:47 — forked from sparkydogX/occupy-memory.py
Pytorch trick : occupy all GPU memory in advance
import os
import torch
from tqdm import tqdm
import time
# declare which gpu device to use
cuda_device = '0'
def check_mem(cuda_device):
devices_info = os.popen('"/usr/bin/nvidia-smi" --query-gpu=memory.total,memory.used --format=csv,nounits,noheader').read().strip().split("\n")
@richardrl
richardrl / headless.py
Created June 7, 2022 20:45 — forked from mikedh/headless.py
Manual pyglet event loop headless rendering
import pyglet
import pyglet.gl as gl
import numpy as np
import os
import tempfile
import subprocess
import collections

Preamble

There is a longstanding issue/missing feature/bug with sockets on Docker on macOS; it may never work; you'll need to use a network connection between Docker containers and X11 on macOS for the foreseeable future.

I started from this gist and made some adjustments:

  • the volume mappings aren't relevant/used, due to the socket issue above.
  • this method only allows X11 connections from your Mac, not the entire local network, which would include everyone on the café/airport WiFi.
  • updated to include using the host.docker.internal name for the the container host, instead.
  • you have to restart XQuartz after the config change.
@richardrl
richardrl / multiprocess_with_instance_methods.py
Created February 14, 2022 02:48 — forked from bnyeggen/multiprocess_with_instance_methods.py
Example showing how to use instance methods with the multiprocessing module
from multiprocessing import Pool
from functools import partial
def _pickle_method(method):
func_name = method.im_func.__name__
obj = method.im_self
cls = method.im_class
if func_name.startswith('__') and not func_name.endswith('__'): #deal with mangled names
cls_name = cls.__name__.lstrip('_')
func_name = '_' + cls_name + func_name
@richardrl
richardrl / multiprocessing with instance method
Created February 14, 2022 02:47 — forked from somma/multiprocessing with instance method
Code illustrates how to pass instance method to multiprocessing and use functools.partial with pool.map() method.
#!/usr/bin/python
# -*- coding:utf-8 -*-
"""
Idea and code was taken from stackoverflow().
This sample illustrates how to
+ how to pass method of instance method
to multiprocessing(idea and code was introduced
at http://goo.gl/tRHN1D by torek).
from graphviz import Digraph
import torch
from torch.autograd import Variable, Function
def iter_graph(root, callback):
queue = [root]
seen = set()
while queue:
fn = queue.pop()
if fn in seen:
import open3d
import numpy as np
def main():
vis = open3d.visualization.Visualizer()
vis.create_window("Pose Visualizer")
vis.get_render_option().line_width = 10.0
obb = open3d.geometry.OrientedBoundingBox(center=np.array([0.0,0.0,0.0]), R=np.eye(3), extent=np.array([1.0, 1.0, 1.0]))
block_gripper_contacts = list(filter(lambda contact: (contact.geom1 == right_gripperid or contact.geom1 == left_gripperid) and contact.geom2 == blockid, self.sim.data.contact))
block_gripper_distances = [contact.dist for contact in block_gripper_contacts]
if len(block_gripper_distances) > 0:
collisions += np.any(np.array(block_gripper_distances) <= 0)