Repository: tempoCollaboration/OQuPy

Issue:
Bug when loading a process tensor from file
I've found a bug when loading a process tensor with non-diagonal coupling from a file.

Here is a (minimal) failing example:
```python
import oqupy

TEMP_FILE = "./temp-process-tensor.hdf5"

system = oqupy.System(oqupy.operators.sigma("x"))
initial_state = oqupy.operators.spin_dm("z+")
correlations = oqupy.PowerLawSD(
    alpha=0.3,
    zeta=1.0,
    cutoff=5.0,
    cutoff_type="exponential",
    temperature=0.2,
    name="ohmic")bath = oqupy.Bath(
    0.5*oqupy.operators.sigma("x"),
    correlations)
tempo_params = oqupy.TempoParameters(
    dt=0.1,
    dkmax=5,
    epsrel=10**(-5))
pt = oqupy.pt_tempo_compute(
    bath,
    start_time=0.0,
    end_time=0.3,
    process_tensor_file=TEMP_FILE,
    overwrite=True,
    parameters=tempo_params)
del pt

pt = oqupy.import_process_tensor(TEMP_FILE, process_tensor_type="file")

```
This is the output:
```
--> PT-TEMPO computation:
100.0%    2 of    2 [########################################] 00:00:00
Elapsed time: 0.0s
Traceback (most recent call last):
  File "./examples/fail.py", line 33, in <module>
    pt = oqupy.import_process_tensor(TEMP_FILE, process_tensor_type="file")
  File "./oqupy/process_tensor.py", line 729, in import_process_tensor
    pt_file = FileProcessTensor(mode="read", filename=filename)
  File "./oqupy/process_tensor.py", line 457, in __init__
    dictionary = self._read_file(filename)
  File "./oqupy/process_tensor.py", line 536, in _read_file
    if transform_in == 0.0:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
```


Comments:

Patch:
diff --git a/.gitignore b/.gitignore
index 73b69be..9057a01 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
 # TEMPO file formats
 *.tempoDynamics
 *.processTensor
+*.hdf5
 
 # local development
 local_dev/
diff --git a/oqupy/process_tensor.py b/oqupy/process_tensor.py
index b80569f..d37f05e 100644
--- a/oqupy/process_tensor.py
+++ b/oqupy/process_tensor.py
@@ -533,10 +533,10 @@ class FileProcessTensor(BaseProcessTensor):
 
         # transforms
         transform_in = np.array(self._f["transform_in"])
-        if transform_in == 0.0:
+        if np.allclose(transform_in, np.array([0.0])):
             transform_in = None
         transform_out = np.array(self._f["transform_out"])
-        if transform_out == 0.0:
+        if np.allclose(transform_out, np.array([0.0])):
             transform_out = None
 
         # initial tensor and mpo/cap/lam tensors


Test patch:
diff --git a/tests/coverage/process_tensor_test.py b/tests/coverage/process_tensor_test.py
index 32879e5..89acbef 100644
--- a/tests/coverage/process_tensor_test.py
+++ b/tests/coverage/process_tensor_test.py
@@ -1,4 +1,4 @@
-# Copyright 2022 The TEMPO Collaboration
+# Copyright 2022 The oqupy Collaboration
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -17,43 +17,57 @@ Tests for the time_evovling_mpo.process_tensor module.
 
 import pytest
 
-import oqupy as tempo
+import oqupy
 
-
-TEMP_FILE = "tests/data/temp.processTensor"
+TEMP_FILE_1 = "./tests/data/temp1.hdf5"
+TEMP_FILE_2 = "./tests/data/temp2.hdf5"
 
 # -- prepare a process tensor -------------------------------------------------
 
-system = tempo.System(tempo.operators.sigma("x"))
-initial_state = tempo.operators.spin_dm("z+")
-correlations = tempo.PowerLawSD(
+system = oqupy.System(oqupy.operators.sigma("x"))
+initial_state = oqupy.operators.spin_dm("z+")
+correlations = oqupy.PowerLawSD(
     alpha=0.3,
     zeta=1.0,
     cutoff=5.0,
     cutoff_type="exponential",
     temperature=0.2,
     name="ohmic")
-bath = tempo.Bath(
-    0.5*tempo.operators.sigma("z"),
+bath1 = oqupy.Bath(
+    0.5*oqupy.operators.sigma("z"),
+    correlations,
+    name="phonon bath")
+bath2 = oqupy.Bath(
+    0.5*oqupy.operators.sigma("x"),
     correlations,
     name="phonon bath")
-tempo_params = tempo.TempoParameters(
+tempo_params = oqupy.TempoParameters(
     dt=0.1,
     dkmax=5,
     epsrel=10**(-5))
-pt = tempo.pt_tempo_compute(
-    bath,
+pt1 = oqupy.pt_tempo_compute(
+    bath1,
+    start_time=0.0,
+    end_time=0.3,
+    parameters=tempo_params)
+pt2 = oqupy.pt_tempo_compute(
+    bath2,
     start_time=0.0,
-    end_time=1.0,
+    end_time=0.3,
     parameters=tempo_params)
-pt.export(TEMP_FILE, overwrite=True)
-del pt
+pt1.export(TEMP_FILE_1, overwrite=True)
+pt2.export(TEMP_FILE_2, overwrite=True)
+del pt1
+del pt2
 
 
 def test_process_tensor():
-    pt = tempo.import_process_tensor(TEMP_FILE, process_tensor_type="simple")
-    str(pt)
-    pt.get_bond_dimensions()
+    pt1 = oqupy.import_process_tensor(TEMP_FILE_1, process_tensor_type="simple")
+    str(pt1)
+    pt1.get_bond_dimensions()
     with pytest.raises(OSError):
-        pt.export(TEMP_FILE)
+        pt1.export(TEMP_FILE_1)
 
+    pt2 = oqupy.import_process_tensor(TEMP_FILE_2, process_tensor_type="file")
+    str(pt2)
+    pt2.get_bond_dimensions()