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

Add binary_encoder parameterized in hyperspherical coordinates #1584

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

Conversation

renatomello
Copy link
Contributor

@renatomello renatomello commented Feb 12, 2025

This is based on Section V of https://arxiv.org/abs/2405.20408 and it works for real- and complex-valued data.

Checklist:

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

@renatomello renatomello added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 12, 2025
@renatomello renatomello added this to the Qibo 0.2.16 milestone Feb 12, 2025
@renatomello renatomello self-assigned this Feb 12, 2025
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.06%. Comparing base (9034a23) to head (c67fd74).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1584   +/-   ##
=======================================
  Coverage   99.06%   99.06%           
=======================================
  Files          76       76           
  Lines       11322    11387   +65     
=======================================
+ Hits        11216    11281   +65     
  Misses        106      106           
Flag Coverage Δ
unittests 99.06% <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.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Run on QPU sim completed! :atom:

You can download the coverage report as an artifact, from the workflow summary page:
https://github.com/qiboteam/qibo/actions/runs/13286656990

renatomello and others added 2 commits March 11, 2025 06:48
Co-authored-by: Alejandro Sopena <44305203+AlejandroSopena@users.noreply.github.com>
Co-authored-by: Alejandro Sopena <44305203+AlejandroSopena@users.noreply.github.com>
Copy link
Contributor

@BrunoLiegiBastonLiegi BrunoLiegiBastonLiegi left a comment

Choose a reason for hiding this comment

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

Thanks, just some minor comments.

@@ -668,6 +674,8 @@ def _generate_rbs_angles(data, nqubits: int, architecture: str):
r_array[j - 1] = math.sqrt(r_array[2 * j] ** 2 + r_array[2 * j - 1] ** 2)
phases[j - 1] = math.acos(r_array[2 * j - 1] / r_array[j - 1])

phases = np.array([float(phase) for phase in phases])
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any specific reason why the phases are not returned as backend specific arrays? (thus with the usual backend.cast)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all functions in this module are backend-agnostic as of right now. If we were to introduce the backend as an argument, I'd prefer to do it in all encodings are once on a separate PR.

for weight in range(1, nqubits):
n_choose_k = int(binom(nqubits, weight))
cummul_n_k += n_choose_k
placeholder = np.random.rand(n_choose_k)
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure how big n_choose_k can get, but just as a reminder generating samples with numba and cupy should be faster if it's big.

Copy link
Contributor Author

@renatomello renatomello Mar 11, 2025

Choose a reason for hiding this comment

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

The size is the regular binomial coefficient, tending to $O\left(n^k / k!\right)$. I think it tends to $\sim 2^{0.9,n}$ when $k = n /2$.


cummul_n_k = 0
initial_string = np.array([1] + [0] * (nqubits - 1))
for weight in range(1, nqubits):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very big loop, it might be clearer to make it as separate function:

for weight in range(1, nqubits):
    separate_function(...)

renatomello and others added 3 commits March 11, 2025 15:20
Co-authored-by: BrunoLiegiBastonLiegi <45011234+BrunoLiegiBastonLiegi@users.noreply.github.com>
Co-authored-by: BrunoLiegiBastonLiegi <45011234+BrunoLiegiBastonLiegi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request run-on-sim
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants