QuantEcon / QuantEcon/QuantEcon.py

RFC: Decompose the four grade-D complexity hotspots

Open
#886 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

refactor
Dominant language
Python
Stars
2.4k
Forks
2.3k
Avg merge
3d 3h
Merged PRs (30d)
3

Description

Problem

Radon rates exactly four functions at cyclomatic-complexity grade D — everything else in the package is C or better, so the complexity is concentrated and tractable:

Function Location CC
_compute_fixed_point_ig _compute_fp.py:159 25
DiscreteDP.__init__ markov/ddp.py:299 24
brent_max optimize/scalar_maximization.py:5 24
polym_lcp_solver game_theory/howson_lcp.py:36 23

DiscreteDP.__init__ alone dispatches dense/sparse × full/state-action-pairs input forms inline; _compute_fixed_point_ig interleaves algorithm and bookkeeping. High-CC plus hand-verified numerics is where regressions hide.

Proposed change

One PR per function; behavior-preserving extraction only:

  • DiscreteDP.__init__ → extract _parse_full_form(...) / _parse_sa_form(...) validators returning a normalized bundle.
  • _compute_fixed_point_ig → separate the iteration loop from error/logging bookkeeping.
  • brent_max is Numba-jitted — some branching is inherent to Brent; treat as best-effort.
  • Guard with before/after output equality on existing tests (coverage in these regions is strong).

Related context: #480 (repeated logic in several modules).

Acceptance criteria
  • Radon grade ≤ C for the three non-jitted functions; no public API change
  • Suite green with unchanged numerical outputs

From the July 2026 technical-debt audit (AI-assisted; claims verified against 28d4b3b on 2026-07-25).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the four named entry points: _compute_fp.py:159, markov/ddp.py:299, optimize/scalar_maximization.py:5, and game_theory/howson_lcp.py:36, then run the existing suite and Radon. Work on one function per PR, preserving public APIs and numerical outputs; done means the three non-jitted functions reach Radon grade C or better and the suite remains green.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.