Add n_pred parameter to Lightcurve.plot() to control prediction grid size#150
Add n_pred parameter to Lightcurve.plot() to control prediction grid size#150
n_pred parameter to Lightcurve.plot() to control prediction grid size#150Conversation
Agent-Logs-Url: https://github.com/ICSM/pgmuvi/sessions/52de7205-ab74-4003-aec4-1ab528fb8cc2 Co-authored-by: sundarjhu <15619959+sundarjhu@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a user-configurable n_pred parameter to Lightcurve.plot() to control the size of the fine prediction time grid, reducing default memory usage (especially for 2D light curves).
Changes:
- Extend
Lightcurve.plot()signature withn_pred=1000. - Use
n_predinstead of a hard-coded 10,000 steps when buildingx_fine_raw. - Document
n_predin theplot()numpydoc docstring.
| for plotting. Lower values reduce memory usage and speed up plotting, | ||
| especially for 2D light curves. Default is 1000. |
There was a problem hiding this comment.
The new docstring lines for n_pred appear to exceed the repo’s configured 88-character line length (Black/Ruff), which will trigger E501. Please wrap the description across multiple lines to keep each line within the limit.
| for plotting. Lower values reduce memory usage and speed up plotting, | |
| especially for 2D light curves. Default is 1000. | |
| for plotting. Lower values reduce memory usage and speed up | |
| plotting, especially for 2D light curves. Default is 1000. |
| mcmc_samples=False, | ||
| n_pred=1000, | ||
| **kwargs, |
There was a problem hiding this comment.
n_pred is passed directly to torch.linspace(..., steps=n_pred). To avoid cryptic runtime errors (e.g., when n_pred is 0/1, negative, non-int, or a NumPy scalar), please validate n_pred early (type + >= 2) and raise a clear ValueError.
| if self.ndim == 1: | ||
| x_raw = self.xdata | ||
| elif self.ndim == 2: | ||
| x_raw = self.xdata[:, 0] | ||
| # y_raw = self.ydata | ||
|
|
||
| # creating array of 10000 test points across the range of the data | ||
| x_fine_raw = torch.linspace(x_raw.min(), x_raw.max(), 10000) | ||
| # creating array of test points across the range of the data | ||
| x_fine_raw = torch.linspace(x_raw.min(), x_raw.max(), n_pred) | ||
|
|
There was a problem hiding this comment.
For self.ndim > 2, x_raw is never assigned but x_fine_raw = torch.linspace(x_raw.min(), ...) is still executed, so calling plot() on higher-dimensional lightcurves will raise UnboundLocalError before hitting the intended NotImplementedError. Please move the ndim guard before computing x_fine_raw (or define x_raw for all supported cases).
| def plot( | ||
| self, | ||
| ylim=None, | ||
| yscale="auto", | ||
| show=True, | ||
| mcmc_samples=False, | ||
| n_pred=1000, | ||
| **kwargs, |
There was a problem hiding this comment.
n_pred changes plot()’s public API and default behavior (10,000 → 1,000). There are existing plot tests, but none exercise the new parameter. Please add a small unit test that plot(show=False, n_pred=...) works for both 1D and 2D, and (once validation is added) that invalid n_pred values raise a clear error.
|
@copilot, please implement all your suggestions. |
…g wrap, tests Agent-Logs-Url: https://github.com/ICSM/pgmuvi/sessions/568dc183-4dd4-44b8-96e2-00dbc89c67c1 Co-authored-by: sundarjhu <15619959+sundarjhu@users.noreply.github.com>
Agent-Logs-Url: https://github.com/ICSM/pgmuvi/sessions/568dc183-4dd4-44b8-96e2-00dbc89c67c1 Co-authored-by: sundarjhu <15619959+sundarjhu@users.noreply.github.com>
Done in 8d297b1. Implemented all four suggestions:
|
Lightcurve.plot()hard-coded 10,000 prediction points for the fine time grid, causing memory issues for 2D light curves. This adds an_predparameter (default1000) to make the grid size user-configurable.Changes
Lightcurve.plot()signature: Addedn_pred=1000parametertorch.linspace(..., 10000)withtorch.linspace(..., n_pred)n_pred(wrapped to ≤88 chars)n_predis validated early — rejects booleans, non-integers, and values< 2; accepts numpy integers vianp.integerndim > 2fix:NotImplementedErroris now raised beforex_raw/x_fine_raware computed, preventing a confusingUnboundLocalErroron higher-dimensional dataTestPlotNPredwith 8 tests covering 1D/2D acceptance, invalid value rejection (float, bool, zero, negative, one), and numpy integer acceptanceUsage
The default changes from 10,000 → 1,000, which also reduces default memory consumption.