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

Ruff #141

Merged
merged 12 commits into from
Feb 10, 2025
Merged

Ruff #141

merged 12 commits into from
Feb 10, 2025

Conversation

taldcroft
Copy link
Member

@taldcroft taldcroft commented Jan 10, 2025

Description

Scratching the ruff itch again, now with xija.

This includes some non-trivial fixes along the way after the --unsafe-fixes commit. I tried to isolate those changes. This will need functional testing with xija_gui_fit.

Interface impacts

None.

Testing

Unit tests

  • Mac
(ska3-flight-2025.0rc2) ➜  xija git:(ruff) git rev-parse --short HEAD          
5ae0456
(ska3-flight-2025.0rc2) ➜  xija git:(ruff) pytest
============================================================ test session starts =============================================================
platform darwin -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /Volumes/git
configfile: pytest.ini
plugins: doctestplus-1.3.0, anyio-4.7.0, timeout-2.3.1
collected 44 items                                                                                                                           

xija/tests/test_get_model_spec.py .......                                                                                              [ 15%]
xija/tests/test_models.py .....................................                                                                        [100%]

============================================================ 44 passed in 37.44s =============================================================

Independent check of unit tests by Jean

  • osx
(ska3) flame:xija jean$ pytest xija
================================================ test session starts =================================================
platform darwin -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /Users/jean/git
configfile: pytest.ini
plugins: anyio-4.7.0, timeout-2.3.1
collected 44 items                                                                                                   

xija/tests/test_get_model_spec.py .......                                                                      [ 15%]
xija/tests/test_models.py .....................................                                                [100%]

================================================== warnings summary ==================================================
xija/xija/tests/test_models.py::test_dpa_real[True]
  /Users/jean/miniforge3/envs/ska3/lib/python3.12/site-packages/setuptools_scm/git.py:312: UserWarning: git archive did not support describe output
    warnings.warn("git archive did not support describe output")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================================== 44 passed, 1 warning in 33.96s ===========================================
(ska3) flame:xija jean$ git rev-parse HEAD
ce3f16a4a862dab2082107a31e5e3f71760da819

Functional tests

From this repo:

python -m xija.gui_fit.app acisfp_spec_matlab --stop 2025:001

Then:

  • Freeze all pars
  • Thaw a couple of power pars
  • Fit
  • Histogram
  • Save model
  • Show radzones, limits
  • Annotate line
  • Model info
  • Move sliders.

All OK.

Base automatically changed from improved-model-spec-file to master January 28, 2025 18:22
@taldcroft taldcroft marked this pull request as ready for review January 30, 2025 22:28
@taldcroft taldcroft requested review from jzuhone and jeanconn January 30, 2025 22:28
@@ -282,7 +282,7 @@ def __init__(self, model, main_window):

def toggle_all_data(self, state):
checked = state == QtCore.Qt.Checked
for i, box in enumerate(self.check_boxes):
for _i, box in enumerate(self.check_boxes):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably just cut the enumerate ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but then I would need to redo all the testing.

ui.add_user_pars("xijamod", self.model.parnames)
ui.set_model(1, "xijamod")
calc_stat = CalcStat(self.model, self.child_pipe, self.maxiter)
ui.load_user_stat("xijastat", calc_stat, lambda x: np.ones_like(x))
xijastat = globals()["xijastat"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would ui.set_state("xijastat") make as much sense if we're sticking with the ui versions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this was changed again in a later commit, though I think my question is still valid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would ui.set_state("xijastat") make as much sense if we're sticking with the ui versions?

I don't understand the question. Make as much as sense as what, and what is the context about sticking with ui versions?

I think these are mostly OBE, in that messing with this code was more trouble than its worth and probably out of scope for ruff (despite my earlier effort).

Copy link
Contributor

@jeanconn jeanconn Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding "I don't understand the question. Make as much as sense as what, " Sorry I was hoping that was clear in context and I had a typo. I meant - would ui.set_stat("xijastat") make as much sense as what you did in the first commit - where what you did was to define xijastat and then supply it with ui.set_state(xijastat) (no quotes). Because ui.set_stat will take either the string or the stat.

With regard to sticking with the ui versions, I thought that the problem with the "ui" versions of the sherpa functions is that they do insert into the namespace, but for most of the tasks one can instead use the OO sherpa pieces directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ui.set_stat will take either the string or the stat.

I'm guessing you trusted the documentation instead of trying it. I've been down that road...

  File "/Volumes/git/xija/xija/gui_fit/fitter.py", line 146, in fit
    ui.set_stat("xijastat")  # type: ignore  # noqa: F821, PGH003
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1, in set_stat
  File "/Users/aldcroft/miniconda3-arm/envs/ska3-flight-2025.0rc2/lib/python3.12/site-packages/sherpa/ui/utils.py", line 3076, in set_stat
    statobj = self._get_stat_by_name(stat)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aldcroft/miniconda3-arm/envs/ska3-flight-2025.0rc2/lib/python3.12/site-packages/sherpa/ui/utils.py", line 2899, in _get_stat_by_name
    raise ArgumentErr('badstat', name)
sherpa.utils.err.ArgumentErr: 'xijastat' is not a valid statistic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Does set_state(str) only work for the built-in statistics? I did not see that advertised. Thanks!

@@ -139,10 +139,12 @@ def fit(self):
ui.set_method(self.method)
ui.get_method().config.update(sherpa_configs.get(self.method, {}))
ui.load_user_model(CalcModel(self.model), "xijamod") # sets global xijamod
xijamod = globals()["xijamod"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this one used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved I think in a later commit though still a little confusing with ui .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't understand how these sherpa functions inject into the namespace. It is really unfortunate that ui.load_user_model doesn't return the model, but there you go.

@taldcroft taldcroft merged commit 744ed7b into master Feb 10, 2025
2 checks passed
@taldcroft taldcroft deleted the ruff branch February 10, 2025 12:10
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

Successfully merging this pull request may close these issues.

3 participants