-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In qutip-v5, a bra ket multiplication returns a number instead of a Qobj. This makes it hard to keep the code clean and compatible for both version. This helper function changes the returned value so that it is identical to the one returned by qutip-v4.
- Loading branch information
Showing
4 changed files
with
24 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from itertools import chain | ||
from functools import reduce | ||
from packaging.version import parse as parse_version | ||
import numpy as np | ||
import qutip | ||
|
||
|
||
def _qobj_compatibility_helper(qobj): | ||
""" | ||
Make qobj generated by operations in qutip-v5 identical to the one by qutip-v4. | ||
Here, if `qobj` is a number (e.g. generated by a bra-ket multiplication), it is replaced by a Qobj. | ||
""" | ||
if parse_version(qutip.__version__) >= parse_version("5.dev"): | ||
if np.isscalar(qobj): | ||
return qutip.Qobj([[qobj]], dims=[[1], [1]]) | ||
return qobj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters