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()
```


Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/tempoCollaboration/OQuPy/pull/74?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration) Report
Base: **89.43**% // Head: **89.64**% // Increases project coverage by **`+0.21%`** :tada:
> Coverage data is based on head [(`dfb2c18`)](https://codecov.io/gh/tempoCollaboration/OQuPy/pull/74?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration) compared to base [(`be1c8bc`)](https://codecov.io/gh/tempoCollaboration/OQuPy/commit/be1c8bc45db3411aaebc213c2b2f52cb8d52e55f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
+ Coverage   89.43%   89.64%   +0.21%     
==========================================
  Files          24       24              
  Lines        3709     3709              
==========================================
+ Hits         3317     3325       +8     
+ Misses        392      384       -8     
```


| [Impacted Files](https://codecov.io/gh/tempoCollaboration/OQuPy/pull/74?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration) | Coverage Δ | |
|---|---|---|
| [oqupy/process\_tensor.py](https://codecov.io/gh/tempoCollaboration/OQuPy/pull/74/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration#diff-b3F1cHkvcHJvY2Vzc190ZW5zb3IucHk=) | `82.55% <100.00%> (+2.08%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/tempoCollaboration/OQuPy/pull/74?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tempoCollaboration).


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()