-
Notifications
You must be signed in to change notification settings - Fork 54
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
base: master
Are you sure you want to change the base?
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 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1244 +/- ##
========================================
Coverage 99.81% 99.82%
========================================
Files 72 72
Lines 10520 10659 +139
========================================
+ Hits 10501 10640 +139
Misses 19 19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Thanks @Canoming. All the methods seem to be implemented correctly.
Regarding the documentation, I have noticed that the new classes QuantumComb
and QuantumChannel
need to be added to qibo.srt so that they appear on the website. The file README.md is not included in any toctree. I think the best place to add it is in advancedexamples.rst.
I only have a few minor suggestions at the code level:
"""Quantum comb is a quantum network such that the systems follows a sequential order. | ||
It is also called the *non-Markovian quantum process* in many literatures. | ||
Specifically, a quantum comb is a quantum network of the form :math:`J[┍i1┑,┕o1┙,┍i2┑,┕o2┙, ...]`, | ||
where the the process first take an input state from system :math:`i1`, then output a state to system :math:`o1`, and so on. |
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.
where the the process first take an input state from system :math:`i1`, then output a state to system :math:`o1`, and so on. | |
where the process first take an input state from system :math:`i1`, then output a state to system :math:`o1`, and so on. |
tensors = [ | ||
operand.full() if operand.is_pure() else operand._tensor for operand in operands | ||
] |
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.
Tests are failing with cupy
and cuquantum
due to this line. np.einsum_path()
is not implemented in some backends, so I think the simplest workaround is to cast to numpy
.
tensors = [ | |
operand.full() if operand.is_pure() else operand._tensor for operand in operands | |
] | |
tensors = [ | |
backend.to_numpy(operand.full()) if operand.is_pure() else backend.to_numpy(operand._tensor) for operand in operands | |
] |
QuantumChannel(matrix, partition=(2, 2, 2), pure=True, backend=backend) | ||
|
||
with pytest.raises(TypeError): | ||
link_product(1, quantum_comb) |
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.
link_product(1, quantum_comb) | |
link_product(1, quantum_comb, backend=backend) |
unitary_channel2, | ||
trace(2, backend=backend), | ||
trace(2, backend=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.
) | |
backend=backend, | |
) |
atol=1e-8, | ||
) | ||
|
||
traced = link_product("ij,j", id, tr) |
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.
traced = link_product("ij,j", id, tr) | |
traced = link_product("ij,j", id, tr, backend=backend) |
link_product("ii", quantum_channel) | ||
link_product("ij, kj", network_state, quantum_channel) | ||
link_product("ij, jj", network_state, quantum_channel) | ||
link_product("ij, jj, jj", network_state, quantum_channel, quantum_channel) |
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.
link_product("ii", quantum_channel) | |
link_product("ij, kj", network_state, quantum_channel) | |
link_product("ij, jj", network_state, quantum_channel) | |
link_product("ij, jj, jj", network_state, quantum_channel, quantum_channel) | |
link_product("ii", quantum_channel, backend=backend) | |
link_product("ij, kj", network_state, quantum_channel, backend=backend) | |
link_product("ij, jj", network_state, quantum_channel, backend=backend) | |
link_product("ij, jj, jj", network_state, quantum_channel, quantum_channel, backend=backend) |
backend=backend, | ||
) | ||
|
||
non_comb = link_product("ij kl, km on -> jl mn", non_channel, unitary_channel) |
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.
non_comb = link_product("ij kl, km on -> jl mn", non_channel, unitary_channel) | |
non_comb = link_product("ij kl, km on -> jl mn", non_channel, unitary_channel, backend=backend) |
link_product(1, quantum_comb) | ||
|
||
with pytest.raises(TypeError): | ||
link_product("ij, i", quantum_comb, matrix) |
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.
link_product("ij, i", quantum_comb, matrix) | |
link_product("ij, i", quantum_comb, matrix, backend=backend) |
@Canoming I'm sorry for my absence. I can't review this PR this week but I can next week. |
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