Skip to content

Commit

Permalink
Copied qml_400_BuildingQRAM problem templates
Browse files Browse the repository at this point in the history
  • Loading branch information
xanadu-qubot committed Feb 14, 2022
1 parent bfaefe0 commit 2540032
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions Coding_Challenges/qml_400_BuildingQRAM_template/1.ans
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
1 change: 1 addition & 0 deletions Coding_Challenges/qml_400_BuildingQRAM_template/1.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0,0,0,0,0,0,0,0
1 change: 1 addition & 0 deletions Coding_Challenges/qml_400_BuildingQRAM_template/2.ans
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
1 change: 1 addition & 0 deletions Coding_Challenges/qml_400_BuildingQRAM_template/2.in
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
1 change: 1 addition & 0 deletions Coding_Challenges/qml_400_BuildingQRAM_template/3.ans
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
1 change: 1 addition & 0 deletions Coding_Challenges/qml_400_BuildingQRAM_template/3.in
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
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.

0 comments on commit 2540032

Please sign in to comment.