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

Rich wires #523

Open
wants to merge 51 commits into
base: develop
Choose a base branch
from
Open

Rich wires #523

wants to merge 51 commits into from

Conversation

ziofil
Copy link
Collaborator

@ziofil ziofil commented Nov 14, 2024

Wires have been challenging to maintain due to evolving requirements.

This PR introduces a better abstraction for Wire that stores a collection of QuantumWire and ClassicalWire dataclasses. Metadata can be added to these dataclasses without modifying the Wires object’s handling of indices and dictionaries. Many methods, like __matmul__, are greatly simplified.

@ziofil ziofil added the no changelog Pull request does not require a CHANGELOG entry label Nov 14, 2024
@ziofil ziofil added the WIP work in progress label Nov 14, 2024
Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.20%. Comparing base (4d61a52) to head (ce57db3).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #523      +/-   ##
===========================================
- Coverage    90.20%   90.20%   -0.01%     
===========================================
  Files          102      102              
  Lines         6321     6310      -11     
===========================================
- Hits          5702     5692      -10     
+ Misses         619      618       -1     
Files with missing lines Coverage Δ
mrmustard/lab_dev/circuit_components.py 98.44% <100.00%> (ø)
...ustard/lab_dev/circuit_components_utils/b_to_ps.py 100.00% <100.00%> (ø)
...mustard/lab_dev/circuit_components_utils/b_to_q.py 100.00% <100.00%> (ø)
...tard/lab_dev/circuit_components_utils/trace_out.py 100.00% <100.00%> (ø)
mrmustard/lab_dev/circuits.py 94.93% <100.00%> (ø)
mrmustard/lab_dev/states/dm.py 95.75% <100.00%> (+0.10%) ⬆️
mrmustard/lab_dev/states/ket.py 98.63% <100.00%> (+0.03%) ⬆️
mrmustard/lab_dev/states/number.py 100.00% <100.00%> (ø)
mrmustard/lab_dev/states/quadrature_eigenstate.py 100.00% <100.00%> (ø)
mrmustard/lab_dev/states/sauron.py 100.00% <ø> (ø)
... and 6 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d61a52...ce57db3. Read the comment docs.

@ziofil ziofil removed the WIP work in progress label Nov 27, 2024
mrmustard/physics/wires.py Outdated Show resolved Hide resolved
mrmustard/physics/wires.py Outdated Show resolved Hide resolved
classical_out or set(),
classical_in or set(),
):
if any(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this check since the type hints already make it explicit that's what we expect

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we need it because otherwise one can pass an unsorted tuple, or list. Like (3,2,1) and then the modes are screwed up. To guard against that we would have to cast to a set, but I'd rather not do that by default because then implicit stuff happens.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But we type hint it as a set does that mean we should update the type hint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What change do you have in mind? Here the hint says set[int] | None and the method raises if it isn't that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right the type hint says its set | None so we shouldn't be expecting something like an unsorted tuple or list to be passed in. If we want to support passing in an unsorted tuple or list then the type hint should be updated to reflect that. If not, then the check shouldn't be necessary as the type hint is already implying it is set | None.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I'm sure you know, the type hint does not enforce anything. Raising an exception in this case guards against running into bugs because of an ordered data structure is passed in when out of order. If this is your only concern about this PR can you accept this check and approve it?

@apchytr apchytr requested a review from aplund December 6, 2024 15:01
.gitignore Outdated Show resolved Hide resolved
mrmustard/lab_dev/circuit_components.py Show resolved Hide resolved
mrmustard/lab_dev/circuits.py Show resolved Hide resolved
mrmustard/physics/wires.py Show resolved Hide resolved
mrmustard/physics/wires.py Show resolved Hide resolved
mrmustard/physics/wires.py Show resolved Hide resolved
mrmustard/physics/wires.py Show resolved Hide resolved
mrmustard/physics/wires.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog Pull request does not require a CHANGELOG entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants