Skip to content

docs: Document Guppy libraries#1552

Draft
maximilianruesch wants to merge 23 commits intomr/feat/compile-libraryfrom
mr/docs/document-libraries
Draft

docs: Document Guppy libraries#1552
maximilianruesch wants to merge 23 commits intomr/feat/compile-libraryfrom
mr/docs/document-libraries

Conversation

@maximilianruesch
Copy link
Copy Markdown
Collaborator

@maximilianruesch maximilianruesch commented Mar 6, 2026

Checkout, build with just build-docs and then open docs/build/library-docs/index.html in your favourite HTML renderer.

Closes #1548

@maximilianruesch maximilianruesch requested a review from ss2165 March 6, 2026 09:58
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.42%. Comparing base (88d36e5) to head (ff7df03).

Additional details and impacted files
@@                     Coverage Diff                     @@
##           mr/feat/compile-library    #1552      +/-   ##
===========================================================
- Coverage                    93.55%   93.42%   -0.13%     
===========================================================
  Files                          130      128       -2     
  Lines                        12364    12064     -300     
===========================================================
- Hits                         11567    11271     -296     
+ Misses                         797      793       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 6, 2026

🐰 Bencher Report

Branchmr/docs/document-libraries
TestbedLinux

🚨 7 Alerts

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_checkLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
699.23 ms
(+12.13%)Baseline: 623.62 ms
654.80 ms
(106.79%)

tests/benchmarks/test_big_array.py::test_big_array_compileLatency
seconds (s)
📈 plot
🚷 threshold
🚨 alert (🔔)
1.90 s
(+18.31%)Baseline: 1.61 s
1.69 s
(112.67%)

tests/benchmarks/test_big_array.py::test_big_array_executableLatency
seconds (s)
📈 plot
🚷 threshold
🚨 alert (🔔)
8.14 s
(+15.19%)Baseline: 7.06 s
7.42 s
(109.71%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_checkLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
49.71 ms
(+11.48%)Baseline: 44.59 ms
46.82 ms
(106.17%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compileLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
108.59 ms
(+12.44%)Baseline: 96.57 ms
101.40 ms
(107.09%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executableLatency
milliseconds (ms)
📈 plot
🚷 threshold
🚨 alert (🔔)
598.57 ms
(+11.33%)Baseline: 537.63 ms
564.51 ms
(106.03%)

tests/benchmarks/test_prelude.py::test_import_guppyLatency
microseconds (µs)
📈 plot
🚷 threshold
🚨 alert (🔔)
52.12 µs
(+26.05%)Baseline: 41.35 µs
43.41 µs
(120.05%)

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
🚨 view alert (🔔)
699,234.88 µs
(+12.13%)Baseline: 623,620.03 µs
654,801.03 µs
(106.79%)

tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
🚨 view alert (🔔)
1,899,484.90 µs
(+18.31%)Baseline: 1,605,537.14 µs
1,685,814.00 µs
(112.67%)

tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
🚨 view alert (🔔)
8,136,986.24 µs
(+15.19%)Baseline: 7,063,681.44 µs
7,416,865.51 µs
(109.71%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
🚨 view alert (🔔)
49,708.55 µs
(+11.48%)Baseline: 44,588.31 µs
46,817.72 µs
(106.17%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
🚨 view alert (🔔)
108,590.09 µs
(+12.44%)Baseline: 96,574.30 µs
101,403.02 µs
(107.09%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
🚨 view alert (🔔)
598,565.57 µs
(+11.33%)Baseline: 537,628.60 µs
564,510.03 µs
(106.03%)

tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
🚨 view alert (🔔)
52.12 µs
(+26.05%)Baseline: 41.35 µs
43.41 µs
(120.05%)

🐰 View full continuous benchmarking report in Bencher

Copy link
Copy Markdown
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

very helpful thank you

concerns additional ways to define (members of) a library, and automatically collect functions to be included in it.

A potential addition would be a `@guppy(export=...)` argument, that registers the function to be included in *the*
library in some global Guppy store (like the `DEF_STORE`). A function could then be included simply by adding that
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a "global library" is a bit confusing - this still would require some notion of a specific library the function is exported in. The string method below addresses this, but passing in library objects rather than strings seems preferable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This seems very similar to how GuppyModules were handled.

main.emulator(n_qubits=..., libraries=discover_hugr_packages()).with_shots(100).run()
```

Optionally, omission of `libraries` may lead to internal calls to automatic discovery, and other means of configuring
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what about instead just refer to library by name, which is then looked up in the discovered set, seems more familiar to the search path/-L mylib compiler CLI pattern

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think all three should be allowed (pass hugr, pass name (which is looked up), and passing nothing which means all known hugrs get thrown in).



# Choice 2, different syntax, same effect
@guppy(instances=[{T: int}, {T: float}, ...]) # may be unpacked, as QOL for manual specification
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

alternative, specify at point of library specification, and use existing type parameter syntax:

library = guppy.library(my_generic_func[int], my_generic_func[float])

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Potentially a lot more verbose, but would allow for different instances in different libraries, which is a win. Perhaps we can do / allow both?

# from package_a, package_b, and package_c
```

There are no guarantees about the order of modules being linked together, or whether that is pairwise or all at once.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we reject duplicate definitions then the order generally only affects what error is reported, rather than whether there is an error or what the resulting Hugr looks like in case of success, so fine :)


# In the future, keywords may be added to allow e.g. privatization of all
# functions from package_b (i.e. swallowing), so for example:
package_a.link(package_b, privatize=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or possibly something funky like package_a.link(Privatize(package_b), ReplaceFuncsWithExisting(package_c)) where Privatize/... have a type of LinkingDirective (i.e. are not funcs producing a Hugr/Package)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will leave that to be figured out by future implementors

@maximilianruesch maximilianruesch linked an issue Mar 10, 2026 that may be closed by this pull request
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.

[Docs]: Document Guppy libraries

4 participants