-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copied qml_400_BuildingQRAM problem templates
- Loading branch information
xanadu-qubot
committed
Feb 14, 2022
1 parent
bfaefe0
commit 2540032
Showing
8 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.353553,0.0,0.353553,0.0,0.353553,0.0,0.353553,0.0,0.353553,-0.0,0.353553,-0.0,0.353553,0.0,0.353553,0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0,0,0,0,0,0,0,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0,0.353553,0.0,0.353553,0.0,0.353553,0.0,0.353553,-0.0,0.353553,-0.0,0.353553,-0.0,0.353553,-0.0,0.353553 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.141592653589793,3.141592653589793,3.141592653589793,3.141592653589793,3.141592653589793,3.141592653589793,3.141592653589793,3.141592653589793 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.353553,0.0,0.351787,0.035296,0.342562,0.087471,0.353112,0.01767,0.353112,0.01767,0.351787,0.035296,0.346506,0.07024,0.337762,0.104482 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0,0.2,0.5,0.1,0.1,0.2,0.4,0.6 |
47 changes: 47 additions & 0 deletions
47
Coding_Challenges/qml_400_BuildingQRAM_template/building_QRAM_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#! /usr/bin/python3 | ||
|
||
import sys | ||
from pennylane import numpy as np | ||
import pennylane as qml | ||
|
||
|
||
def qRAM(thetas): | ||
"""Function that generates the superposition state explained above given the thetas angles. | ||
Args: | ||
- thetas (list(float)): list of angles to apply in the rotations. | ||
Returns: | ||
- (list(complex)): final state. | ||
""" | ||
|
||
# QHACK # | ||
|
||
# Use this space to create auxiliary functions if you need it. | ||
|
||
# QHACK # | ||
|
||
dev = qml.device("default.qubit", wires=range(4)) | ||
|
||
@qml.qnode(dev) | ||
def circuit(): | ||
|
||
# QHACK # | ||
|
||
# Create your circuit: the first three qubits will refer to the index, the fourth to the RY rotation. | ||
|
||
# QHACK # | ||
|
||
return qml.state() | ||
|
||
return circuit() | ||
|
||
|
||
if __name__ == "__main__": | ||
# DO NOT MODIFY anything in this code block | ||
inputs = sys.stdin.read().split(",") | ||
thetas = np.array(inputs, dtype=float) | ||
|
||
output = qRAM(thetas) | ||
output = [float(i.real.round(6)) for i in output] | ||
print(*output, sep=",") |
Binary file not shown.