Skip to content

Commit

Permalink
Add quantum_random.py (#7446)
Browse files Browse the repository at this point in the history
* Create quantum_random.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update quantum_random.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update quantum_random.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update quantum/quantum_random.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update quantum/quantum_random.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update quantum/quantum_random.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update quantum_random.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update quantum_random.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* requirements.txt: Add projectq

* Update quantum_random.py

* Update quantum/quantum_random.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update quantum_random.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update quantum_random.py

* Update quantum_random.py

* Update quantum/quantum_random.py

* Update quantum/quantum_random.py

* Update quantum_random.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
  • Loading branch information
3 people authored Oct 20, 2022
1 parent 4829fea commit 831280c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions quantum/quantum_random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import doctest

import projectq
from projectq.ops import H, Measure


def get_random_number(quantum_engine: projectq.cengines._main.MainEngine) -> int:
"""
>>> isinstance(get_random_number(projectq.MainEngine()), int)
True
"""
qubit = quantum_engine.allocate_qubit()
H | qubit
Measure | qubit
return int(qubit)


if __name__ == "__main__":
doctest.testmod()

# initialises a new quantum backend
quantum_engine = projectq.MainEngine()

# Generate a list of 10 random numbers
random_numbers_list = [get_random_number(quantum_engine) for _ in range(10)]

# Flushes the quantum engine from memory
quantum_engine.flush()

print("Random numbers", random_numbers_list)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ numpy
opencv-python
pandas
pillow
projectq
qiskit
requests
scikit-fuzzy
Expand Down

0 comments on commit 831280c

Please sign in to comment.