-
Notifications
You must be signed in to change notification settings - Fork 57
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
Creation of quantum_info.quantum_networks
submodule and QuantumNetwork
class
#1137
Conversation
quantum_info.quantum_network
submodule and QuantumNetwork
classquantum_info.quantum_networks
submodule and QuantumNetwork
class
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1137 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 68 69 +1
Lines 9906 10084 +178
==========================================
+ Hits 9906 10084 +178
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Ah, sorry. I just rethought it. According to our construction of non-pure networks from pure networks, the phase of the complex will be omitted. So here is the expected behavior of the multiplication and division:
I've updated |
… the `__mul__` and `__truediv__`
for more information, see https://pre-commit.ci
I updated the test file to match the change of behavior of |
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.
It looks like a basic functional class now.
@Canoming could you help me beef up the documentation for |
Could you add that to the docstrings of these functions too? Thanks. |
Co-authored-by: Alejandro Sopena <44305203+AlejandroSopena@users.noreply.github.com>
Ah, sorry for the late reply. I can write some documentation for this class. But should we restore the |
As long as the branch is up-to-date with |
Emm.. I just found an issue in the latest version of import numpy as np
from qibo.quantum_info.quantum_networks import QuantumNetwork
from qibo.gates import DepolarizingChannel
# Create a quantum network from numpy array is fine
test = np.ones((2,2,2,2))
test_choi = QuantumNetwork(test, (2,2,2,2), pure=True)
print(test_choi.partition)
print(test_choi.system_output)
# But create a quantum network from the output of the old quantum channel will crash the kernal
test_ch = DepolarizingChannel(0,0.5)
N = len(test_ch.target_qubits)
partition = (2**N, 2**N)
depolar_choi = QuantumNetwork(test_ch.to_choi(), partition)
print(f'A quantum channel is a quantum netowrk of the form {depolar_choi}') The creation of the
I used these codes as the demo use case of By the way, I'm also not sure where to put the documentation of |
Quantum Networks | ||
^^^^^^^^^^^^^^^^ | ||
|
||
.. autoclass:: qibo.quantum_info.quantum_networks.QuantumNetwork | ||
:members: | ||
:member-order: bysource | ||
|
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.
A couple of words to introduce this might be helpful
if backend is None: # pragma: no cover | ||
backend = self._backend |
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.
I believe this will fail if the QuantumNetwork
was created with backend=None
.
In the __init__
you should probably do:
self._backend = backend if backend is not None else GlobalBackend()
return float(norm) <= precision_tol | ||
|
||
def positive_semidefinite(self, precision_tol: float = 1e-8): | ||
"""Returns bool indicating if Choi operator :math:`\\mathcal{E}` of the networn is positive-semidefinite. |
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.
"""Returns bool indicating if Choi operator :math:`\\mathcal{E}` of the networn is positive-semidefinite. | |
"""Returns bool indicating if Choi operator :math:`\\mathcal{E}` of the network is positive-semidefinite. |
if self.pure() and number > 0.0: | ||
return QuantumNetwork( | ||
self.matrix(backend=self._backend) / np.sqrt(number), | ||
partition=self.partition, | ||
system_output=self.system_output, | ||
pure=True, | ||
backend=self._backend, | ||
) | ||
|
||
return QuantumNetwork( | ||
self.matrix(backend=self._backend) / number, | ||
partition=self.partition, | ||
system_output=self.system_output, | ||
pure=False, | ||
backend=self._backend, | ||
) |
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.
if self.pure() and number > 0.0: | |
return QuantumNetwork( | |
self.matrix(backend=self._backend) / np.sqrt(number), | |
partition=self.partition, | |
system_output=self.system_output, | |
pure=True, | |
backend=self._backend, | |
) | |
return QuantumNetwork( | |
self.matrix(backend=self._backend) / number, | |
partition=self.partition, | |
system_output=self.system_output, | |
pure=False, | |
backend=self._backend, | |
) | |
number = np.sqrt(number) if self.pure() and number > 0.0 else number | |
return QuantumNetwork( | |
self.matrix(backend=self._backend) / number, | |
partition=self.partition, | |
system_output=self.system_output, | |
pure=self.pure(), | |
backend=self._backend, | |
) | |
This closes #1077
Checklist: