Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation compatibility with qutip-v5 #192

Merged
merged 7 commits into from
Mar 5, 2023
Merged

Conversation

BoxiLi
Copy link
Member

@BoxiLi BoxiLi commented Feb 18, 2023

  • Remove some unnecessary branching that was used for the compatibility of qutip-v5. They are no longer needed in the new alpha version.
  • Update the pulse paper examples to be compatible with qutip-v5.
  • Update the documentation to be compatible with qutip-v5.

Note that doctest still doesn't fully pass with qutip-v5 because of the spaces in printed Qobj._repr_. But this should be fine if we only build the doc against qutip-v4.7 for now.

SolverOptions is removed from qutip5.
Ignore the future warning for qutip.Options for now.
The use of qutip.Options should be removed in ~1 year after the official release of qutip5
- Turn-off progress bar for the solvers
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.
@BoxiLi
Copy link
Member Author

BoxiLi commented Feb 18, 2023

@hodgestar
DO you think if worth have something like this in qutip-v5?

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

@hodgestar
Copy link
Contributor

We should definitely have a nice solution for cases like q.dag() * q which return a scalar in v5 and a Qobj in v4, but I don't think that solution can be in qutip. We could add a function to v5, but no such function is in v4 and we're not planning a 4.8. So the function probably has to be in libraries that use qutip, like qutip_qip.

Rather than the function you have now, I recommend creating a qutip_qip.compat module (so one can easily remove these later) and inside having a function like:

def to_scalar(qobj_or_scalar):
    if isinstance(qobj_or_scalar, Qobj):
        if qobj_or_scalar.dims == [[1], [1]]:   # <-- maybe this check should also handle more dims?
            return qobj_or_scalar[0, 0]
        else:
            raise ValueError(...)
    return qobj_or_scalar

This avoids explicit version checks and implements a more specific set of functionality.

@BoxiLi
Copy link
Member Author

BoxiLi commented Feb 20, 2023

Yes, the example you provide is better, avoiding the version check. There are indeed other cases instead of just dims=[[1],[1]] but this covers >99% of situations.

And now thinking about it again. You are also right that unless we can have this for both qutip-v4 and v5, it is not gonna be sufficient. Maybe we could just provide the example above as part of the upgrade guide.

@BoxiLi BoxiLi merged commit 2eccfec into qutip:master Mar 5, 2023
@BoxiLi BoxiLi added the qutip5 qutip 5 compatibility label Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qutip5 qutip 5 compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants