Skip to content

Save and Load objects#778

Open
manuschneider wants to merge 16 commits into
masterfrom
save_load
Open

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

Conversation

@manuschneider

@manuschneider manuschneider commented Apr 11, 2026

Copy link
Copy Markdown
Collaborator
  • 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

codecov Bot commented Apr 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 31.87251% with 171 lines in your changes missing coverage. Please review.
✅ Project coverage is 30.06%. Comparing base (b3f9221) to head (ac9f3a2).
⚠️ Report is 4 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/backend/Storage.cpp 36.58% 16 Missing and 10 partials ⚠️
pybind/storage_py.cpp 16.00% 15 Missing and 6 partials ⚠️
pybind/tensor_py.cpp 12.50% 14 Missing and 7 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 ⚠️
src/Bond.cpp 60.00% 4 Missing and 2 partials ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #778      +/-   ##
==========================================
- Coverage   30.07%   30.06%   -0.01%     
==========================================
  Files         238      238              
  Lines       35405    35510     +105     
  Branches    14729    14765      +36     
==========================================
+ Hits        10648    10677      +29     
- Misses      17505    17573      +68     
- Partials     7252     7260       +8     
Flag Coverage Δ
cpp 29.57% <31.87%> (-0.01%) ⬇️
python 59.41% <ø> (ø)

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

Components Coverage Δ
C++ backend 31.30% <45.69%> (+0.04%) ⬆️
Python bindings 17.13% <11.00%> (-0.16%) ⬇️
Python package 59.41% <ø> (ø)
Files with missing lines Coverage Δ
include/Bond.hpp 63.94% <ø> (+0.68%) ⬆️
include/Symmetry.hpp 54.73% <ø> (ø)
include/Tensor.hpp 53.46% <ø> (+0.40%) ⬆️
include/UniTensor.hpp 47.84% <ø> (+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 32.76% <100.00%> (ø)
src/DenseUniTensor.cpp 50.28% <100.00%> (+0.05%) ⬆️
src/Type.cpp 0.00% <ø> (ø)
... and 16 more

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b3f9221...ac9f3a2. 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

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

Copy link
Copy Markdown

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
Member

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

manuschneider commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator Author

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.

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

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

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

pcchen commented May 31, 2026

Copy link
Copy Markdown
Collaborator

@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

pcchen commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

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