Skip to content

Commit

Permalink
add support for tat v0.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhangxyz committed Nov 17, 2023
1 parent 87c1215 commit 7ecbe29
Show file tree
Hide file tree
Showing 60 changed files with 86 additions and 82 deletions.
29 changes: 14 additions & 15 deletions tetragono/tetragono/abstract_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ def Edge(self):
type
The edge type of this abstract state.
"""
return self.Tensor.model.Edge
# Get the compat edge constructor.
return self.Tensor.__self__.symmetry.Edge

@property
def Symmetry(self):
Expand All @@ -229,7 +230,8 @@ def Symmetry(self):
type
The symmetry type of this abstract state.
"""
return self.Tensor.model.Symmetry
# Group all input into a tuple
return staticmethod(lambda *args: args[0] if args and isinstance(args[0], tuple) else args)

def _v2_to_v3_rename(self, state):
"""
Expand Down Expand Up @@ -328,10 +330,8 @@ def _construct_symmetry(self, value):
Symmetry
The result symmetry object.
"""
if isinstance(value, self.Symmetry):
return value
else:
return self.Symmetry(value)
# Symmetry is nothing but a tuple wrapper
return self.Symmetry(value)

@property
def total_symmetry(self):
Expand Down Expand Up @@ -367,7 +367,7 @@ def _total_symmetry_edge(self):
Edge
The result virtual edge.
"""
return self.Edge([(-self._total_symmetry, 1)], False)
return self.Edge([(self._total_symmetry, 1)], False).conjugate()

def _construct_edge(self, value):
"""
Expand All @@ -383,10 +383,8 @@ def _construct_edge(self, value):
Edge
The result edge object.
"""
if isinstance(value, self.Edge):
return value
else:
return self.Edge(value)
# Edge accept argument with type Edge. So previous condition is not needed.
return self.Edge(value)

def _construct_physics_edge(self, edge):
"""
Expand Down Expand Up @@ -444,13 +442,14 @@ def _set_hamiltonian(self, points, tensor):
The hamiltonian tensor.
"""
body = len(points)
if not isinstance(tensor, self.Tensor):
raise TypeError("Wrong hamiltonian type")
# Do not check hamiltonian type temporarily
#if not isinstance(tensor, self.Tensor):
# raise TypeError("Wrong hamiltonian type")
if {f"{i}" for i in tensor.names} != {f"{i}{j}" for i in ["I", "O"] for j in range(body)}:
raise ValueError("Wrong hamiltonian name")
for i in range(body):
edge_out = tensor.edges(f"O{i}")
edge_in = tensor.edges(f"I{i}")
edge_out = tensor.edge_by_name(f"O{i}")
edge_in = tensor.edge_by_name(f"I{i}")
if edge_out != self.physics_edges[points[i]]:
raise ValueError("Wrong hamiltonian edge")
if edge_out.conjugated() != edge_in:
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/common_tensor/Fermi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
from .tensor_toolkit import Fedge, Tedge, rename_io

Tensor = TAT.Fermi.Z.Tensor
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/common_tensor/FermiFermi_Hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
from .tensor_toolkit import Fedge, Tedge, rename_io

Tensor = TAT.FermiFermi.Z.Tensor
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/common_tensor/FermiU1_Hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
from .tensor_toolkit import Fedge, Tedge, rename_io

Tensor = TAT.FermiU1.Z.Tensor
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/common_tensor/FermiU1_tJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
from .tensor_toolkit import Fedge, Tedge, rename_io

Tensor = TAT.FermiU1.Z.Tensor
Expand Down
22 changes: 13 additions & 9 deletions tetragono/tetragono/common_tensor/No.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
from .tensor_toolkit import rename_io, kronecker_product

Tensor = TAT.No.Z.Tensor

identity = Tensor(["I0", "O0"], [2, 2])
identity.blocks[identity.names] = [[1, 0], [0, 1]]
identity = Tensor(["I0", "O0"], [2, 2]).zero()
identity[{"I0": 0, "O0": 0}] = 1
identity[{"I0": 1, "O0": 1}] = 1

pauli_x = Tensor(["I0", "O0"], [2, 2])
pauli_x.blocks[pauli_x.names] = [[0, 1], [1, 0]]
pauli_x = Tensor(["I0", "O0"], [2, 2]).zero()
pauli_x[{"I0": 0, "O0": 1}] = 1
pauli_x[{"I0": 1, "O0": 0}] = 1
Sx = pauli_x / 2

pauli_y = Tensor(["I0", "O0"], [2, 2])
pauli_y.blocks[pauli_y.names] = [[0, -1j], [1j, 0]]
pauli_y = Tensor(["I0", "O0"], [2, 2]).zero()
pauli_y[{"I0": 0, "O0": 1}] = -1j
pauli_y[{"I0": 1, "O0": 0}] = +1j
Sy = pauli_y / 2

pauli_z = Tensor(["I0", "O0"], [2, 2])
pauli_z.blocks[pauli_z.names] = [[1, 0], [0, -1]]
pauli_z = Tensor(["I0", "O0"], [2, 2]).zero()
pauli_z[{"I0": 0, "O0": 0}] = +1
pauli_z[{"I0": 1, "O0": 1}] = -1
Sz = pauli_z / 2

pauli_x_pauli_x = kronecker_product(
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/common_tensor/Parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
from .tensor_toolkit import Fedge, Tedge, rename_io

Tensor = TAT.Parity.Z.Tensor
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/sampling_lattice/gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import signal
from datetime import datetime
import numpy as np
import TAT
from tat import compat as TAT
from ..sampling_lattice import SamplingLattice, Observer, SweepSampling, ErgodicSampling, DirectSampling
from ..utility import (show, showln, mpi_rank, mpi_size, SignalHandler, seed_differ, lattice_randomize, write_to_file,
get_imported_function, restrict_wrapper, bcast_number, write_configurations)
Expand Down
3 changes: 2 additions & 1 deletion tetragono/tetragono/sampling_lattice/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import os
import numpy as np
import PyScalapack
# PyScalapack support should be dropped, I think...
#import PyScalapack
from ..utility import (show, showln, allreduce_lattice_buffer, allreduce_buffer, allreduce_number, bcast_buffer,
lattice_update, lattice_prod_sum, lattice_conjugate, mpi_rank, mpi_size, mpi_comm, pickle)
from ..tensor_element import tensor_element
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/sampling_lattice/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#

import numpy as np
import TAT
from tat import compat as TAT
from ..auxiliaries import DoubleLayerAuxiliaries, ThreeLineAuxiliaries
from ..utility import mpi_rank, mpi_size
from ..tensor_element import tensor_element
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import cmd
from io import StringIO
import numpy as np
import TAT
from tat import compat as TAT
from .utility import (mpi_rank, mpi_size, mpi_comm, write_to_file, read_from_file, show, showln, seed_differ,
get_imported_function, allgather_array, restrict_wrapper, write_configurations,
read_configurations)
Expand Down
2 changes: 1 addition & 1 deletion tetragono/tetragono/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import importlib.machinery
from mpi4py import MPI
import numpy as np
import TAT
from tat import compat as TAT

clear_line = "\u001b[2K"

Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/J1J2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/J1J2/pbc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/bcs/square/d_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/bcs/square/s_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/boson_metal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/boson_metal/hopping_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/boson_metal/initial_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/cluster_heisenberg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/cluster_heisenberg/pbc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/free_fermion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/free_fermion/complex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/gibbs_free_fermion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet
from tetragono.common_tensor.tensor_toolkit import half_reverse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet
from tetragono.common_tensor.Parity import *
from tetragono.common_tensor.tensor_toolkit import rename_io, kronecker_product, half_reverse
Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/gibbs_heisenberg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
2 changes: 1 addition & 1 deletion tetraku/tetraku/models/gibbs_hubbard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet
from tetragono.common_tensor.tensor_toolkit import half_reverse

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet
from tetragono.common_tensor.Parity import *
from tetragono.common_tensor.tensor_toolkit import rename_io, kronecker_product, half_reverse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#

import TAT
from tat import compat as TAT
import tetragono as tet
from tetragono.common_tensor.Parity import *
from tetragono.common_tensor.tensor_toolkit import rename_io, kronecker_product, half_reverse
Expand Down
Loading

0 comments on commit 7ecbe29

Please sign in to comment.