-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logging for h5 #119
Merged
Merged
Add logging for h5 #119
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
762b12f
add krec saving
alik-git 19c1cf4
update h5 logging to use HDF5Logger, same as sim2sim.py
alik-git 4752353
add parallel envs and handle saving for h5
alik-git 9780d6e
add parallel env saving for krec as well
alik-git 8bb1f9a
remove plotting and remove onnx export
alik-git f3b7b34
update logic
budzianowski 2216adf
Merge branch 'master' of github.com:kscalelabs/sim into data_gen_and_…
budzianowski 8aab407
add script to compare h5 files from mujoco vs isaac to ensure consist…
alik-git 38a464b
update numpy requirement to <2.0.0
alik-git 9137d88
change pillow req to > 6.2.0
alik-git 76a9c65
scipy version > 1.10.0
alik-git f1cbc9e
lint
alik-git c78f3f7
organise imports
alik-git c6237e9
Merge branch 'master' into data_gen_and_krec
alik-git File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
""" | ||
Compare two HDF5 files and analyze their differences. | ||
|
||
Usage: | ||
python compare_h5.py --isaac-file path/to/isaac.h5 --mujoco-file path/to/mujoco.h5 | ||
|
||
Example: | ||
python sim/compare_h5.py \ | ||
--isaac-file runs/h5_out/stompypro/2024-12-02_20-04-51/env_0/stompypro_env_0/h5_out/2024-12-02_20-04-51__053b2b5b-21c9-497c-b637-b66935dfe475.h5 \ | ||
--mujoco-file sim/resources/stompypro/h5_out/2024-12-02_21-10-41__5820ade7-9fc0-46df-8469-2f305480bcae.h5 | ||
|
||
python sim/compare_h5.py \ | ||
--isaac-file runs/h5_out/stompypro/2024-12-02_20-04-51/env_1/stompypro_env_1/h5_out/2024-12-02_20-04-51__d2016a6f-a486-4e86-8c5e-c9addd2cc13e.h5 \ | ||
--mujoco-file sim/resources/stompypro/h5_out/2024-12-02_21-10-41__5820ade7-9fc0-46df-8469-2f305480bcae.h5 | ||
|
||
""" | ||
|
||
import h5py | ||
import numpy as np | ||
from pathlib import Path | ||
import argparse | ||
|
||
def load_h5_file(file_path): | ||
"""Load H5 file and return a dictionary of datasets""" | ||
data = {} | ||
with h5py.File(file_path, 'r') as f: | ||
# Recursively load all datasets | ||
def load_group(group, prefix=''): | ||
for key in group.keys(): | ||
path = f"{prefix}/{key}" if prefix else key | ||
if isinstance(group[key], h5py.Group): | ||
load_group(group[key], path) | ||
else: | ||
data[path] = group[key][:] | ||
load_group(f) | ||
return data | ||
|
||
def compare_h5_files(issac_path, mujoco_path): | ||
"""Compare two H5 files and print differences""" | ||
print(f"\nLoading files:") | ||
print(f"Isaac: {issac_path}") | ||
print(f"Mujoco: {mujoco_path}") | ||
|
||
# Load both files | ||
issac_data = load_h5_file(issac_path) | ||
mujoco_data = load_h5_file(mujoco_path) | ||
|
||
print("\nFile lengths:") | ||
print(f"Isaac datasets: {len(issac_data)}") | ||
print(f"Mujoco datasets: {len(mujoco_data)}") | ||
|
||
print("\nDataset shapes:") | ||
print("\nIsaac shapes:") | ||
for key, value in issac_data.items(): | ||
print(f"{key}: {value.shape}") | ||
|
||
print("\nMujoco shapes:") | ||
for key, value in mujoco_data.items(): | ||
print(f"{key}: {value.shape}") | ||
|
||
# Find common keys | ||
common_keys = set(issac_data.keys()) & set(mujoco_data.keys()) | ||
print(f"\nCommon datasets: {len(common_keys)}") | ||
|
||
# Find uncommon keys | ||
issac_only_keys = set(issac_data.keys()) - common_keys | ||
mujoco_only_keys = set(mujoco_data.keys()) - common_keys | ||
print(f"\nIsaac only datasets: {len(issac_only_keys)}") | ||
for key in issac_only_keys: | ||
print(f"Isaac only: {key}") | ||
print(f"\nMujoco only datasets: {len(mujoco_only_keys)}") | ||
for key in mujoco_only_keys: | ||
print(f"Mujoco only: {key}") | ||
|
||
# Compare data for common keys | ||
for key in common_keys: | ||
issac_arr = issac_data[key] | ||
mujoco_arr = mujoco_data[key] | ||
|
||
print(f"\n========== For {key} ===============") | ||
|
||
if issac_arr.shape != mujoco_arr.shape: | ||
print(f"\n{key} - Shape mismatch: Isaac {issac_arr.shape} vs Mujoco {mujoco_arr.shape}") | ||
|
||
# Calculate differences | ||
min_shape = min(issac_arr.shape[0], mujoco_arr.shape[0]) | ||
if issac_arr.shape != mujoco_arr.shape: | ||
raise ValueError(f"Shapes do not match for {key}. Cannot compare datasets with different shapes.") | ||
diff = np.abs(issac_arr[:min_shape] - mujoco_arr[:min_shape]) | ||
max_diff = np.max(diff) | ||
mean_diff = np.mean(diff) | ||
|
||
print(f"Max difference: {max_diff:.6f}") | ||
print(f"Mean difference: {mean_diff:.6f}\n") | ||
|
||
start_idx = 0 | ||
display_timesteps = 10 | ||
end_idx = start_idx + display_timesteps | ||
|
||
np.set_printoptions(formatter={'float': '{:0.6f}'.format}, suppress=True) | ||
print("Isaac:\n", issac_arr[start_idx:end_idx]) | ||
print("Mujoco:\n", mujoco_arr[start_idx:end_idx]) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Compare two H5 files from Isaac and Mujoco simulations') | ||
parser.add_argument('--isaac-file', required=True, help='Path to Isaac simulation H5 file') | ||
parser.add_argument('--mujoco-file', required=True, help='Path to Mujoco simulation H5 file') | ||
|
||
args = parser.parse_args() | ||
|
||
print(f"Isaac path: {args.isaac_file}") | ||
print(f"Mujoco path: {args.mujoco_file}") | ||
|
||
compare_h5_files(args.isaac_file, args.mujoco_file) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proper todo - remove print ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes proper TODO, will remove as soon as its done.