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

Adding ability to perturb a vector by some factor #861

Merged
merged 19 commits into from
Nov 4, 2024

Conversation

Shivansh20128
Copy link
Contributor

@Shivansh20128 Shivansh20128 commented Oct 16, 2024

Description

Provide a brief description of the PR's purpose here. If your PR is supposed to fix an existing issue, use
a keyword to link your PR to the issue.

Adding the ability to perturb a vector by some random value by adding a submodule in matrix_ops.
This PR includes the docstring, the function as described in the issue mentioned, and the tests for the feature function.
#Resolves #260

Changes

Notable changes that this PR has either accomplished or will accomplish. Feel free to add more lines to the itemized list
below.

  • Added the function perturb_vectors
  • Added docstrings for the function perturb_vectors
  • Added tests for the function perturb_vectors in file test_perturb_vector.py

Checklist

Before marking your PR ready for review, make sure you checked the following locally. If this is your first PR, you might be notified of some workflow failures after a maintainer has approved the workflow jobs to be run on your PR.

Additional information is available in the documentation.

  • Use ruff for errors related to code style and formatting.
  • Verify all previous and newly added unit tests pass in pytest.
  • Check the documentation build does not lead to any failures. Sphinx build can be checked locally for any failures related to your PR
  • Use linkcheck to check for broken links in the documentation
  • Use doctest to verify the examples in the function docstrings work as expected.

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.9%. Comparing base (4a4ce5e) to head (f18a7b2).
Report is 23 commits behind head on master.

Additional details and impacted files
@@          Coverage Diff           @@
##           master    #861   +/-   ##
======================================
  Coverage    97.9%   97.9%           
======================================
  Files         165     166    +1     
  Lines        3253    3262    +9     
  Branches      713     715    +2     
======================================
+ Hits         3185    3194    +9     
  Misses         44      44           
  Partials       24      24           

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

@Shivansh20128 Shivansh20128 marked this pull request as ready for review October 16, 2024 11:43
>>> from toqito.matrix_ops import perturb_vectors
>>> import numpy as np
>>> vectors = [np.array([1.0, 2.0]), np.array([3.0, 4.0])]
>>> perturbed_vectors = perturb_vectors(vectors, eps=0.1)
Copy link
Collaborator

@purva-thakre purva-thakre Oct 23, 2024

Choose a reason for hiding this comment

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

Suggested change
>>> perturbed_vectors = perturb_vectors(vectors, eps=0.1)
>>> perturb_vectors(vectors, eps=0.1)

Show the output as we want it to show in the documentation build. You can use # doctest: +SKIP for doctest failures as we expect the output to be different due to randn.

>>> complex_dm # doctest: +SKIP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not done yet. See #861 (comment)

Shivansh20128 and others added 3 commits October 24, 2024 10:49
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
@vprusso
Copy link
Owner

vprusso commented Oct 24, 2024

Thanks for the changes and updates, @Shivansh20128 ! LGTM, but I'll ping @purva-thakre to see if she has any additional final comments. Great work, as always!

>>> import numpy as np
>>> vectors = [np.array([1.0, 2.0]), np.array([3.0, 4.0])]
>>> perturb_vectors(vectors, eps=0.1) # doctest: +SKIP

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Shivansh20128 You have to add the output manually here. Right now, the RTD output is blank for the example.

image

See below for example:

>>> povms # doctest: +SKIP
array([[[[ 0.20649603+0.j, 0.79350397+0.j],
[ 0.77451456+0.j, 0.22548544+0.j]],
<BLANKLINE>
[[-0.25971638+0.j, 0.25971638+0.j],
[-0.28048509+0.j, 0.28048509+0.j]]],
<BLANKLINE>
<BLANKLINE>
[[[-0.25971638+0.j, 0.25971638+0.j],
[-0.28048509+0.j, 0.28048509+0.j]],
<BLANKLINE>
[[ 0.40448792+0.j, 0.59551208+0.j],
[ 0.10740892+0.j, 0.89259108+0.j]]]])

image

Copy link
Contributor Author

@Shivansh20128 Shivansh20128 Nov 3, 2024

Choose a reason for hiding this comment

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

@purva-thakre Added! I hope its fine now.

Copy link
Collaborator

@purva-thakre purva-thakre left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your patience @Shivansh20128 !

@purva-thakre purva-thakre merged commit 467666a into vprusso:master Nov 4, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Add ability to perturb a vector by some factor
3 participants