diff --git a/qchack2022/algo 300/solution.py b/qchack2022/algo 300/solution.py new file mode 100644 index 0000000..6a381a6 --- /dev/null +++ b/qchack2022/algo 300/solution.py @@ -0,0 +1,43 @@ +import sys +from pennylane import numpy as np +import pennylane as qml + + +def qfunc_adder(m, wires): + """Quantum function capable of adding m units to a basic state given as input. + + Args: + - m (int): units to add. + - wires (list(int)): list of wires in which the function will be executed on. + """ + + qml.QFT(wires=wires) + + # QHACK # + n = len(wires) + + for k in range(n): + qml.RZ(2 * np.pi * m / (2 ** (k + 1)), wires=wires[k]) + # QHACK # + qml.QFT(wires=wires).inv() + + +if __name__ == "__main__": + # DO NOT MODIFY anything in this code block + inputs = sys.stdin.read().split(",") + m = int(inputs[0]) + n_wires = int(inputs[1]) + wires = range(n_wires) + + dev = qml.device("default.qubit", wires=wires, shots=1) + + @qml.qnode(dev) + def test_circuit(): + # Input: |2^{N-1}> + qml.PauliX(wires=0) + + qfunc_adder(m, wires) + return qml.sample() + + output = test_circuit() + print(output, sep=",")