From 068da968551081d451dfd3630f0ff177bb30795f Mon Sep 17 00:00:00 2001 From: tina oberoi Date: Tue, 17 Oct 2023 11:27:26 -0500 Subject: [PATCH] Add neccessary comments --- scratchpad/qtensor_MPS/mps.py | 11 +++++++++++ scratchpad/qtensor_MPS/test.py | 5 +---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scratchpad/qtensor_MPS/mps.py b/scratchpad/qtensor_MPS/mps.py index 5e6a63af..2d25db62 100644 --- a/scratchpad/qtensor_MPS/mps.py +++ b/scratchpad/qtensor_MPS/mps.py @@ -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() @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/scratchpad/qtensor_MPS/test.py b/scratchpad/qtensor_MPS/test.py index 475b764f..4773d2f2 100644 --- a/scratchpad/qtensor_MPS/test.py +++ b/scratchpad/qtensor_MPS/test.py @@ -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() \ No newline at end of file + 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)) \ No newline at end of file