Skip to content
Snippets Groups Projects

RC 0.2.0

Open Daniel Sali requested to merge rc-020 into main
1 unresolved thread

Changes based on code review feedback.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Daniel Sali requested review from @normann

    requested review from @normann

  • assigned to @salid

  • Daniel Sali added 1 commit

    added 1 commit

    Compare with previous version

    • Hi Daniel,

      Thanks a lot for your MR. You did a very good job!

      For the record, going through each point raised in the code review and in our email exchange:

      • :white_check_mark: Dynare preprocessor options are now supported via the dynare_options argument in the dynare() function.

      • :white_check_mark: PyIndices has been unified in a new indices.py module.

      • :white_check_mark: No remaining use of Self: all class methods now use either quoted class names or omit return annotations.

      • :white_check_mark: Docstrings have been added to all from_julia routines.

      • :white_check_mark: PyGsSolverWs.from_julia is now a fully functional method. The former placeholder convert_jl_distribution has been removed, and a clean distribution_from_julia routine now returns proper scipy.stats objects. Much better!

      • :white_check_mark: Logging is now configurable via setup_logging() and respects the DYNARE_PYTHON_LOGLEVEL environment variable (DEBUG, INFO, WARNING, ERROR, CRITICAL).

      • :white_check_mark: Enum parsing has been cleaned up: fragile repr()-based parsing was replaced by cls[str(jl_enum)] in SymbolType.from_julia, EstimatedParameterType.from_julia, and PySGSolver.from_julia.

      • :warning: Dynamic loading of external libraries (e.g., Tasmanian) is still a bit fragile:

        • If LIBTASMANIAN_PATH is wrong or the file is corrupted, the current implementation may crash without a clear error.
        • Required functions (like tsgConstructTasmanianSparseGrid) aren’t checked explicitly.
        • The library is loaded at module scope, which introduces side effects on import even if Tasmanian features aren’t used.
        • Although Tasmanian handles its own memory, the global ctypes.CDLL reference keeps the library loaded for the entire Python session, which could limit flexibility in modular or long-running applications.

      A lazy-loading helper such as the following would improve safety and control:

      _TASlib = None
      
      def get_tasmanian_lib():
          global _TASlib
          if _TASlib is not None:
              return _TASlib
      
          libtas_path = os.getenv("LIBTASMANIAN_PATH")
          if not libtas_path:
              logger.warning("LIBTASMANIAN_PATH not set. Tasmanian-dependent features will be unavailable.")
              return None
      
          try:
              _TASlib = ctypes.CDLL(libtas_path)
              for name in ["tsgConstructTasmanianSparseGrid", ...]:
                  getattr(_TASlib, name)
              return _TASlib
          except Exception as e:
              logger.error(f"Failed to load Tasmanian library: {e}")
              return None

      Each method needing Tasmanian would then call:

      lib = get_tasmanian_lib()
      if lib is None:
          raise RuntimeError("Tasmanian is not available.")

      I noticed you implemented a related pattern in PyTasmanianSG.__del__, which is great, but we may want to consolidate this logic into a central function like get_tasmanian_lib() for reuse and extensibility.

      • :white_check_mark: Unused TypeVar declarations in PyGeneralizedFirstOrderAlgorithm were removed.
      • :white_check_mark: The typo List(int) was corrected to List[int] in PyLUWs.
      • :white_check_mark: Global initialization is now deferred via lazy_init. Initialization happens only on first use of dynare() (via ensure_initialized() and the _has_run flag). Users can also call ensure_initialized() manually to trigger setup earlier or outside of dynare().

      Let me know what you think of the remaining points, especially regarding the Tasmanian loading strategy. Once that's settled, I believe the code will be ready for release. Thanks again for the quality of your work and your responsiveness throughout! It's a real pleasure working with you on this.

  • Normann Rion left review comments

    left review comments

Please register or sign in to reply
Loading