Skip to content

Commit

Permalink
CI, fix pytest etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
kharitonov-ivan committed Nov 8, 2023
1 parent 841d248 commit e8e76bd
Show file tree
Hide file tree
Showing 124 changed files with 232 additions and 213 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ on: [push, pull_request]
jobs:
lint-format:
runs-on: ubuntu-latest
container:
container:
image: python:3.10-slim

steps:
- uses: actions/checkout@v2
- name: Install Ruff, Black, and isort
run: pip install ruff "black[jupyter]" isort
- name: Check imports order with isort
run: isort . --check-only
- name: Check Python code formatting with Black
run: black --check .
- name: Run Ruff linter
run: ruff .
- uses: actions/checkout@v2
- name: Install Ruff, Black, and isort
run: pip install ruff "black[jupyter]" isort
- name: Check imports order with isort
run: isort . --check-only
- name: Check Python code formatting with Black
run: black --check .
- name: Run Ruff linter
run: ruff .
20 changes: 20 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Python package testing

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libeigen3-dev
- name: Install dependencies
run: python -m pip install --upgrade pip && python -m pip install -e .
- name: Run tests
run: pytest
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ dmypy.json
# Pyre type checker
.pyre/

# Images
.images
*.png
*.gif

# VScode
.vscode
.vscode/settings.json
Expand All @@ -149,4 +144,5 @@ data/*

# results
*.csv
*.pdf
*.pdf
*.drawio.bkp
41 changes: 40 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies = [
"ipykernel>=6.26.0",
"black[jupyter]>=23.10.1",
"nb-clean>=3.1.0",
"pytest-xdist[psutil]>=3.3.1",
]
requires-python = ">= 3.9, < 3.11"
readme = "README.md"
Expand Down
8 changes: 0 additions & 8 deletions src/common/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,3 @@ def __new__(cls, log_weight, gaussian):
obj = np.asarray((log_weight, gaussian), dtype=dtype).view(cls)
# Finally, we must return the newly created object:
return obj


if __name__ == "__main__":
a = Gaussian(mean=[2.0, 2.0, 3.0], covariance=np.eye(3), ndim=3)
b = WeightedGaussian(log_weight=0.03)
import pdb

pdb.set_trace()
6 changes: 3 additions & 3 deletions src/common/vectorized_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def vectorized_gaussian_logpdf(X, means, covariances):
results = vectorized_gaussian_logpdf(X, means, covariances)
fast_time = time.time() - fast_start

print("Reference time:", ref_time)
print("Vectorized time:", fast_time)
print("Speedup:", ref_time / fast_time)
print("Reference time:", ref_time) # noqa: T201
print("Vectorized time:", fast_time) # noqa: T201
print("Speedup:", ref_time / fast_time) # noqa: T201

assert np.allclose(results, refs)
14 changes: 7 additions & 7 deletions src/evaluation_runners/nuscenes/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(

# Load data.
if verbose:
print("Initializing nuScenes tracking evaluation")
print("Initializing nuScenes tracking evaluation") # noqa: T201
pred_boxes, self.meta = load_prediction(self.result_path, self.cfg.max_boxes_per_sample, TrackingBox, verbose=verbose)
gt_boxes = load_gt(nusc, self.eval_set, TrackingBox, verbose=verbose)
# assert set(pred_boxes.sample_tokens) == set(
Expand All @@ -105,10 +105,10 @@ def __init__(

# Filter boxes (distance, points per box, etc.).
if verbose:
print("Filtering tracks")
print("Filtering tracks") # noqa: T201
pred_boxes = filter_eval_boxes(nusc, pred_boxes, self.cfg.class_range, verbose=verbose)
if verbose:
print("Filtering ground truth tracks")
print("Filtering ground truth tracks") # noqa: T201
gt_boxes = filter_eval_boxes(nusc, gt_boxes, self.cfg.class_range, verbose=verbose)

self.sample_tokens = gt_boxes.sample_tokens
Expand All @@ -129,7 +129,7 @@ def evaluate(self) -> Tuple[TrackingMetrics, TrackingMetricDataList]:
# Step 1: Accumulate metric data for all classes and distance thresholds.
# -----------------------------------
if self.verbose:
print("Accumulating metric data...")
print("Accumulating metric data...") # noqa: T201
metric_data_list = TrackingMetricDataList()

def accumulate_class(curr_class_name):
Expand All @@ -156,7 +156,7 @@ def accumulate_class(curr_class_name):
# Step 2: Aggregate metrics from the metric data.
# -----------------------------------
if self.verbose:
print("Calculating metrics...")
print("Calculating metrics...") # noqa: T201
for class_name in self.cfg.class_names:
# Find best MOTA to determine threshold to pick for traditional metrics.
# If multiple thresholds have the same value, pick the one with the highest recall.
Expand Down Expand Up @@ -200,7 +200,7 @@ def render(self, md_list: TrackingMetricDataList) -> None:
:param md_list: TrackingMetricDataList instance.
"""
if self.verbose:
print("Rendering curves")
print("Rendering curves") # noqa: T201

def savepath(name):
return os.path.join(self.plot_dir, name + ".pdf")
Expand All @@ -223,7 +223,7 @@ def main(self, render_curves: bool = True) -> Dict[str, Any]:

# Dump the metric data, meta and metrics to disk.
if self.verbose:
print("Saving metrics to: %s" % self.output_dir)
print("Saving metrics to: %s" % self.output_dir) # noqa: T201
metrics_summary = metrics.serialize()
metrics_summary["meta"] = self.meta.copy()
with open(os.path.join(self.output_dir, "metrics_summary.json"), "w") as f:
Expand Down
7 changes: 1 addition & 6 deletions src/evaluation_runners/nuscenes/nuscenes_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def run_tracking_evaluation(self):
results = {}

for scene_name in self.evaluation_set:
print(f"scene name: {scene_name}")
scene = [scene for scene in self.nuscenes_helper.scene if scene["name"] == scene_name][0]
scene_token = scene["token"]
results.update(self.process_scene(scene_token))
Expand Down Expand Up @@ -245,10 +244,7 @@ def get_measurements_for_one_sample(self, token):

# get object pose
pos_x, pos_y, pos_z = detection.translation
quaternion = Quaternion(detection.rotation)
yaw = quaternion.angle if quaternion.axis[2] > 0 else -quaternion.angle
print(yaw)

_quaternion = Quaternion(detection.rotation)
object_size = detection.size
detection_confidence = detection.detection_score

Expand All @@ -258,7 +254,6 @@ def get_measurements_for_one_sample(self, token):
metadata=ObjectMetadata(object_class=obj_type, size=object_size, confidence=detection_confidence),
)
if detection.detection_name == "car" and detection.detection_score > 0.3:
print(detection.detection_name, detection.detection_score)
measurements.append(object_detection) # get only x,y position

observations = ObservationList(measurements)
Expand Down
6 changes: 0 additions & 6 deletions src/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from src.metrics import GOSPA
from src.motion_models import MotionModel
from src.simulator import MeasurementData, ObjectData
from src.utils.get_path import get_images_dir
from src.utils.plotting import setup_ax
from src.utils.visualizer.common.plot_series import (
OBJECT_COLORS,
Expand Down Expand Up @@ -256,11 +255,6 @@ def run_tracker(
tracker_P_G: float = 0.999,
):
ground_truth, env_sensor_model, object_data, meas_data = generate_environment(object_configs, total_time, env_motion_model, env_meas_model, env_P_D, env_lambda_c, env_range_c)
# ground_truth = GroundTruthConfig(object_configs, total_time)
# env_sensor_model = SensorModelConfig(env_P_D, env_lambda_c, env_range_c)
# object_data = ObjectData(ground_truth, env_motion_model, if_noisy=False)
# meas_data_gen = MeasurementData(object_data, env_sensor_model, env_meas_model)
# meas_data = [next(meas_data_gen) for _ in range(total_time)]

tracker_meas_model = env_meas_model if tracker_meas_model is None else tracker_meas_model
tracker_motion_model = env_motion_model if tracker_motion_model is None else tracker_motion_model
Expand Down
4 changes: 2 additions & 2 deletions src/utils/get_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def get_data_dir():
return os.path.join(get_project_dir(), "data")


def get_images_dir(current_file=__file__, dir_name=".images"):
def get_images_dir(current_file=__file__, dir_name="images"):
current_dir = os.path.dirname(os.path.abspath(current_file))
image_dir = os.path.join(current_dir, dir_name)
os.makedirs(image_dir, exist_ok=True)
return image_dir


def delete_images_dir(current_file=__file__, dir_name=".images") -> None:
def delete_images_dir(current_file=__file__, dir_name="images") -> None:
current_dir = os.path.dirname(os.path.abspath(current_file))
image_dir = os.path.join(current_dir, dir_name)
try:
Expand Down
6 changes: 3 additions & 3 deletions src/utils/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ def get_profile_data(self):
for _i in range(1000):
r = re.compile(r"^$")

print(p.get_profile_data())
print(p.get_profile_data()) # noqa: T201

try:
with Profiler(enabled=True, contextstr="exception") as p:
raise ValueError("Error")
except ValueError:
print(p.get_profile_data())
print(p.get_profile_data()) # noqa: T201

profiling_enabled = False
with Profiler(enabled=profiling_enabled, contextstr="not enabled") as p:
for _i in range(1000):
r = re.compile(r"^$")

print(p.get_profile_data())
print(p.get_profile_data()) # noqa: T201
6 changes: 3 additions & 3 deletions src/utils/vectorized_gaussian_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def vectorized_gaussian_logpdf(X, means, covariances):
results = vectorized_gaussian_logpdf(X, means, covariances)
fast_time = time.time() - fast_start

print("Reference time:", ref_time)
print("Vectorized time:", fast_time)
print("Speedup:", ref_time / fast_time)
print("Reference time:", ref_time) # noqa: T201
print("Vectorized time:", fast_time) # noqa: T201
print("Speedup:", ref_time / fast_time) # noqa: T201

assert np.allclose(results, refs)
24 changes: 24 additions & 0 deletions tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# .github/workflows/tests.yml
name: Tests
on: push
jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: 3.8
architecture: x64
- run: sudo apt -y install libeigen3-dev
- run: cd /usr/include && sudo ln -sf eigen3/Eigen Eigen
- run: sudo apt -y install ninja-build
- run: pip install nox==2020.12.31
- run: pip install poetry==1.1.6
tests:
- run: nox
- name: Archive code coverage results
uses: actions/upload-artifact@v2
with:
name: test-pmbm-plots
path: tests/PMBM/.images/*.png
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 6 additions & 7 deletions tests/MOT/n_mot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from src.motion_models import ConstantVelocityMotionModel
from src.scenarios.initial_conditions import all_object_scenarios
from src.trackers.n_object_trackers import GlobalNearestNeighboursTracker
from tests.testing_trackers import ( # noqa
env_clutter_rate,
env_detection_probability,
env_measurement_model,
filepath_fixture,
test_synthetic_scenario,
)
from tests.testing_trackers import test_synthetic_scenario # noqa: F401


@pytest.fixture(scope="session")
def _file_():
yield __file__


@pytest.fixture(params=[x for x in all_object_scenarios if x.motion_model == ConstantVelocityMotionModel]) # and
Expand Down
Binary file removed tests/PHD/.images/GMPHD-n_MOT_linear_CV.gif
Diff not rendered.
Binary file removed tests/PHD/.images/GMPHD-n_MOT_linear_CV.png
Diff not rendered.
12 changes: 6 additions & 6 deletions tests/PHD/phd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from src.scenarios.initial_conditions import all_object_scenarios
from src.trackers.multiple_object_trackers.PHD import GMPHD

from ..testing_trackers import ( # noqa
env_clutter_rate,
env_detection_probability,
env_measurement_model,
test_synthetic_scenario,
)
from ..testing_trackers import test_synthetic_scenario # noqa: F401


@pytest.fixture(scope="session")
def _file_():
yield __file__


@pytest.fixture(params=[x for x in all_object_scenarios if x.motion_model == ConstantVelocityMotionModel])
Expand Down
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading

0 comments on commit e8e76bd

Please sign in to comment.