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
Add Qobj method for getting data as a numpy array shaped like a tensor rather than an array #2353
Comments
In the development version In the release version, |
Ah, that would be great! Thanks for pointing out those other functions as well. In the release version, would the implementation be something like the following? np.transpose(np.reshape(my_qobj.full(), dims_to_tensor_shape(my_qobj.dims)), dims_to_tensor_perm(my_qobj.dims)) Do I perhaps want the inverse permutation of dims_to_tensor_perm? Should the numpy reshape use 'F' for the order parameter? |
It seems fine like this. |
I'll add that it might be worth addressing the fact that there are two common conventions for representing quantum states as tensors that each have their pros and cons. Perhaps this would be better placed in a separate issue, but I'll explain here anyway. Consider a joint state like Two common representations of this abstract state as a tensor are
These two conventions essentially correspond to the "super" and "choi" representations for channels. Representation 1. is nice when you are doing most of your calculations with pure states, but then want a density matrix towards the end, which you can do with just When I said above that these two conventions should be "addressed" in some way, I was intentionally vague because I'm honestly not sure what the best way to do that would be. One option would be to simply mention it in the user guide somewhere, perhaps near the section on the Super and Choi representations. Another would be to support both conventions via optional parameters like |
Problem Description
There is no built in method for converting a Qobj into a numpy array such that the
shape
of the numpy array reflects thedims
of the Qobj. While fixing this is a oneliner withnp.reshape
, there are many opportunities for mistakes here, such as making sure the numpy reshape convention (row-major or column-major) matches the Qutip convention.Proposed Solution
Add a
full_tensor
andget_data_tensor
method toQobj
which behave likefull
andget_data
except the returned numpy array has a shape equal todims
flattened into a 1D list.Alternate Solutions
Instead of a new method,
full
andget_data
could be given an optional parameterkeep_shape: bool = false
Additional Context
No response
The text was updated successfully, but these errors were encountered: