Exemple #1
0
 def test_entanglement_of_formation_invalid_input(self):
     input_state = np.array([[0, 1], [1, 0]])
     expected = "Input must be a state-vector or 2-qubit density matrix."
     with patch('sys.stdout', new=StringIO()) as fake_stout:
         res = entanglement_of_formation(input_state, 1)
     self.assertEqual(fake_stout.getvalue().strip(), expected)
     self.assertIsNone(res)
Exemple #2
0
 def test_entanglement_of_formation(self):
     input_state = np.array([[0.5, 0.25, 0.75, 1],
                             [1, 0, 1, 0],
                             [0.5, 0.5, 0.5, 0.5],
                             [0, 1, 0, 1]])
     res = entanglement_of_formation(input_state, 2)
     self.assertAlmostEqual(0.6985340217364572, res)
Exemple #3
0
 def test_entanglement_of_formation(self):
     psi1 = [1, 0, 0, 0]
     rho1 = [[0.5, 0, 0, 0.5], [0, 0, 0, 0], [0, 0, 0, 0], [0.5, 0, 0, 0.5]]
     rho2 = [[0, 0, 0, 0], [0, 0.5, -0.5j, 0], [0, 0.5j, 0.5, 0],
             [0, 0, 0, 0]]
     rho3 = 0.5 * np.array(rho1) + 0.5 * np.array(rho2)
     rho4 = 0.75 * np.array(rho1) + 0.25 * np.array(rho2)
     eofs = [
         entanglement_of_formation(state, 2)
         for state in [psi1, rho1, rho2, rho3, rho4]
     ]
     targets = [0.0, 1.0, 1.0, 0.0, 0.35457890266527003]
     self.assertTrue(np.allclose(eofs, targets))
Exemple #4
0
 def test_entanglement_of_formation_1d_input(self):
     input_state = np.array([0.5, 0.25, 0.75, 1])
     res = entanglement_of_formation(input_state, 2)
     self.assertAlmostEqual(0.15687647805861626, res)
Exemple #5
0
 def test_entanglement_of_formation_invalid_input(self):
     input_state = np.array([[0, 1], [1, 0]])
     res = entanglement_of_formation(input_state, 1)
     self.assertIsNone(res)