Skip to content

Commit

Permalink
Add neccessary comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tina oberoi authored and tina oberoi committed Oct 17, 2023
1 parent 5038346 commit 068da96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 11 additions & 0 deletions scratchpad/qtensor_MPS/mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, tensor_name, N, physical_dim = 1) -> None:
@staticmethod
def construct_mps_from_wavefunction(wavefunction, tensor_name, N, physical_dim = 1) -> 'MPS':
"""
Method to create wavefunction from mps
"""
if wavefunction.size != physical_dim**N:
raise ValueError()
Expand Down Expand Up @@ -116,6 +117,7 @@ def get_wavefunction(self) -> np.array:

def apply_single_qubit_gate(self, gate, index) -> None:
"""
Method to apply single qubit gate on mps
Assumption: Gates are unitary
0
Expand All @@ -137,6 +139,8 @@ def apply_single_qubit_gate(self, gate, index) -> None:

def apply_two_qubit_gate(self, gate, operating_qubits):
"""
Method to apply two qubit gates on mps
0 1
| |
gate
Expand Down Expand Up @@ -200,6 +204,9 @@ def apply_two_qubit_gate(self, gate, operating_qubits):
self._nodes[operating_qubits[1]] = new_right

def inner_product(self, wMPS):
"""
Method to calculate inner product of mps
"""

T = self.get_mps_nodes(False)
W = wMPS.get_mps_nodes(False)
Expand All @@ -218,9 +225,13 @@ def inner_product(self, wMPS):
return np.complex128((tn.contract_between(T[-1], W[-1])).tensor)

def get_norm(self):
"""
Method to calculate norm of mps
"""
return np.sqrt(self.inner_product(self).real)

def get_expectation(self):
pass



Expand Down
5 changes: 1 addition & 4 deletions scratchpad/qtensor_MPS/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,4 @@ def test_apply_gate_for_ghz_circuit():
mps.apply_two_qubit_gate(cnot(), [0,1])
mps.apply_two_qubit_gate(cnot(), [1,2])
assert mps.get_norm() == 1
assert np.allclose(mps.get_wavefunction(), np.array([ 0.7071, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7071], dtype=np.complex64))


test_apply_one_qubit_mps_operation_xgate()
assert np.allclose(mps.get_wavefunction(), np.array([ 0.7071, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7071], dtype=np.complex64))

0 comments on commit 068da96

Please sign in to comment.