Skip to content

Temporary patch for skimage ArrayMap's read-only issues#260

Closed
n-wbrown wants to merge 2 commits intoroyerlab:mainfrom
n-wbrown:ro_arrays
Closed

Temporary patch for skimage ArrayMap's read-only issues#260
n-wbrown wants to merge 2 commits intoroyerlab:mainfrom
n-wbrown:ro_arrays

Conversation

@n-wbrown
Copy link

Hello,

First of all, thank you for all your hard work on ultrack and for making it freely available. It's a terrific tool and is really helping out with the research I'm working on.

I've encountered an issue with running track on my laptop but I've also put together a small fix for it. In short, passing read-only arrays to skimage's Arraymap in mip_solver.py causes Arraymap to throw exceptions. The skimage community recognizes the issue (scikit-image/scikit-image#6378) and the underlying cause appears to be cython. While the community did fix the issue very recently (scikit-image/scikit-image#7535) on the main branch, these changes have not made it to a release yet. As skimage can take many months between releases, this pull was flagged for 0.27 release, and skimage 0.26 just released in December of 2025, I'm unsure how long we will need to wait for this fix to make it to an official skimage release.

I recognize that there's a very similar PR right now (#252) being worked on by @JoOkuma and @macromeer. Given the similarity of these two PRs, feel free to close this one if it isn't deemed to be productive. There is a small difference in this one as I've fixed the issue by setting the writable flag of the numpy arrays to true rather than duplicating the arrays in memory.

Details on my system:
os: sequoia 15.7.3
chip: Apple M4

I've tested this in two environments, with these packages
Python: 3.12.8
cbc: stable 2.10.12 (bottled) (installed with brew)
numpy 2.3.5
scikit-image 0.26.0
ultrack 9a7084d

Python: 3.11.14
cbc: stable 2.10.12 (bottled) (installed with brew)
numpy 2.3.5
scikit-image 0.26.0
ultrack 0.7.1

When attempting to run track (from ultrack import track) I encountered a number of errors like the one shown in the test below.

___________ test_sql_tracking[config_content0-timelapse_mock_data0] ____________

linked_database_mock_data = MainConfig(data_config=DataConfig(n_workers=1, working_dir=PosixPath('/private/var/folders/3v/rkgm0_w93g1_l3j6lk59rgch...=36000, method=-1, link_function='identity', power=4, bias=-0.0, dismiss_weight_guess=None, include_weight_guess=None))

    @pytest.mark.parametrize(
        "config_content,timelapse_mock_data",
        _TEST_PARAMS,
        indirect=True,
    )
    def test_sql_tracking(
        linked_database_mock_data: MainConfig,
    ) -> None:
        config = linked_database_mock_data
>       solve(config)

ultrack/core/solve/_test/test_sql_tracking.py:63: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
ultrack/core/solve/processing.py:56: in solve
    tracker(index=batch_index, **kwargs)
ultrack/core/solve/sqltracking.py:111: in __call__
    self.construct_model(index)
ultrack/core/solve/sqltracking.py:79: in construct_model
    self._add_edges(solver=solver, index=index)
ultrack/core/solve/sqltracking.py:357: in _add_edges
    solver.add_edges(df["source_id"], df["target_id"], df["weight"])
ultrack/core/solve/solver/mip_solver.py:181: in add_edges
    sources = self._forward_map[np.asarray(sources, dtype=int, copy=True)]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/opt/anaconda3/envs/ultrack312-dev-0/lib/python3.12/site-packages/skimage/util/_map_array.py:184: in __getitem__
    out = map_array(
/opt/anaconda3/envs/ultrack312-dev-0/lib/python3.12/site-packages/skimage/util/_map_array.py:72: in map_array
    _map_array(input_arr, out_view, input_vals, output_vals)
skimage/util/_remap.pyx:11: in skimage.util._remap._map_array
    ???
<stringsource>:664: in View.MemoryView.memoryview_cwrapper
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   ValueError: buffer source array is read-only

<stringsource>:352: ValueError
---------------------------- Captured stderr setup -----------------------------

The test suite, with no changes results in this:

Results (198.90s):
        34 failed
       128 passed
        11 skipped
       193 warnings
        10 errors

With the changes:

Results (284.02s):
         4 failed
       167 passed
        11 skipped
       210 warnings
         1 error

@n-wbrown
Copy link
Author

See #252 for details. This will eventually be fixed by the skimage fixes.

@n-wbrown n-wbrown closed this Feb 17, 2026
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.

1 participant