guppylang icon indicating copy to clipboard operation
guppylang copied to clipboard

feat: Add unsafe array take and put operations

Open mark-koch opened this issue 5 months ago • 3 comments

I'm reluctant to add this, but this should remove the need for people to use option-arrays.

Questions:

  • Is put a good name?
  • Should the names include an _unsafe suffix?

mark-koch avatar Aug 07 '25 10:08 mark-koch

Codecov Report

:x: Patch coverage is 87.30159% with 8 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 93.55%. Comparing base (495aba5) to head (1b3bc7b). :warning: Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
guppylang/src/guppylang/std/array.py 61.90% 8 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1165      +/-   ##
==========================================
- Coverage   93.59%   93.55%   -0.04%     
==========================================
  Files         128      128              
  Lines       11451    11503      +52     
==========================================
+ Hits        10717    10762      +45     
- Misses        734      741       +7     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Aug 07 '25 10:08 codecov-commenter

This is waiting on an updated implementation using borrow array, which requires a "check" HUGR operation https://github.com/CQCL/hugr/issues/2569

ss2165 avatar Sep 23 '25 08:09 ss2165

My main comment is that this makes the analysis for borrow-return "squashing" substantially harder (and/or less effective). See https://github.com/CQCL/tket2/pull/1159 . Doesn't mean we can't do this, but we may want to hold off.

UPDATE: I've reduced scope of that squashing meaning that it is now "safe" even given this PR, although https://github.com/CQCL/tket2/issues/1176 would still be useful (not essential).

acl-cqc avatar Oct 12 '25 18:10 acl-cqc

🐰 Bencher Report

Branchfeat/array-unsafe
TestbedLinux
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_check📈 view plot
🚷 view threshold
686,313.06 µs
(-7.28%)Baseline: 740,166.66 µs
777,174.99 µs
(88.31%)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
1,636,192.38 µs
(+3.93%)Baseline: 1,574,284.68 µs
1,652,998.92 µs
(98.98%)
tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
7,392,575.38 µs
(+1.45%)Baseline: 7,287,270.12 µs
7,651,633.63 µs
(96.61%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
50,534.84 µs
(-33.16%)Baseline: 75,604.05 µs
79,384.25 µs
(63.66%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
90,098.21 µs
(+1.61%)Baseline: 88,672.51 µs
93,106.13 µs
(96.77%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
603,180.49 µs
(+1.00%)Baseline: 597,223.46 µs
627,084.63 µs
(96.19%)
tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
49.95 µs
(-3.03%)Baseline: 51.51 µs
54.09 µs
(92.36%)
🐰 View full continuous benchmarking report in Bencher

github-actions[bot] avatar Dec 16 '25 11:12 github-actions[bot]

🐰 Bencher Report

Branchfeat/array-unsafe
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes
(Result Δ%)
Upper Boundary
nodes
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
143.70 x 1e3
(0.00%)Baseline: 143.70 x 1e3
145.13 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
6,590.00
(0.00%)Baseline: 6,590.00
6,655.90
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
21.67 x 1e3
(0.00%)Baseline: 21.67 x 1e3
21.89 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
606.00
(0.00%)Baseline: 606.00
612.06
(99.01%)
🐰 View full continuous benchmarking report in Bencher

github-actions[bot] avatar Dec 16 '25 11:12 github-actions[bot]

What should be the suffix for the panicking versions?

How about making put and take the panicking versions and make the fallible versions try_take and try_put ?

ss2165 avatar Dec 17 '25 13:12 ss2165

How about making put and take the panicking versions and make the fallible versions try_take and try_put ?

Actually, that sounds like a good option 👍

mark-koch avatar Dec 17 '25 13:12 mark-koch