Add quantum_random.py (#7446)

* 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>
This commit is contained in:
Alan Paul 2022-10-20 15:57:13 +05:30 committed by GitHub
parent 4829fea24d
commit 831280cedd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

30
quantum/quantum_random.py Normal file
View File

@ -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)

View File

@ -7,6 +7,7 @@ numpy
opencv-python
pandas
pillow
projectq
qiskit
requests
scikit-fuzzy