Skip to content

Save and Load objects#778

Open
manuschneider wants to merge 14 commits into
masterfrom
save_load
Open

Save and Load objects#778
manuschneider wants to merge 14 commits into
masterfrom
save_load

Conversation

@manuschneider
Copy link
Copy Markdown
Collaborator

@manuschneider manuschneider commented Apr 11, 2026

  • Pickle support
  • HDF5 support

addresses #157 and #660

The Pickle support can already be checked and merged at this stage, and HDF5 can be implemented subsequently (check #660 for this).

…ethods: to_binary(std::ostream) and from_binary(std::istream)

Clearer separation: Save and Load handle file IO, while to_binary and from_binary only write to ostream or istream
implementation classes provide to_binary_dispatch(std::ostream) and from_binary_dispatch(std::istream)
…ectly because the char* is not terminated by \0. Potentially illegal memory access
@manuschneider manuschneider changed the title Save and Load complex data Save and Load objects Apr 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 11, 2026

Codecov Report

❌ Patch coverage is 29.92701% with 192 lines in your changes missing coverage. Please review.
✅ Project coverage is 29.03%. Comparing base (03b3901) to head (2962ec1).
⚠️ Report is 48 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/backend/Storage.cpp 34.88% 17 Missing and 11 partials ⚠️
pybind/storage_py.cpp 16.00% 15 Missing and 6 partials ⚠️
pybind/tensor_py.cpp 12.50% 14 Missing and 7 partials ⚠️
pybind/tnalgo_py.cpp 9.52% 15 Missing and 4 partials ⚠️
pybind/symmetry_py.cpp 0.00% 13 Missing and 3 partials ⚠️
pybind/unitensor_py.cpp 15.78% 12 Missing and 4 partials ⚠️
pybind/bond_py.cpp 6.25% 12 Missing and 3 partials ⚠️
src/tn_algo/MPS.cpp 0.00% 15 Missing ⚠️
src/Tensor.cpp 47.05% 5 Missing and 4 partials ⚠️
src/Symmetry.cpp 20.00% 8 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #778      +/-   ##
==========================================
+ Coverage   28.91%   29.03%   +0.12%     
==========================================
  Files         240      240              
  Lines       35505    35643     +138     
  Branches    14794    14851      +57     
==========================================
+ Hits        10265    10350      +85     
- Misses      18078    18105      +27     
- Partials     7162     7188      +26     
Flag Coverage Δ
cpp 28.65% <29.92%> (+0.13%) ⬆️
python 51.07% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
C++ backend 30.33% <45.09%> (+0.21%) ⬆️
Python bindings 16.72% <10.74%> (-0.17%) ⬇️
Python package 51.07% <ø> (ø)
Files with missing lines Coverage Δ
include/Bond.hpp 63.26% <ø> (+0.68%) ⬆️
include/Symmetry.hpp 54.73% <ø> (ø)
include/Tensor.hpp 53.25% <ø> (+0.40%) ⬆️
include/UniTensor.hpp 47.59% <ø> (+0.12%) ⬆️
include/backend/Storage.hpp 80.95% <100.00%> (-0.12%) ⬇️
include/backend/Tensor_impl.hpp 65.89% <ø> (ø)
include/tn_algo/MPS.hpp 0.00% <ø> (ø)
src/BlockFermionicUniTensor.cpp 31.43% <100.00%> (ø)
src/DenseUniTensor.cpp 50.05% <100.00%> (+0.05%) ⬆️
src/Type.cpp 0.00% <ø> (ø)
... and 17 more

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03b3901...2962ec1. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@manuschneider manuschneider added the Pending check/approval Issue fixed, and need feedback label Apr 22, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c00d2384da

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/backend/Storage.cpp Outdated
Comment thread src/Tensor.cpp Outdated
Comment thread src/tn_algo/MPS.cpp Outdated
@IvanaGyro
Copy link
Copy Markdown
Collaborator

The C++ coding style we use uses PascalCase for function names. We should be consistent with it for the new functions especially the functions in the changing files have already follow the coding style.

@manuschneider
Copy link
Copy Markdown
Collaborator Author

manuschneider commented Apr 28, 2026

The C++ coding style we use uses PascalCase for function names. We should be consistent with it for the new functions especially the functions in the changing files have already follow the coding style.

I checked the Cytnx API. We use one-word names, both upper- and lowercase (Save, permute). For longer names, we use snake_case (set_name), and I even found one outlier with camelCase (combineBonds).
I agree that we should be more consistent.

But I suggest deviating from Google's style guide here, because I could not find any instance where we currently use PascalCase for functions or methods, and we should not introduce yet another convention for new functions. Another reason to deviate from Google style guide is that we want to have a consistent API on Python and C++. In Python, snake_case is recommended for function names, and therefore I would also suggest this for our API (and because we already use it a lot).

I renamed some functions in this branch because they started with an underscore (which should be avoided) and did not have very meaningful names (e.g.,_Save -> to_binary).

We should discuss this in #836 instead.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64b25e4bc0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/Bond.cpp
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19ac5b06f8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pybind/tensor_py.cpp Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13ad2a01c2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/Bond.cpp
Comment thread src/UniTensor.cpp
@manuschneider manuschneider removed the Pending check/approval Issue fixed, and need feedback label May 26, 2026
@manuschneider manuschneider added the Pending check/approval Issue fixed, and need feedback label May 30, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b9a36200cf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread pybind/tnalgo_py.cpp Outdated
@manuschneider
Copy link
Copy Markdown
Collaborator Author

This can be checked and merged, HDF5 will be addressed in another PR (#783).

@pcchen
Copy link
Copy Markdown
Collaborator

pcchen commented May 31, 2026

@manuschneider I plan to deal with this PR after we relase v1.1.0, do you agree?

@pcchen pcchen added this to the v1.2.0 milestone Jun 1, 2026
@pcchen
Copy link
Copy Markdown
Collaborator

pcchen commented Jun 1, 2026

I will take this PR with milestone v1.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex Pending check/approval Issue fixed, and need feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants