Browse code

Add a function for constructing an n-qubit gate from a tensor product of 1-qubit gates

Joseph Weston authored on 15/11/2019 19:12:40
Showing 1 changed files
... ...
@@ -1,3 +1,5 @@
1
+from functools import reduce
2
+
1 3
 from hypothesis import given
2 4
 import hypothesis.strategies as st
3 5
 import hypothesis.extra.numpy as hnp
... ...
@@ -57,6 +59,12 @@ project_zero = np.array([[1, 0], [0, 0]])
57 59
 project_one = np.array([[0, 0], [0, 1]])
58 60
 
59 61
 
62
+def product_gate(single_qubit_gates):
63
+    # We reverse so that 'single_qubit_gates' can be indexed by the qubit
64
+    # identifier; e.g. qubit #0 is actually the least-significant qubit
65
+    return reduce(np.kron, reversed(single_qubit_gates))
66
+
67
+
60 68
 # -- Tests --
61 69
 
62 70