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

refactor QuantumNetwork to support general quantum networks #1244

Open
wants to merge 40 commits into
base: master
Choose a base branch
from

Conversation

Canoming
Copy link
Contributor

@Canoming Canoming commented Mar 2, 2024

Checklist:

  • Reviewers confirm new code works as expected.
  • Tests are passing.
  • Coverage does not decrease.
  • Documentation is updated.

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

class diagram

@Canoming Canoming added the quantum_info module PRs and issues related to the quantum information module label Mar 2, 2024
@Canoming Canoming self-assigned this Mar 2, 2024
@renatomello renatomello marked this pull request as draft March 6, 2024 16:02
@scarrazza scarrazza added this to the Qibo 0.2.8 milestone Mar 26, 2024
@Canoming Canoming marked this pull request as ready for review April 17, 2024 07:45
@Canoming
Copy link
Contributor Author

The build of the wheel fails after I merge the master into this branch. Not sure what causes the problem

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.82%. Comparing base (c132711) to head (871ba16).
Report is 30 commits behind head on master.

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            
Flag Coverage Δ
unittests 99.82% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MatteoRobbiati MatteoRobbiati removed the request for review from BrunoLiegiBastonLiegi May 22, 2024 09:14
@scarrazza scarrazza modified the milestones: Qibo 0.2.8, Qibo 0.2.9 May 23, 2024
Copy link
Contributor

@AlejandroSopena AlejandroSopena left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +971 to +973
tensors = [
operand.full() if operand.is_pure() else operand._tensor for operand in operands
]
Copy link
Contributor

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.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
link_product(1, quantum_comb)
link_product(1, quantum_comb, backend=backend)

unitary_channel2,
trace(2, backend=backend),
trace(2, backend=backend),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
)
backend=backend,
)

atol=1e-8,
)

traced = link_product("ij,j", id, tr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
traced = link_product("ij,j", id, tr)
traced = link_product("ij,j", id, tr, backend=backend)

Comment on lines +149 to +152
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
link_product("ij, i", quantum_comb, matrix)
link_product("ij, i", quantum_comb, matrix, backend=backend)

@renatomello
Copy link
Contributor

@Canoming I'm sorry for my absence. I can't review this PR this week but I can next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
quantum_info module PRs and issues related to the quantum information module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants