Browse code

apply a minor refactor to 'hamiltonian_term'

We now construct the site arrays to pass to 'val' in a single
place (this is more readable).

Joseph Weston authored on 03/12/2019 15:07:02
Showing 1 changed files
... ...
@@ -2087,10 +2087,12 @@ class _VectorizedFinalizedBuilderMixin(_FinalizedBuilderMixin):
2087 2087
         to_family = self.site_arrays[to_which].family
2088 2088
         to_tags = self.site_arrays[to_which].tags
2089 2089
         to_site_array = SiteArray(to_family, to_tags[to_off])
2090
+        site_arrays = (to_site_array,)
2090 2091
         if not is_onsite:
2091 2092
             from_family = self.site_arrays[from_which].family
2092 2093
             from_tags = self.site_arrays[from_which].tags
2093 2094
             from_site_array = SiteArray(from_family, from_tags[from_off])
2095
+            site_arrays = self.symmetry.to_fd(to_site_array, from_site_array)
2094 2096
 
2095 2097
         # Construct args from params
2096 2098
         if params:
... ...
@@ -2107,20 +2109,10 @@ class _VectorizedFinalizedBuilderMixin(_FinalizedBuilderMixin):
2107 2109
                        ', '.join(map('"{}"'.format, missing)))
2108 2110
                 raise TypeError(''.join(msg))
2109 2111
 
2110
-        if is_onsite:
2111
-            try:
2112
-                ham = val(to_site_array, *args)
2113
-            except Exception as exc:
2114
-                _raise_user_error(exc, val)
2115
-        else:
2116
-            try:
2117
-                ham = val(
2118
-                        *self.symmetry.to_fd(
2119
-                            to_site_array,
2120
-                            from_site_array),
2121
-                        *args)
2122
-            except Exception as exc:
2123
-                _raise_user_error(exc, val)
2112
+        try:
2113
+            ham = val(*site_arrays, *args)
2114
+        except Exception as exc:
2115
+            _raise_user_error(exc, val)
2124 2116
 
2125 2117
         expected_shape = (
2126 2118
             len(to_site_array),