Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaoberoi committed Jan 22, 2024
1 parent 8583a1a commit 8313a5b
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions scratchpad/qtensor_MPS/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ def test_apply_one_qubit_mps_operation_xgate():
def test_apply_twoq_cnot_two_qubits():
# In the following tests, the first qubit is always the control qubit.
# Check that CNOT|10> = |11>
mps = MPS("q", 4, 2)
mps = MPS("q", 2, 2)
assert np.isclose(mps.get_norm(), 1.0)

# mps.apply_single_qubit_gate(xgate(), 0)
mps.apply_two_qubit_gate(cnot(), [1, 2])
# assert np.isclose(mps.get_norm(), 1.0)
# assert np.allclose(
# mps.get_wavefunction(), np.array([0.0, 0.0, 0.0, 1.0], dtype=np.complex64)
# )
mps.apply_single_qubit_gate(xgate(), 0)
mps.apply_two_qubit_gate(cnot(), [0, 1])
print(mps.get_wavefunction())
assert np.isclose(mps.get_norm(), 1.0)
assert np.allclose(
mps.get_wavefunction(), np.array([0.0, 0.0, 0.0, 1.0], dtype=np.complex64)
)


def test_apply_two_twoq_cnot_two_qubits():
Expand Down Expand Up @@ -168,16 +169,6 @@ def test_mps_mpo():
assert np.isclose(allmps[i].inner_product(allmps[j]), i == j)


def test_mpo_two_qubit():
mpo_layer = MPOLayer("q", 4, 2)
# print("BEFORE")
# print(mpo_layer._nodes)
mpo_layer.add_two_qubit_gate(cnot(), [1, 2])
print("AFTER")
print(mpo_layer._nodes)
# assert (mps1.get_wavefunction() == mps2.get_wavefunction()).all()


def test_mpo_single_qubit_gate():
mps1 = MPS("q", 2, 2)
mps1.apply_single_qubit_gate(xgate(), 0)
Expand Down Expand Up @@ -260,7 +251,6 @@ def test_mpo_mps_inner_prod():
mpo.construct_mpo(pauli_string)

mps1 = MPS("q", n, 2)
# mps1.apply_single_qubit_gate(xgate(), 1)

inner_prod1 = mpo.mpo_mps_inner_prod(mps1)
condition1 = np.allclose(
Expand Down

0 comments on commit 8313a5b

Please sign in to comment.