Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
93abc1d
updated comments and cleaned up debug lines
manuschneider Jun 13, 2025
74b8822
updated method descriptions for UniTensor, added warnings where users…
manuschneider Jun 13, 2025
6bc73d8
fixed old buggy version of _swapsigns_(const std::vector<cytnx_int64>…
manuschneider Jun 13, 2025
1038410
implemented fermion twists (or self-swaps) on one leg, and on all bra…
manuschneider Jun 13, 2025
e47b859
moved implementation of twists from UniTensor_base to the implementat…
manuschneider Jun 16, 2025
f244159
-fixed bug when adding or subtracting fermionic tensors
manuschneider Jun 16, 2025
5b9daf3
fixed pybind to return handles for inline functions
manuschneider Jun 17, 2025
3afc022
for fermionic tensors: Transpose (and thus also Dagger) changes the r…
manuschneider Jun 17, 2025
f6ee7e7
Merge commit '9efeffc25b5c03bc29704507372ac1afdf2b4e7f' into fermion_…
manuschneider Nov 3, 2025
06f03fa
Merge branch 'master' into fermion_twist
manuschneider Nov 3, 2025
9170865
Merge commit 'cbdeebf53da122969e74026711bd4244fdafe9d5' into fermion_…
manuschneider Nov 3, 2025
75edd6a
error with line endings in docs folder
manuschneider Nov 3, 2025
e681095
Merge commit '59a86466ee71c7e9da06d148aea7eac9ba93b087' into fermion_…
manuschneider Nov 3, 2025
b7807fd
Merge remote-tracking branch 'origin/master' into fermion_twist
manuschneider Nov 3, 2025
66e21f0
Merge remote-tracking branch 'origin/master' into fermion_twist
manuschneider Nov 14, 2025
099f0aa
Merge remote-tracking branch 'master' into fermion_twist
manuschneider Dec 3, 2025
74caf0d
fixed merge issue
manuschneider Dec 3, 2025
ba15358
added gtests
manuschneider Feb 12, 2026
9f61643
fixed issues:
manuschneider Mar 30, 2026
553d75d
improved and unified error messages
manuschneider Mar 30, 2026
79ea299
Merge remote-tracking branch 'master' into fermion_twist
manuschneider Mar 30, 2026
2a39193
Merge remote-tracking branch 'master' into fermion_twist
manuschneider Apr 9, 2026
ccf0ab7
fixed issues:
manuschneider Apr 11, 2026
f298349
Merge master into fermion_twist, resolving conflicts in unitensor_py.cpp
pcchen Apr 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/code/python/outputs/guide_uniten_tagged_contract.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Cytnx error occur at virtual boost::intrusive_ptr<cytnx::UniTensor_base> cytnx::DenseUniTensor::contract(const boost::intrusive_ptr<cytnx::UniTensor_base>&, const bool&, const bool&)
# error: [ERROR][DenseUniTensor][contract] cannot contract common label: <c> @ self bond#2 & rhs bond#0, BRA-KET mismatch!
# error: [ERROR][DenseUniTensor][contract] Cannot contract common label: <c> @ self bond#2 & rhs bond#0, BRA-KET mismatch!

# file : /home/hunghaoti/Workplace/Cytnx_dir/Cytnx_dev/src/DenseUniTensor.cpp (994)
6 changes: 3 additions & 3 deletions include/Accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace cytnx {
};

static Accessor tilend(const cytnx_int64 &min, const cytnx_int64 &step = 1) {
cytnx_error_msg(step == 0, "[ERROR] cannot have _step=0 for tilend%s", "\n");
cytnx_error_msg(step == 0, "[ERROR] Cannot have _step=0 for tilend%s", "\n");
Accessor out;
out._type = Accessor::Tilend;
out._min = min;
Expand All @@ -139,7 +139,7 @@ namespace cytnx {
};

static Accessor step(const cytnx_int64 &step) {
cytnx_error_msg(step == 0, "[ERROR] cannot have _step=0 for _step%s", "\n");
cytnx_error_msg(step == 0, "[ERROR] Cannot have _step=0 for _step%s", "\n");
Accessor out;
out._type = Accessor::Step;
// out._min = 0;
Expand All @@ -148,7 +148,7 @@ namespace cytnx {
};

static Accessor qns(const std::vector<std::vector<cytnx_int64>> &qns) {
cytnx_error_msg(qns.size() == 0, "[ERROR] cannot have empty qnums.%s", "\n");
cytnx_error_msg(qns.size() == 0, "[ERROR] Cannot have empty qnums.%s", "\n");
Accessor out;

out._type = Accessor::Qns;
Expand Down
6 changes: 3 additions & 3 deletions include/Bond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ namespace cytnx {
if ((this->_type != BD_REG)) {
if (new_bondType == BD_REG) {
cytnx_error_msg(this->_qnums.size(),
"[ERROR] cannot change type to BD_REG for a symmetry bond.%s", "\n");
"[ERROR] Cannot change type to BD_REG for a symmetry bond.%s", "\n");
}
if (std::abs(int(this->_type)) != std::abs(int(new_bondType))) {
cytnx_error_msg(this->_qnums.size(),
"[ERROR] cannot exchange BDtype between BD_* <-> gBD_* .%s", "\n");
"[ERROR] Cannot exchange BDtype between BD_* <-> gBD_* .%s", "\n");
}
}

Expand All @@ -106,7 +106,7 @@ namespace cytnx {

void clear_type() {
if (this->_type != BD_REG) {
cytnx_error_msg(this->_qnums.size(), "[ERROR] cannot clear type for a symmetry bond.%s",
cytnx_error_msg(this->_qnums.size(), "[ERROR] Cannot clear type for a symmetry bond.%s",
"\n");
}
this->_type = bondType::BD_REG;
Expand Down
2 changes: 1 addition & 1 deletion include/LinOp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace cytnx {
cytnx_error_msg(dtype<1 || dtype >= N_Type,"[ERROR] invalid dtype.%s","\n");
this->_dtype = dtype;
}else{
cytnx_error_msg(true,"[ERROR] cannot specify func with type=mv_elem%s. use set_elem
cytnx_error_msg(true,"[ERROR] Cannot specify func with type=mv_elem%s. use set_elem
instead.","\n");
}
};
Expand Down
292 changes: 232 additions & 60 deletions include/UniTensor.hpp

Large diffs are not rendered by default.

216 changes: 108 additions & 108 deletions include/backend/Scalar.hpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions include/tn_algo/MPS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,20 @@ namespace cytnx {
void Init_Msector(const cytnx_uint64 &N, const std::vector<cytnx_uint64> &phys_dim,
const cytnx_uint64 &virt_dim, const std::vector<cytnx_int64> &select,
const cytnx_int64 &dtype) {
cytnx_error_msg(true, "[ERROR][MPS][type=iMPS] cannot call Init_Msector%s", "\n");
cytnx_error_msg(true, "[ERROR][MPS][type=iMPS] Cannot call Init_Msector%s", "\n");
}
// void Init_prodstate(const std::vector<cytnx_uint64> &phys_dim, const
// std::vector<cytnx_uint64> cstate, const cytnx_int64 &dtype);
// cytnx_error_msg(true,"[ERROR][MPS][type=iMPS] cannot call prodstate%s","\n");
// cytnx_error_msg(true,"[ERROR][MPS][type=iMPS] Cannot call prodstate%s","\n");
// }
void Into_Lortho() {
cytnx_error_msg(true, "[ERROR][MPS][type=iMPS] cannot call Into_Lortho%s", "\n");
cytnx_error_msg(true, "[ERROR][MPS][type=iMPS] Cannot call Into_Lortho%s", "\n");
}
void S_mvleft() {
cytnx_error_msg(true, "[ERROR][MPS][type=iMPS] cannot call S_mvleft%s", "\n");
cytnx_error_msg(true, "[ERROR][MPS][type=iMPS] Cannot call S_mvleft%s", "\n");
}
void S_mvright() {
cytnx_error_msg(true, "[ERROR][MPS][type=iMPS] cannot call S_mvright%s", "\n");
cytnx_error_msg(true, "[ERROR][MPS][type=iMPS] Cannot call S_mvright%s", "\n");
}
boost::intrusive_ptr<MPS_impl> clone() const {
boost::intrusive_ptr<MPS_impl> out(new RegularMPS());
Expand Down
4 changes: 2 additions & 2 deletions include/utils/vec_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace cytnx {
template <class T>
void vec_tofile(const std::string &filepath, const std::vector<T> &in) {
std::fstream f(filepath, std::ios::out | std::ios::binary);
cytnx_error_msg(!f.is_open(), "[ERROR][vec_tofile] cannot open filepath: %s\n", filepath);
cytnx_error_msg(!f.is_open(), "[ERROR][vec_tofile] Cannot open filepath: %s\n", filepath);
vec_tofile(f, in);
f.close();
}
Expand All @@ -31,7 +31,7 @@ namespace cytnx {
template <class T>
std::vector<T> vec_fromfile(const std::string &filepath) {
std::fstream f(filepath, std::ios::in | std::ios::binary);
cytnx_error_msg(!f.is_open(), "[ERROR][vec_fromfile] cannot open filepath: %s\n", filepath);
cytnx_error_msg(!f.is_open(), "[ERROR][vec_fromfile] Cannot open filepath: %s\n", filepath);
auto fsize = FileSize(filepath.c_str());
cytnx_error_msg(fsize % sizeof(T),
"[ERROR][vec_fromfile] the total size of file %lu is not multiple of size %lu "
Expand Down
26 changes: 19 additions & 7 deletions pybind/unitensor_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void unitensor_binding(py::module &m) {
"[ERROR] try to getitem from a empty UniTensor%s", "\n");
cytnx_error_msg(
self.uten_type() != UTenType.Dense,
"[ERROR] cannot get element using [] from Block/SparseUniTensor. Use at() instead.%s", "\n");
"[ERROR] Cannot get element using [] from Block/SparseUniTensor. Use at() instead.%s", "\n");

auto accessors = build_accessors(self, locators);
return self.get(accessors);
Expand All @@ -406,7 +406,7 @@ void unitensor_binding(py::module &m) {
"[ERROR] try to setelem to a empty UniTensor%s", "\n");
cytnx_error_msg(
self.uten_type() == UTenType.Sparse,
"[ERROR] cannot set element using [] from SparseUniTensor. Use at() instead.%s", "\n");
"[ERROR] Cannot set element using [] from SparseUniTensor. Use at() instead.%s", "\n");

auto accessors = build_accessors(self, locators);
self.set(accessors, rhs);
Expand Down Expand Up @@ -507,7 +507,7 @@ void unitensor_binding(py::module &m) {
[](UniTensor &self, const cytnx_int64 &device) {
cytnx_error_msg(self.device() == device,
"[ERROR][pybind][to_diffferent_device] same device for to() should be "
"handle in python side.%s",
"handled on the Python side.%s",
"\n");
return self.to(device);
},
Expand Down Expand Up @@ -557,15 +557,27 @@ void unitensor_binding(py::module &m) {
return self.permute_nosignflip(mapper,rowrank);
},py::arg("mapper"), py::arg("rowrank")=(cytnx_int64)(-1))
.def("permute_nosignflip_", [](UniTensor &self, const std::vector<cytnx_int64> &mapper, const cytnx_int64 &rowrank){
self.permute_nosignflip_(mapper,rowrank);
return self.permute_nosignflip_(mapper,rowrank);
Comment on lines 559 to +560
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Return self by reference in chainable pybind wrappers

These new in-place bindings return from lambdas without an explicit return type, so C++ deduces auto as UniTensor (by value) rather than UniTensor&. That means self.permute_nosignflip_(...)/self.twist_(...) mutate self but then return a copy, so chained calls execute on a temporary copy instead of the original object unless the caller reassigns (e.g. u.permute_nosignflip_(...).twist_()). Use an explicit -> UniTensor& return type (and reference return policy) for these overload lambdas.

Useful? React with 👍 / 👎.

},py::arg("mapper"), py::arg("rowrank")=(cytnx_int64)(-1))

.def("permute_nosignflip_", [](UniTensor &self, const std::vector<std::string> &mapper, const cytnx_int64 &rowrank){
self.permute_nosignflip_(mapper,rowrank);
return self.permute_nosignflip_(mapper,rowrank);
},py::arg("mapper"), py::arg("rowrank")=(cytnx_int64)(-1))



.def("twist", [](UniTensor &self, const cytnx_int64 &idx){
return self.twist(idx);
},py::arg("idx"))
.def("twist", [](UniTensor &self, const std::string label){
return self.twist(label);
},py::arg("label"))
.def("twist_", [](UniTensor &self, const cytnx_int64 &idx){
return self.twist_(idx);
},py::arg("idx"))
.def("twist_", [](UniTensor &self, const std::string label){
return self.twist_(label);
},py::arg("label"))
.def("fermion_twists", &UniTensor::fermion_twists)
.def("fermion_twists_", &UniTensor::fermion_twists_)

.def("make_contiguous", &UniTensor::contiguous)
.def("contiguous_", &UniTensor::contiguous_)
Expand Down
2 changes: 1 addition & 1 deletion src/Accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace cytnx {

// range constr.
Accessor::Accessor(const cytnx_int64 &min, const cytnx_int64 &max, const cytnx_int64 &step) {
cytnx_error_msg(step == 0, "[ERROR] cannot have step=0 for range%s", "\n");
cytnx_error_msg(step == 0, "[ERROR] Cannot have step=0 for range%s", "\n");
this->_type = Accessor::Range;
this->_min = min;
this->_max = max;
Expand Down
Loading
Loading