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

Allowing circuit execution using float32 and float64 dtypes #1625

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

Conversation

renatomello
Copy link
Contributor

@renatomello renatomello commented Apr 3, 2025

Closes #1515 and #1626 . This has implications for qiboml and qibochem since it allows memory reduction for circuits that only contain gates with real-valued matrix representations.

Also fixes some tests on GPU.

Needs qiboteam/qibojit#219

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 Apr 3, 2025
@renatomello renatomello added this to the Qibo 0.2.18 milestone Apr 3, 2025
@renatomello renatomello self-assigned this Apr 3, 2025
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.11%. Comparing base (c818eba) to head (80f7f45).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1625   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files          77       77           
  Lines       11475    11486   +11     
=======================================
+ Hits        11373    11384   +11     
  Misses        102      102           
Flag Coverage Δ
unittests 99.11% <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.

@renatomello
Copy link
Contributor Author

@scarrazza do we have any intention of supporting data types like complex256, float128, or float16?

https://numpy.org/doc/stable/user/basics.types.html

@scarrazza
Copy link
Member

I would say not, but did you try somenof those with the code in this PR?

@renatomello renatomello linked an issue Apr 3, 2025 that may be closed by this pull request
@renatomello renatomello marked this pull request as ready for review April 3, 2025 12:07
Copy link

github-actions bot commented Apr 4, 2025

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/14264634691

@renatomello renatomello requested review from AlejandroSopena and removed request for scarrazza April 7, 2025 05:47
Copy link
Member

@stavros11 stavros11 left a comment

Choose a reason for hiding this comment

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

Thanks @renatomello. This looks good to me and it's great to be able to simulate circuits using real dtypes whenever this is possible.

I just noticed the following issue: the following

import qibo
from qibo import Circuit, gates, matrices

c = Circuit(1)
c.add(gates.X(0))

qibo.set_backend("numpy")
qibo.set_dtype("float32")

state = c().state()
print(state.dtype)

gives float32 as expected, however if I switch the setting of backend and precision to

qibo.set_dtype("float32")
qibo.set_backend("numpy")

it goes back to the default complex128. Is this the behavior we want?

@renatomello
Copy link
Contributor Author

Thanks @renatomello. This looks good to me and it's great to be able to simulate circuits using real dtypes whenever this is possible.

I just noticed the following issue: the following

import qibo
from qibo import Circuit, gates, matrices

c = Circuit(1)
c.add(gates.X(0))

qibo.set_backend("numpy")
qibo.set_dtype("float32")

state = c().state()
print(state.dtype)

gives float32 as expected, however if I switch the setting of backend and precision to

qibo.set_dtype("float32")
qibo.set_backend("numpy")

it goes back to the default complex128. Is this the behavior we want?

I would say so, yes. set_backend completely resets the backend. So, if nothing is specified regarding the data type, then it will default to the default data type.

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.

Backend precision v. dtype redundancy Possibility to generalize Backend.set_precision
3 participants