Skip to content

Commit

Permalink
Merge pull request #780 from StanfordVL/torch
Browse files Browse the repository at this point in the history
NumPy -> Torch
  • Loading branch information
hang-yin authored Aug 21, 2024
2 parents f448668 + 06abaeb commit bbb17d3
Show file tree
Hide file tree
Showing 178 changed files with 4,475 additions and 3,286 deletions.
151 changes: 101 additions & 50 deletions .github/workflows/examples-as-test.yml
Original file line number Diff line number Diff line change
@@ -1,81 +1,132 @@
name: Examples as Test
name: Examples as Tests

on:
schedule:
# * is a special character in YAML so you have to quote this string
# Format: minute hour day-of-month month day-of-week(starts on sunday)
# Scheduled for 2 am, every sunday, tuesday, friday
- cron: '0 10 * * 0,2,5'
# Scheduled for 2 am, everyday
- cron: '0 10 * * *'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
test:
runs-on: [self-hosted, linux, gpu]
if: github.repository == 'StanfordVL/OmniGibson-dev'

generate_example_tests:
name: Generate Example Tests
runs-on: [self-hosted, linux, gpu, dataset-enabled]
defaults:
run:
shell: micromamba run -n omnigibson /bin/bash -leo pipefail {0}
steps:
- name: Checkout source
uses: actions/checkout@v2
with:
submodules: true
path: omnigibson

- name: Add CUDA to env
run: echo "/usr/local/cuda/bin" >> $GITHUB_PATH

- name: Setup python
uses: actions/setup-python@v2
with:
python-version: "3.8"
architecture: x64

path: omnigibson-src

- name: Install dev requirements
working-directory: omnigibson
working-directory: omnigibson-src
run: pip install -r requirements-dev.txt

- name: Install additional dev requirements
working-directory: omnigibson
run: pip install -r tests/requirements-tests.txt


- name: Install
working-directory: omnigibson
working-directory: omnigibson-src
run: pip install -e .

- name: Uninstall pip bddl
working-directory: omnigibson
run: pip uninstall -y bddl
- name: Generate example tests
working-directory: omnigibson-src
run: python tests/create_tests_of_examples.py

- name: Get list of generated tests
id: get-test-list
working-directory: omnigibson-src
run: |
echo "example_tests=$(cat tests/example_tests.json)" >> $GITHUB_OUTPUT
outputs:
example_tests: ${{ steps.get-test-list.outputs.example_tests }}

run_test:
name: Run Example Tests
needs: [generate_example_tests]
runs-on: [self-hosted, linux, gpu, dataset-enabled]

strategy:
matrix:
test_file:
- ${{ needs.generate_example_tests.outputs.example_tests != '' && fromJson(needs.generate_example_tests.outputs.example_tests) }}
fail-fast: true

defaults:
run:
shell: micromamba run -n omnigibson /bin/bash -leo pipefail {0}

steps:
- name: Check for generated tests
if: ${{ needs.generate_example_tests.outputs.example_tests == '' }}
run: |
echo "No tests were generated. Failing the job."
exit 1
- name: Checkout BDDL
- name: Fix home
run: echo "HOME=/root" >> $GITHUB_ENV

- name: Checkout source
uses: actions/checkout@v2
with:
repository: StanfordVL/bddl-dev
ref: 581be50e7cfd2b3a1447aaa1b4fc2424b673339c
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} # PAT is required since this is a different repo
path: bddl
submodules: recursive
lfs: true

- name: Install BDDL
working-directory: bddl
run: pip install -e .
submodules: true
path: omnigibson-src

- name: Link Dataset
working-directory: omnigibson
run: ln -s /scr/ig-data omnigibson/data
- name: Install dev requirements
working-directory: omnigibson-src
run: pip install -r requirements-dev.txt

- name: Create tests of examples
working-directory: omnigibson
run: python tests/create_tests_of_examples.py
- name: Install
working-directory: omnigibson-src
run: pip install -e .

- name: Run tests
working-directory: omnigibson
run: pytest /tmp/tests_of_examples
working-directory: omnigibson-src
run: pytest -s tests/tests_of_examples/${{ matrix.test_file }}.py --junitxml=${{ matrix.test_file }}.xml && cp ${{ matrix.test_file }}.xml ${GITHUB_WORKSPACE}/

- name: Remove Files
uses: JesseTG/[email protected]
- name: Deploy artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.run_id }}-tests-${{ matrix.test_file }}
path: ${{ matrix.test_file }}.xml

- name: Fail on failure or error
run: grep -Eq "<failure|error" ${{ matrix.test_file }}.xml; if [ $? -eq 0 ]; then exit 1; else exit 0; fi

upload_report:
name: Compile Example Test Report
runs-on: [self-hosted, linux]
defaults:
run:
shell: micromamba run -n omnigibson /bin/bash -leo pipefail {0}
needs: [run_test]
steps:
- name: Checkout source
uses: actions/checkout@v2
with:
submodules: true
path: omnigibson-src
- name: Pull reports
uses: actions/download-artifact@v3
with:
path: omnigibson-src
- name: Example Test Report0
uses: dorny/test-reporter@v1
with:
path: /tmp/tests_of_examples
name: Example Test Results
working-directory: omnigibson-src
path: ${{ github.run_id }}-tests-*/*_test.xml
reporter: java-junit
fail-on-error: 'true'
fail-on-empty: 'true'

# - name: Upload coverage to Codecov
# uses: codecov/[email protected]
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
16 changes: 13 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,30 @@ jobs:
runs-on: [self-hosted, linux, gpu, dataset-enabled]

strategy:
fail-fast: false
matrix:
test_file:
- test_dump_load_states
- test_envs
- test_multiple_envs
- test_object_removal
- test_object_states
- test_primitives
- test_robot_states_flatcache
- test_robot_states_no_flatcache
- test_robot_teleoperation
- test_scene_graph
- test_sensors
- test_symbolic_primitives
- test_systems
- test_transform_utils
- test_transition_rules

defaults:
run:
shell: micromamba run -n omnigibson /bin/bash -leo pipefail {0}

steps:
- name: Fix home
run: echo "HOME=/root" >> $GITHUB_ENV

- name: Checkout source
uses: actions/checkout@v2
with:
Expand All @@ -57,13 +58,22 @@ jobs:
- name: Run tests
working-directory: omnigibson-src
run: pytest -s tests/${{ matrix.test_file }}.py --junitxml=${{ matrix.test_file }}.xml && cp ${{ matrix.test_file }}.xml ${GITHUB_WORKSPACE}/
continue-on-error: true

- name: Deploy artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.run_id }}-tests-${{ matrix.test_file }}
path: ${{ matrix.test_file }}.xml

- name: Check for failures or errors
run: |
if grep -Eq 'failures="[1-9][0-9]*"|errors="[1-9][0-9]*"' ${{ matrix.test_file }}.xml; then
exit 1
else
exit 0
fi
upload_report:
name: Compile Report
runs-on: [self-hosted, linux]
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,7 @@ coverage.xml

# Doc
docs/reference
site/
site/

# Tests of examples
tests/tests_of_examples
18 changes: 17 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@ repos:
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
name: isort (python)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: no-commit-to-branch
name: Check for numpy imports
entry: git grep -l "import numpy"
language: system
types: [python]
exclude: |
(?x)^(
\.pre-commit-config\.yaml|
omnigibson/utils/deprecated_utils\.py| # Keep Numpy import for deprecated Omniverse utils
omnigibson/utils/numpy_utils\.py| # Utilities specifically for numpy operations and dtype
tests/test_transform_utils\.py # This test file uses Scipy and Numpy
)$
stages: [commit]
5 changes: 3 additions & 2 deletions docs/tutorials/custom_robot_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ Now that we have the USD file for the robot, let's write our own robot class. Fo
??? code "stretch.py"
``` python linenums="1"
import os
import numpy as np
import math
import torch as th
from omnigibson.macros import gm
from omnigibson.robots.active_camera_robot import ActiveCameraRobot
from omnigibson.robots.manipulation_robot import GraspingPoint, ManipulationRobot
Expand Down Expand Up @@ -157,7 +158,7 @@ Now that we have the USD file for the robot, let's write our own robot class. Fo
def _default_joint_pos(self):
# Define the default joint positions for your robot

return np.array([0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0.0, 0, 0, np.pi / 8, np.pi / 8])
return th.tensor([0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0.0, 0, 0, math.pi / 8, math.pi / 8]. dtype=th.float32)

@property
def wheel_radius(self):
Expand Down
Loading

0 comments on commit bbb17d3

Please sign in to comment.