-
Notifications
You must be signed in to change notification settings - Fork 61
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
refactor QuantumNetwork
to support general quantum networks
#1244
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
The build of the |
There are the new conflicts with |
try: | ||
tensor = np.transpose(operator.reshape(list(partition) * 2), order) | ||
return tensor.reshape([dim**2 for dim in partition]) | ||
except: | ||
raise_error( | ||
ValueError, | ||
"``partition`` does not match the shape of the input matrix. " | ||
+ f"Cannot reshape matrix of size {operator.shape} to partition {partition}", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it's best to check if partition
and operator.shape
match before trying the calculation. Raise an error if it doesn't and only do the calculation if it does. That way you avoid using try
and except
completely.
from functools import reduce | ||
from logging import warning | ||
from numbers import Number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Canoming This question still remains: we don't need this Number
class for typing, do we?
try: | ||
tensor = np.transpose(operator.reshape(list(partition) * 2), order) | ||
return tensor.reshape([dim**2 for dim in partition]) | ||
except ValueError: | ||
raise_error( | ||
ValueError, | ||
"``partition`` does not match the shape of the input matrix. " | ||
+ f"Cannot reshape matrix of size {operator.shape} to partition {partition}", | ||
) | ||
except InvalidArgumentError: | ||
raise_error( | ||
ValueError, | ||
"``partition`` does not match the shape of the input matrix. " | ||
+ f"Cannot reshape matrix of size {operator.shape} to partition {partition}", | ||
) | ||
except RuntimeError: | ||
raise_error( | ||
ValueError, | ||
"``partition`` does not match the shape of the input matrix. " | ||
+ f"Cannot reshape matrix of size {operator.shape} to partition {partition}", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a much simpler way of implementing this. Just check if partition
matches operator.shape
. If not, raise your custom error. If it does, the calculation is done. None of these try / except
are needed. I had already mentioned this in the previous review round.
Returns: | ||
bool: Hermiticity condition. | ||
:class:`qibo.quantum_info.quantum_networks.QuantumNetwork`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Canoming also not resolved
Co-authored-by: Renato Mello <[email protected]>
Co-authored-by: Renato Mello <[email protected]>
Co-authored-by: Renato Mello <[email protected]>
For the |
I see. Which backend exactly? Do you have an example code? |
I encountered the issue before, but I don't remember the exact scenario. It was |
That's fine. That happens everywhere but we don't explicitly check if it's a |
for more information, see https://pre-commit.ci
Checklist:
I've refactored the
QuantumNetworks
to support general quantum networks and make it more compatible with usual tensor contraction methods.To make things clear, I made a class diagram for the future development of the module