Added JSON serialisation for Lambda functions#1695
Open
bennthomsen wants to merge 10 commits intoQCoDeS:mainfrom
Open
Added JSON serialisation for Lambda functions#1695bennthomsen wants to merge 10 commits intoQCoDeS:mainfrom
bennthomsen wants to merge 10 commits intoQCoDeS:mainfrom
Conversation
for more information, see https://pre-commit.ci
…oadbean into JSONserialisation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1695 +/- ##
==========================================
- Coverage 72.12% 71.16% -0.97%
==========================================
Files 9 9
Lines 1539 1602 +63
==========================================
+ Hits 1110 1140 +30
- Misses 429 462 +33 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
astafan8
reviewed
Feb 3, 2026
Contributor
There was a problem hiding this comment.
why are there two duplicated(?) plots instead of one in this example? or is it github mis-rendering?
Author
There was a problem hiding this comment.
This seems to be working fine in VScode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Summary
Title: Added JSON serialization for Lambda functions
Description
This PR adds support for serializing and deserializing
BluePrintobjects that contain arbitrary functions (arb_func), including lambda functions and named functions, to/from JSON format.Changes
Files Modified:
src/broadbean/blueprint.py(+131 lines) - Core serialization/deserialization logictests/test_arb_func_serialization.py(+263 lines) - New comprehensive test suitetests/test_blueprint.py(+1 line) - Updated existing testKey Features
Lambda Function Serialization: Lambda functions used with
PulseAtoms.arb_funccan now be serialized to JSON by storing their source code, extracted usinginspect.getsource()with regex parsing.Named Function Serialization: Regular named functions are serialized with both their name and full source code, allowing reconstruction even in different Python sessions.
Graceful Fallbacks: When functions cannot be reconstructed (e.g., missing dependencies or invalid source), the system falls back to a zero function with appropriate warnings.
Sample Rate Persistence: The
SR(sample rate) property is now included in the blueprint description and restored during deserialization.Backward Compatibility: Legacy JSON formats without the new
func_typefield are still supported.Usage Example
Example with a named function:
Technical Details
Serialization (
descriptionproperty):arb_funcsegments and extracts function informationDeserialization (
blueprint_from_description):eval()Testing
Added comprehensive test suite (
test_arb_func_serialization.py) covering:Breaking Changes
None - existing functionality and JSON format remains compatible.