Skip to content

Commit a908887

Browse files
committed
Add function for semi positive block and random noise to varipeps.utils.random
1 parent 0c67a8d commit a908887

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

varipeps/utils/random.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,33 @@ def positive_block(
180180
if normalize:
181181
block /= jnp.linalg.norm(block)
182182
return block
183+
184+
def semi_positive_block(
185+
self, dim: Sequence[int], dtype: Type[np.number], *, normalize: bool = True
186+
) -> jnp.ndarray:
187+
if jnp.dtype(dtype) is jnp.dtype(jnp.complex64) or jnp.dtype(
188+
dtype
189+
) is jnp.dtype(jnp.complex128):
190+
self.key, key1, key2 = jax.random.split(self.key, 3)
191+
block = jax.random.uniform(key1, dim, minval=-0.3, maxval=1).astype(
192+
dtype
193+
) + 1j * jax.random.uniform(key2, dim, minval=-0.3, maxval=1).astype(dtype)
194+
else:
195+
self.key, key1 = jax.random.split(self.key, 2)
196+
block = jax.random.uniform(key1, dim, dtype=dtype, minval=-0.3, maxval=1)
197+
if normalize:
198+
block /= jnp.linalg.norm(block)
199+
return block
200+
201+
202+
def apply_random_noise_unitcell(unitcell, relative_amplitude=1e-3):
203+
rng = PEPS_Random_Number_Generator.get_generator()
204+
205+
def random_noise(a):
206+
return a + a * rng.block(a.shape, dtype=a.dtype) * relative_amplitude
207+
208+
new_t = [
209+
t.replace_tensor(random_noise(t.tensor)) for t in unitcell.get_unique_tensors()
210+
]
211+
212+
return unitcell.replace_unique_tensors(new_t)

0 commit comments

Comments
 (0)