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

Added the ability to control slackness in physicality conditions. #524

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

Conversation

arsalan-motamedi
Copy link
Collaborator

Context:
Currently, the tolerance for channel CPTP conditions, density matrix positivity and trace conditions, and pure state norm conditions use settings.ATOL to control their slackness. This PR allows to use arbitrary slackness for them.

Description of the Change:
Introduced new variable atol: float = settings.ATOL which is to control this slackness in all physicality conditions including is_CP, is_TP, and is_physical for Channels, and is_positive and is_physical for DMs, and finally, is_physical for Kets.

Benefits:
Will be convenient to set the slackness. Also, is helpful in some tests.

Possible Drawbacks:
None.
Related GitHub Issues:
None.

@arsalan-motamedi arsalan-motamedi added the no changelog Pull request does not require a CHANGELOG entry label Nov 15, 2024
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.80%. Comparing base (4c603d0) to head (c718903).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #524      +/-   ##
===========================================
- Coverage    89.84%   89.80%   -0.05%     
===========================================
  Files           93       93              
  Lines         6098     6092       -6     
===========================================
- Hits          5479     5471       -8     
- Misses         619      621       +2     
Files with missing lines Coverage Δ
mrmustard/lab_dev/states/dm.py 95.59% <100.00%> (-0.06%) ⬇️
mrmustard/lab_dev/states/ket.py 98.58% <100.00%> (-0.01%) ⬇️
mrmustard/lab_dev/transformations/base.py 99.41% <100.00%> (-0.02%) ⬇️

... and 1 file with indirect coverage changes


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 4c603d0...c718903. Read the comment docs.

@@ -49,10 +49,12 @@ class DM(State):

short_name = "DM"

@property
def is_positive(self) -> bool:
def is_positive(self, atol: float = settings.ATOL) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than adding a parameter what if instead we encouraged users to use

with settings(ATOL=1e-8):
     ...

Of course we would then have to make that clear in our documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a good alternative. This was a fixed suggested by Eli, so let me ask his opinion on this solution as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps a global ATOL is not such a good idea though, because it affects many checks of different things

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, Eli was indifferent and open to this suggestion too. But, why do we want to opt for this more convoluted solution is maybe a concern.

Just for the context: The issue that we initially had with changing the settings globally is that some tests may be run together, and therefore, having a global settings while changing it locally seems unsafe in this situation. However, seems like Anthony's suggestion is addressing this issue as well.

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