Repository: qutip/qutip

Issue:
Failing unit tests in test_subsystem_apply
Since the PR merge of Ben's (@bcriger) code for Efficient Application of CPTP Maps to Subsystems, there has been a number of failing unit tests. I have fixed some of the tests and ported Ben's code to be python3 compatible, but there are still two remaining errors, which I have traced to the fact that `subsystem_apply(..., reference=True)` does not give the expected results (some normalization problem? perhaps with the eigenvectors?)

```
In [1]: from qutip import *
In [2]: rho_3 = rand_dm(3)
In [3]: superop = kraus_to_super(rand_kraus_map(3))
In [4]: analytic_result = vector_to_operator(superop * operator_to_vector(rho_3))
In [5]: analytic_result
Out[5]: Quantum object: dims = [[3], [3]], shape = [3, 3], type = oper, isHerm = True
        ⎜0.396                  (0.069−5.343×10−04j)    (−0.003+0.030j) |
        |(0.069+5.343×10−04j)   0.407                   (−0.029−0.076j) |
        |(−0.003−0.030j)        (−0.029+0.076j)         0.293           |

In [6]: ref_result = subsystem_apply(rho_3, superop, [True], reference=True)
In [7]: ref_result
Out[7]: Quantum object: dims = [[3], [3]], shape = [3, 3], type = oper, isHerm = True
        ⎜0.354                 (0.067−0.036j)           (0.058+0.004j)  |
        |(0.067+0.036j)        0.407                    (0.039−0.041j)  |
        |(0.058−0.004j)        (0.039+0.041j)           0.240           ⎟

In [8]: efficient_result = subsystem_apply(rho_3, superop, [True])
In [9]: efficient_result
Out[9]: Quantum object: dims = [[3], [3]], shape = [3, 3], type = oper, isHerm = True
        ⎜0.396                  (0.069−5.343×10−04j)      (−0.003+0.030j) |
        | (0.069+5.343×10−04j)  0.407                     (−0.029−0.076j) |
        |(−0.003−0.030j)        (−0.029+0.076j)           0.293           ⎟
```

Probably @bcriger would be the best person to fix this issue.



Discussion:
These tests are now skipped with the skipif decorator, but should be looked at again before next release.


Resolving patch:
diff --git a/qutip/subsystem_apply.py b/qutip/subsystem_apply.py
--- a/qutip/subsystem_apply.py
+++ b/qutip/subsystem_apply.py
@@ -270,7 +270,7 @@ def _subsystem_apply_reference(state, channel, mask):
         rho_out = Qobj(inpt=zeros(state.shape), dims=state.dims)
         for operator_iter in k_qubit_kraus_list:
             operator_iter = iter(operator_iter)
-            op_iter_list = [next(operator_iter) if mask[j]
+            op_iter_list = [next(operator_iter).conj().T if mask[j]
                             else qeye(state.dims[0][j])
                             for j in range(len(state.dims[0]))]
             full_oper = tensor(list(map(Qobj, op_iter_list)))


Test patch:
diff --git a/qutip/tests/test_subsystem_apply.py b/qutip/tests/test_subsystem_apply.py
--- a/qutip/tests/test_subsystem_apply.py
+++ b/qutip/tests/test_subsystem_apply.py
@@ -65,7 +65,7 @@ def test_SimpleSingleApply(self):
         efficient_diff = (efficient_result - analytic_result).data.todense()
         assert_(norm(naive_diff) < 1e-12 and norm(efficient_diff) < 1e-12)
 
-    @skipif(True)  # until we do something about this
+    #@skipif(True)  # until we do something about this
     def test_SimpleSuperApply(self):
         """
         Non-composite system, operator on Liouville space.
@@ -108,7 +108,7 @@ def test_ComplexSingleApply(self):
         efficient_diff = (efficient_result - analytic_result).data.todense()
         assert_(norm(efficient_diff) < 1e-12)
 
-    @skipif(True)  # until we do something about this
+    #@skipif(True)  # until we do something about this
     def test_ComplexSuperApply(self):
         """
         Superoperator: Efficient numerics and reference return same result,