def test_mix_direct_and_deferred(self): sdm = SparseDM(1) sdm.rotate_y(0, np.pi) sdm.apply_ptm(0, ptm.amp_ph_damping_ptm(1, 0)) sdm.rotate_y(0, np.pi) sdm.project_measurement(0, 0) assert not np.allclose(sdm.trace(), 1)
def test_rotate_xyz(): sdm = SparseDM(1) sdm.rotate_x(0, np.pi / 2) sdm.rotate_z(0, np.pi / 2) sdm.rotate_y(0, -np.pi / 2) assert np.allclose(sdm.trace(), 1) sdm.project_measurement(0, 0) assert np.allclose(sdm.trace(), 1)
def test_renormalize(): sdm = SparseDM(2) sdm.hadamard(0) sdm.project_measurement(0, 1) assert np.allclose(sdm.trace(), 0.5) sdm.renormalize() assert np.allclose(sdm.trace(), 1)
def test_meas_on_ground_state(): sdm = SparseDM(1) sdm.ensure_dense(0) sdm.project_measurement(0, 0) assert len(sdm.classical) == 1 assert 0 in sdm.classical assert sdm.classical[0] == 0 assert len(sdm.idx_in_full_dm) == 0 assert sdm.full_dm.no_qubits == 0 assert np.allclose(sdm.trace(), 1)
def test_meas_on_hadamard(): sdm = SparseDM(1) sdm.hadamard(0) p0, p1 = sdm.peak_measurement(0) assert p0 == 0.5 assert p1 == 0.5 sdm.project_measurement(0, 1) print(sdm.full_dm.to_array()) assert len(sdm.classical) == 1 assert sdm.full_dm.no_qubits == 0 assert sdm.classical[0] == 1 assert np.allclose(sdm.trace(), 0.5)
def test_rotate_x(): sdm = SparseDM(2) sdm.rotate_x(0, np.pi) sdm.rotate_x(1, np.pi) assert np.allclose(sdm.trace(), 1) sdm.project_measurement(1, 1) sdm.project_measurement(0, 1) assert np.allclose(sdm.trace(), 1) sdm.rotate_x(0, np.pi / 2) sdm.rotate_x(1, np.pi / 2) sdm.project_measurement(1, 1) sdm.project_measurement(0, 1) assert np.allclose(sdm.trace(), 0.25)
def test_peak_then_measure(): sdm = SparseDM(1) assert np.allclose(sdm.trace(), 1) sdm.ensure_dense(0) assert np.allclose(sdm.trace(), 1) p0, p1 = sdm.peak_measurement(0) assert np.allclose(p0, 1) assert np.allclose(p1, 0) sdm.project_measurement(0, 0) assert len(sdm.classical) == 1 assert 0 in sdm.classical assert sdm.classical[0] == 0 assert len(sdm.idx_in_full_dm) == 0 assert sdm.full_dm.no_qubits == 0 assert np.allclose(sdm.trace(), 1)