Esempio n. 1
0
    def test_check_state(self):
        for size in [3, 4]:
            for rnd in [0.1, 0.9]:
                q = Qubits.w(size)
                print("w{0:d} state for rnd = {1:f}".format(size, rnd))
                assert self.check_state(
                    q,
                    rnd) == 1, "incorrect w{0:d} state for m = {1:f}".format(
                        size, rnd)

        for size in [3, 4]:
            for rnd in [0.1, 0.9]:
                q = Qubits.ghz(size)
                print("ghz{0:d} state".format(size))
                assert self.check_state(
                    q,
                    rnd) == 0, "incorrect w{0:d} state for m = {1:f}".format(
                        size, rnd)
Esempio n. 2
0
 def test_04_ghz_or_w_state(self):
     """// Task 4. |0..0⟩ + |1..1⟩ or W state ?
 // Input: An even number of qubits (stored in an array) which are guaranteed to be
 //        either in superposition of states |0..0⟩ and |1..1⟩
 //        or in W state ( https://en.wikipedia.org/wiki/W_state ).
 // Output: 0 if qubits were in W state,
 //         1 if they were in the second superposition.
 // The state of the qubits at the end of the operation should be the same as the starting state."""
     for ix in range(2, 8, 2):
         for tp in [0, 1]:
             if tp == 1:
                 q = Qubits.w(ix)
             else:
                 q = Qubits.ghz(ix)
             qq = q.clone()
             m = self.ghz_or_w_state(q)
             assert m == tp, "wrong superposition chosen"
             self.assert_qubits(q, qq)
Esempio n. 3
0
 def test_sign_flip(self):
     q = Qubits.ghz(1)
     self.sign_flip(q)
     self.assert_signs(q, [(0, 1), (1, -1)])
     self.sign_flip(q)
     self.assert_signs(q, [(0, 1), (1, 1)])