bluesky / hklpy

Diffractometer computation library with ophyd pseudopositioner support
https://blueskyproject.io/hklpy
BSD 3-Clause "New" or "Revised" License
2 stars 11 forks source link

xx forward() should pick answer consistent with forward_solutions_table() and default decision function #314

Closed prjemian closed 6 months ago

prjemian commented 6 months ago
prjemian commented 6 months ago

Hey! This CI test failed (as expected) yet the failure was not reported and the CI run reported it passed:

2023-12-15T17:10:58.7361001Z hkl/tests/test_diffract.py::test_i303_forward_solution_original_problem FAILED [ 47%]

Why?

prjemian commented 6 months ago

Missing 29 FAILED tests in that run alone! Such as:

2023-12-15T17:11:13.7540605Z hkl/tests/test_save_restore_UB.py::test_fourc_orientation_save FAILED    [ 88%]
2023-12-15T17:11:13.9605639Z hkl/tests/test_save_restore_UB.py::test_fourc_run_orientation_info FAILED [ 88%]
2023-12-15T17:11:14.1855896Z hkl/tests/test_save_restore_UB.py::test_list_orientation_runs FAILED     [ 89%]
2023-12-15T17:11:14.4015204Z hkl/tests/test_save_restore_UB.py::test_no_primary_stream FAILED         [ 89%]
2023-12-15T17:11:14.6074653Z hkl/tests/test_save_restore_UB.py::test_missing_energy_key FAILED        [ 89%]
2023-12-15T17:11:14.8122051Z hkl/tests/test_save_restore_UB.py::test_restore_orientation FAILED       [ 89%]
2023-12-15T17:11:15.0168836Z hkl/tests/test_save_restore_UB.py::test_restore_sample FAILED            [ 89%]
prjemian commented 6 months ago

This is a common report in the tests:

2023-12-15T14:15:49.3143529Z             |   File "/home/runner/micromamba/envs/hklpy-test-py-3.11/lib/python3.11/site-packages/databroker/mongo_normalized.py", line 1277, in get_serializer
2023-12-15T14:15:49.3143721Z             |     from suitcase.mongo_normalized import Serializer
2023-12-15T14:15:49.3144061Z             | ModuleNotFoundError: No module named 'suitcase'
prjemian commented 6 months ago

So two problems:

prjemian commented 6 months ago

Test stopped on first pytest failed test but the CI reported as green. :(

prjemian commented 6 months ago

At least it failed on the expected failure due to #303

        # Check that phi is held constant in forward()
        # Returns a position namedtuple.
        position = e4cv.forward(refl)
>       assert pytest.approx(position.phi, abs=1e-4) == 21.3456
E       assert 0.0 ± 1.0e-04 == 21.3456
E         comparison failed
E         Obtained: 21.3456
E         Expected: 0.0 ± 1.0e-04
prjemian commented 6 months ago

Py3.8 fails now (as it did in previous run) with:

hkl/__init__.py:37: in <module>
    from .configuration import DiffractometerConfiguration  # noqa: F401, F402, E402
hkl/configuration.py:187: in <module>
    class DCReflection:
hkl/configuration.py:190: in DCReflection
    reflection: dict[str, float]
E   TypeError: 'type' object is not subscriptable
prjemian commented 6 months ago

Still:

hkl/configuration.py:237: in DCSample
    reflections: list[DCReflection]
E   TypeError: 'type' object is not subscriptable

As this SO post states:

The following answer only applies to Python < 3.9

prjemian commented 6 months ago

Still fails with:

2023-12-18T22:32:25.0637480Z           |     from suitcase.mongo_normalized import Serializer
2023-12-18T22:32:25.0638003Z           | ModuleNotFoundError: No module named 'suitcase'

A solution for which was noted previously.

prjemian commented 6 months ago

This is odd. A run passed back one (1) UID but there are zero (0) in the catalog.

    def test_fourc_orientation_save(cat, RE, fourc):
        assert len(cat) == 0
        det = hw().noisy_det

        # this run will not save orientation information
        _uids = RE(bp.count([det]))
        assert len(_uids) == 1
>       assert len(cat) == 1
E       assert 0 == 1
E        +  where 0 = len(<Catalog {1}>)

hkl/tests/test_save_restore_UB.py:87: AssertionError
prjemian commented 6 months ago

Failed in both py3.9 & 3.10

prjemian commented 6 months ago

Starting to see the deeper cause: TypeError: Type is not JSON serializable: _ResultTuple. So what, exactly, has this content. Suspect a numpy structure.

more detail:

2023-12-18T22:54:14.4451462Z _________________________ test_fourc_orientation_save __________________________
2023-12-18T22:54:14.4452270Z 
2023-12-18T22:54:14.4452843Z cat = <Catalog {1}>
2023-12-18T22:54:14.4453646Z RE = <bluesky.run_engine.RunEngine object at 0x7f715f35e350>
2023-12-18T22:54:14.4456525Z fourc = Fourc(prefix='', name='fourc', settle_time=0.0, timeout=None, egu='', limits=(0, 0), source='computed', read_attrs=['h... '_hklpy_version', '_pseudos', '_reals', '_constraints', '_mode', 'orientation_attrs', 'h', 'k', 'l'], concurrent=True)
2023-12-18T22:54:14.4458142Z 
2023-12-18T22:54:14.4458400Z     def test_fourc_orientation_save(cat, RE, fourc):
2023-12-18T22:54:14.4459079Z         assert len(cat) == 0
2023-12-18T22:54:14.4459805Z         det = hw().noisy_det
2023-12-18T22:54:14.4460236Z     
2023-12-18T22:54:14.4460677Z         # this run will not save orientation information
2023-12-18T22:54:14.4461330Z         _uids = RE(bp.count([det]))
2023-12-18T22:54:14.4461867Z         assert len(_uids) == 1
2023-12-18T22:54:14.4462299Z >       assert len(cat) == 1
2023-12-18T22:54:14.4462573Z E       assert 0 == 1
2023-12-18T22:54:14.4463014Z E        +  where 0 = len(<Catalog {1}>)
2023-12-18T22:54:14.4463387Z 
2023-12-18T22:54:14.4463639Z hkl/tests/test_save_restore_UB.py:87: AssertionError
2023-12-18T22:54:14.4464541Z ---------------------------- Captured stderr setup -----------------------------
2023-12-18T22:54:14.4465453Z OBJECT CACHE: Will use up to 2_513_667_686 bytes (15% of total physical RAM)
2023-12-18T22:54:14.4466475Z ------------------------------ Captured log setup ------------------------------
2023-12-18T22:54:14.4467203Z INFO     tiled.server.object_cache:app.py:517 Will use up to 2_513_667_686 bytes (15% of total physical RAM)
2023-12-18T22:54:14.4468398Z _______________________ test_fourc_run_orientation_info ________________________
2023-12-18T22:54:14.4469134Z TypeError
2023-12-18T22:54:14.4469351Z 
2023-12-18T22:54:14.4469749Z The above exception was the direct cause of the following exception:
2023-12-18T22:54:14.4470369Z 
2023-12-18T22:54:14.4470715Z cat = <Catalog {1}>
2023-12-18T22:54:14.4471291Z RE = <bluesky.run_engine.RunEngine object at 0x7f715cf1dd50>
2023-12-18T22:54:14.4473542Z fourc = Fourc(prefix='', name='fourc', settle_time=0.0, timeout=None, egu='', limits=(0, 0), source='computed', read_attrs=['h... '_hklpy_version', '_pseudos', '_reals', '_constraints', '_mode', 'orientation_attrs', 'h', 'k', 'l'], concurrent=True)
2023-12-18T22:54:14.4475085Z 
2023-12-18T22:54:14.4475337Z     def test_fourc_run_orientation_info(cat, RE, fourc):
2023-12-18T22:54:14.4475733Z >       RE(bp.count([fourc]))
2023-12-18T22:54:14.4475924Z 
2023-12-18T22:54:14.4476046Z hkl/tests/test_save_restore_UB.py:128: 
2023-12-18T22:54:14.4476485Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2023-12-18T22:54:14.4477341Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:899: in __call__
2023-12-18T22:54:14.4478322Z     plan_return = self._resume_task(init_func=_build_task)
2023-12-18T22:54:14.4479715Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:1038: in _resume_task
2023-12-18T22:54:14.4480811Z     raise exc
2023-12-18T22:54:14.4481719Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:1668: in _run
2023-12-18T22:54:14.4482312Z     raise err
2023-12-18T22:54:14.4482927Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:1528: in _run
2023-12-18T22:54:14.4483584Z     msg = self._plan_stack[-1].send(resp)
2023-12-18T22:54:14.4484250Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/plans.py:81: in count
2023-12-18T22:54:14.4484845Z     return (yield from inner_count())
2023-12-18T22:54:14.4485571Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/utils/__init__.py:1202: in dec_inner
2023-12-18T22:54:14.4486219Z     return (yield from plan)
2023-12-18T22:54:14.4486934Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/preprocessors.py:954: in stage_wrapper
2023-12-18T22:54:14.4488599Z     return (yield from finalize_wrapper(inner(), unstage_devices()))
2023-12-18T22:54:14.4490302Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/preprocessors.py:511: in finalize_wrapper
2023-12-18T22:54:14.4491516Z     ret = yield from plan
2023-12-18T22:54:14.4492685Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/preprocessors.py:952: in inner
2023-12-18T22:54:14.4493782Z     return (yield from plan)
2023-12-18T22:54:14.4495200Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/utils/__init__.py:1202: in dec_inner
2023-12-18T22:54:14.4496345Z     return (yield from plan)
2023-12-18T22:54:14.4497551Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/preprocessors.py:327: in run_wrapper
2023-12-18T22:54:14.4498738Z     yield from contingency_wrapper(plan,
2023-12-18T22:54:14.4500123Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/preprocessors.py:577: in contingency_wrapper
2023-12-18T22:54:14.4501343Z     ret = yield from plan
2023-12-18T22:54:14.4502448Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/plans.py:77: in inner_count
2023-12-18T22:54:14.4503749Z     yield from bps.declare_stream(*detectors, name='primary')
2023-12-18T22:54:14.4505168Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/plan_stubs.py:47: in declare_stream
2023-12-18T22:54:14.4506690Z     return (yield Msg('declare_stream', None, *separate_devices(objs), name=name))
2023-12-18T22:54:14.4508170Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:1588: in _run
2023-12-18T22:54:14.4509246Z     new_response = await coro(msg)
2023-12-18T22:54:14.4510711Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:1852: in _declare_stream
2023-12-18T22:54:14.4511930Z     return (await current_run.declare_stream(msg))
2023-12-18T22:54:14.4513304Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/bundlers.py:198: in declare_stream
2023-12-18T22:54:14.4514603Z     return (await self._prepare_stream(stream_name, objs))
2023-12-18T22:54:14.4516134Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/bundlers.py:167: in _prepare_stream
2023-12-18T22:54:14.4517441Z     await self.emit(DocumentNames.descriptor, descriptor_doc)
2023-12-18T22:54:14.4518856Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:2515: in emit
2023-12-18T22:54:14.4519921Z     self.emit_sync(name, doc)
2023-12-18T22:54:14.4521083Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:2512: in emit_sync
2023-12-18T22:54:14.4522211Z     self.dispatcher.process(name, doc)
2023-12-18T22:54:14.4523430Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/run_engine.py:2535: in process
2023-12-18T22:54:14.4524683Z     exceptions = self.cb_registry.process(name, name.name, doc)
2023-12-18T22:54:14.4526075Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/utils/__init__.py:384: in process
2023-12-18T22:54:14.4527169Z     func(*args, **kwargs)
2023-12-18T22:54:14.4528381Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/bluesky/utils/__init__.py:473: in __call__
2023-12-18T22:54:14.4529596Z     return mtd(*args, **kwargs)
2023-12-18T22:54:14.4530777Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/databroker/v1.py:771: in insert
2023-12-18T22:54:14.4531908Z     self.v2.post_document(name, doc)
2023-12-18T22:54:14.4533251Z ../../../micromamba/envs/hklpy-test-py-3.10/lib/python3.10/site-packages/databroker/client.py:323: in post_document
2023-12-18T22:54:14.4534456Z     content=safe_json_dump({"name": name, "doc": doc})
2023-12-18T22:54:14.4535254Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2023-12-18T22:54:14.4536065Z 
2023-12-18T22:54:14.4536892Z content = {'doc': {'configuration': {'fourc': {'data': {'fourc_U': array([[-1.22173048e-05, -1.00000000e+00,  0.00000000e+00],
2023-12-18T22:54:14.4538499Z  ......}, 'hints': {'fourc': {'fields': ['fourc_h', 'fourc_k', 'fourc_l']}}, 'name': 'primary', ...}, 'name': 'descriptor'}
prjemian commented 6 months ago

Here:

k1='fourc_lattice'  k2='value'  type(v2)=<class 'numpy.ndarray'>
k1='fourc_lattice_reciprocal'  k2='value'  type(v2)=<class 'hkl.sample._ResultTuple'>
k1='fourc_U'  k2='value'  type(v2)=<class 'numpy.ndarray'>
k1='fourc_UB'  k2='value'  type(v2)=<class 'numpy.ndarray'>
k1='fourc__pseudos'  k2='value'  type(v2)=<class 'tuple'>
k1='fourc__reals'  k2='value'  type(v2)=<class 'tuple'>
k1='fourc__constraints'  k2='value'  type(v2)=<class 'numpy.ndarray'>
prjemian commented 6 months ago

The original issue has become a small part of this PR. Better to restart in new branch. There is a clear and simple way to resolve the original problem. The prior problems with failed unit tests that did not fail the CI workflow should be resolved in a separate PR.

Leave this branch and PR open until the new ones catch up with this.

prjemian commented 6 months ago
prjemian commented 6 months ago

Superseded by #317