Ejemplo n.º 1
0
 def test_equiv(self):
     """Test equiv method"""
     vec = np.array([1, 0, 0, -1j]) / np.sqrt(2)
     phase = np.exp(-1j * np.pi / 4)
     statevec = Statevector(vec)
     self.assertTrue(statevec.equiv(phase * vec))
     self.assertTrue(statevec.equiv(Statevector(phase * vec)))
     self.assertFalse(statevec.equiv(2 * vec))
Ejemplo n.º 2
0
    def test_equiv_on_circuit(self):
        """Test the equiv method on different types of input."""
        statevec = Statevector([1, 0])

        qc = QuantumCircuit(1)
        self.assertTrue(statevec.equiv(qc))
        qc.x(0)
        self.assertFalse(statevec.equiv(qc))
Ejemplo n.º 3
0
 def test_densitymatrix_to_statevector_pure(self):
     """Test converting a pure density matrix to statevector."""
     state = 1 / np.sqrt(2) * (np.array([1, 0, 0, 0, 0, 0, 0, 1]))
     psi = Statevector(state)
     rho = DensityMatrix(psi)
     phi = rho.to_statevector()
     self.assertTrue(psi.equiv(phi))