Skip to content

Commit

Permalink
change default ttno construction algo to QR
Browse files Browse the repository at this point in the history
  • Loading branch information
liwt31 committed Jul 19, 2024
1 parent 394ad22 commit 43cd801
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions renormalizer/mps/mpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def __init__(self, model: Model = None, terms: Union[Op, List[Op]] = None, offse

self.dtype = factor.dtype

mpo_symbol, self.qn, self.qntot, self.qnidx, self.symbolic_out_ops_list, self.primary_ops \
self.symbolic_mpo, self.qn, self.qntot, self.qnidx, self.symbolic_out_ops_list, self.primary_ops \
= construct_symbolic_mpo(table, factor, algo=algo)
# from renormalizer.mps.symbolic_mpo import _format_symbolic_mpo
# print(_format_symbolic_mpo(mpo_symbol))
Expand All @@ -285,7 +285,7 @@ def __init__(self, model: Model = None, terms: Union[Op, List[Op]] = None, offse
# evaluate the symbolic mpo
assert model.basis is not None

for impo, mo in enumerate(mpo_symbol):
for impo, mo in enumerate(self.symbolic_mpo):
mo_mat = symbolic_mo_to_numeric_mo(model.basis[impo], mo, self.dtype)
self.append(mo_mat)

Expand Down
2 changes: 1 addition & 1 deletion renormalizer/mps/symbolic_mpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def _decompose_qr(term_row, term_col, non_red, in_ops_list, factor, primary_ops,
"""
assert non_red.shape == (len(term_row), len(term_col))
assert k == 1

non_red.data = factor[non_red.data - 1]
gamma = non_red.todense()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def symbolic_mo_to_numeric_mo_general(basis_sets: List[BasisSet], mo, dtype):
return np.moveaxis(mo_tensor, mo.ndim - 1, -1)


def construct_symbolic_mpo(tn: BasisTree, terms: List[Op], const: float = 0):
algo = "Hopcroft-Karp"
def construct_symbolic_ttno(tn: BasisTree, terms: List[Op], const: float = 0, algo: str = "qr"):
nodes = tn.postorder_list()
basis = list(chain(*[n.basis_sets for n in nodes]))
model = Model(basis, [])
Expand Down
8 changes: 4 additions & 4 deletions renormalizer/tn/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from renormalizer.utils import calc_vn_entropy, calc_vn_entropy_dm
from renormalizer.tn.node import TreeNodeTensor, TreeNodeBasis, copy_connection, TreeNodeEnviron
from renormalizer.tn.treebase import Tree, BasisTree
from renormalizer.tn.symbolic_mpo import construct_symbolic_mpo, symbolic_mo_to_numeric_mo_general
from renormalizer.tn.symbolic_ttno import construct_symbolic_ttno, symbolic_mo_to_numeric_mo_general


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -138,19 +138,19 @@ def dummy(cls, basis: BasisTree):
basis.dummy_ttno = cls(new_basis, [new_basis.identity_op])
return basis.dummy_ttno

def __init__(self, basis: BasisTree, terms: Union[List[Op], Op], root: TreeNodeTensor = None):
def __init__(self, basis: BasisTree, terms: Union[List[Op], Op], root: TreeNodeTensor = None, algo: str = "qr"):
self.basis: BasisTree = basis
if isinstance(terms, Op):
terms = [terms]
self.terms: List[Op] = terms

if not root:
symbolic_mpo, mpoqn = construct_symbolic_mpo(basis, terms)
self.symbolic_ttno, mpoqn = construct_symbolic_ttno(basis, terms, algo=algo)
# from renormalizer.mps.symbolic_mpo import _format_symbolic_mpo
# print(_format_symbolic_mpo(symbolic_mpo))
node_list_basis = self.basis.postorder_list()
node_list_op = []
for impo, (mo, qn) in enumerate(zip(symbolic_mpo, mpoqn)):
for impo, (mo, qn) in enumerate(zip(self.symbolic_ttno, mpoqn)):
node_basis: TreeNodeBasis = node_list_basis[impo]
mo_mat = symbolic_mo_to_numeric_mo_general(node_basis.basis_sets, mo, backend.real_dtype)
node_list_op.append(TreeNodeTensor(mo_mat, qn))
Expand Down

0 comments on commit 43cd801

Please sign in to comment.