Skip to content
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

Different behaviour with or without the pre-commit hook (reportAttributeAccessIssue) #285

Closed
ReHoss opened this issue Jul 26, 2024 · 3 comments

Comments

@ReHoss
Copy link

ReHoss commented Jul 26, 2024

Hi there,

When running pre-commit run with the environment given below, I get this error

error: "run_data_generator" is not a known attribute of module "examples.python_scripts.generating_trajectory_data.trajectory_generator"(reportAttributeAccessIssue)

while running pyright does not return any error.

Could you explain why this behaviour is observed?

Working tree:
control_dde/
├── examples/
│   ├── __init__.py
│   └── python_scripts/
│       ├── __init__.py
│       └── generating_trajectory_data/
│           ├── __init__.py
│           └── trajectory_generator.py
└── test/
    └── test_generator_and_training.py
test_generator_and_training.py
import pathlib
from typing import Any, Generator

import pytest
from control_dde.utils import PATH_PROJECT_ROOT
from examples.python_scripts.generating_trajectory_data import trajectory_generator


@pytest.fixture(params=[94])
def seed(request) -> Generator[int, None, None]:
    yield request.param


@pytest.fixture(params=["debug_pytest"])
def mlflow_experiment_name(request) -> Generator[str, None, None]:
    yield request.param


@pytest.fixture(params=["unique_trajectory_divided", "multiple_trajectories"])
def data_type(request) -> Generator[str, None, None]:
    yield request.param


@pytest.fixture(params=[20])
def num_steps(request) -> Generator[int, None, None]:
    yield request.param


@pytest.fixture(params=["zero", "uniform"])
def control_type(request) -> Generator[str, None, None]:
    yield request.param


@pytest.fixture(params=[1, 4])
def num_trajectories(request) -> Generator[int, None, None]:
    yield request.param


@pytest.fixture(
    params=["pendulum", "mackey_glass", "vanderpol", "linear_time_invariant"]
)
def env_name(request) -> Generator[str, None, None]:
    yield request.param


@pytest.fixture
def dict_env_params() -> dict[str, Any]:
    return {
        "pendulum": {},
        "mackey_glass": {},
        "vanderpol": {},
        "linear_time_invariant": {
            "dt": 0.01,
            "matrix_a": [[1, 2], [3, 4]],
            "matrix_b": [[-1], [-2]],
            "matrix_c": [[0, 1]],
            "control_penalty": 1,
            "dtype": "float32",
        },
    }


@pytest.fixture
def dict_configuration(
    seed: int,
    mlflow_experiment_name: str,
    data_type: str,
    num_steps: int,
    control_type: str,
    num_trajectories: int,
    env_name: str,
    dict_env_params: dict[str, Any],
) -> dict[str, Any]:
    return {
        "seed": seed,
        "mlflow_experiment_name": mlflow_experiment_name,
        "data": {
            "type": data_type,
            "num_steps": num_steps,
            "control_type": control_type,
            "num_trajectories": num_trajectories,
        },
        "env": {"name": env_name, "params": dict_env_params[env_name]},
    }


def test_generator_from_list_configurations(dict_configuration: dict[str, Any]):
    trajectory_generator.run_data_generator(
        dict_config=dict_configuration,
        path_config_absolute=None,
        path_project_root=pathlib.Path(PATH_PROJECT_ROOT),
        plot_trajectory_data=True,
    )
pyrightconfig.json
{
  "venvPath": "venv",
  "venv": "venv_control_dde",
}
.pre-commit-config.yaml
  - repo: https://github.com/RobertCraigie/pyright-python
    rev: v1.1.373
    hooks:
      - id: pyright
        exclude: 'oderl/.*'
        files: "."
        args: ["--pythonpath", "."]
        additional_dependencies: [ torch, pytest, typing_extensions, jaxtyping, matplotlib, gymnasium, seaborn, torchvision, scipy ]
@RobertCraigie
Copy link
Owner

should your import be this?

from control_dde.examples.python_scripts.generating_trajectory_data import trajectory_generator

if you could share a repository to reproduce this issue, that'd be a great help :)

@chrismv48
Copy link

This is happening to me too. Driving me nuts

@RobertCraigie
Copy link
Owner

I believe this will be due to dependency mismatches or other pre-commit environment differences, so I'm closing in favour of #203.

@RobertCraigie RobertCraigie closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants