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 quantum_random.py #7446

Merged
merged 23 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cfdebf3
Create quantum_random.py
Alanzz Oct 20, 2022
345851d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2022
0d7f911
Update quantum_random.py
Alanzz Oct 20, 2022
a11917e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2022
9c5babb
Update quantum_random.py
Alanzz Oct 20, 2022
c499f6c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2022
6c7589e
Update quantum/quantum_random.py
Alanzz Oct 20, 2022
b57bb45
Update quantum/quantum_random.py
Alanzz Oct 20, 2022
d9614fe
Update quantum/quantum_random.py
Alanzz Oct 20, 2022
62db8d1
Update quantum_random.py
Alanzz Oct 20, 2022
2819d05
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2022
572e22b
Update quantum_random.py
Alanzz Oct 20, 2022
4286193
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2022
2d690ef
requirements.txt: Add projectq
cclauss Oct 20, 2022
922ee2c
Update quantum_random.py
Alanzz Oct 20, 2022
d0258f0
Update quantum/quantum_random.py
Alanzz Oct 20, 2022
8b052d1
Update quantum_random.py
Alanzz Oct 20, 2022
84d794b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2022
757ac8a
Update quantum_random.py
Alanzz Oct 20, 2022
fce3736
Update quantum_random.py
Alanzz Oct 20, 2022
a6c2d90
Update quantum/quantum_random.py
cclauss Oct 20, 2022
c0f07bd
Update quantum/quantum_random.py
cclauss Oct 20, 2022
4722451
Update quantum_random.py
Alanzz Oct 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions quantum/quantum_random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import doctest
import projectq
from projectq.ops import H, Measure


def get_random_number(quantum_engine : projectq.cengines._main.MainEngine) -> int:
Alanzz marked this conversation as resolved.
Show resolved Hide resolved
Alanzz marked this conversation as resolved.
Show resolved Hide resolved
Alanzz marked this conversation as resolved.
Show resolved Hide resolved
# """
# >>> instance(get_random_number(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 = 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
cclauss marked this conversation as resolved.
Show resolved Hide resolved
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