Add docstring

This commit is contained in:
tankya2
2024-03-04 14:52:47 +08:00
parent fb5b755fe4
commit bcacd9dc57
2 changed files with 62 additions and 2 deletions

View File

@@ -26,6 +26,11 @@ class QiboCircuitToEinsum:
self.circuit = circuit
def state_vector_operands(self):
"""Create the operands for expectation computation in the interleave format.
Returns:
Operands for the contraction in the interleave format.
"""
input_bitstring = "0" * len(self.active_qubits)
input_operands = self._get_bitstring_tensors(input_bitstring)
@@ -84,6 +89,17 @@ class QiboCircuitToEinsum:
return (2, 2) * nqubits
def init_intermediate_circuit(self, circuit):
"""Initialize the intermediate circuit representation.
This method initializes the intermediate circuit representation by extracting gate matrices and qubit IDs
from the given quantum circuit.
Parameters:
circuit (object): The quantum circuit object.
Returns:
None
"""
self.gate_tensors = []
gates_qubits = []
@@ -105,6 +121,18 @@ class QiboCircuitToEinsum:
self.active_qubits = np.unique(gates_qubits)
def init_basis_map(self, backend, dtype):
"""Initialize the basis map for the quantum circuit.
This method initializes a basis map for the quantum circuit, which maps binary
strings representing qubit states to their corresponding quantum state vectors.
Parameters:
backend (object): The backend object providing the array conversion method.
dtype (object): The data type for the quantum state vectors.
Returns:
None
"""
asarray = backend.asarray
state_0 = asarray([1, 0], dtype=dtype)
state_1 = asarray([0, 1], dtype=dtype)
@@ -112,6 +140,17 @@ class QiboCircuitToEinsum:
self.basis_map = {"0": state_0, "1": state_1}
def init_inverse_circuit(self, circuit):
"""Initialize the inverse circuit representation.
This method initializes the inverse circuit representation by extracting gate matrices and qubit IDs
from the given quantum circuit.
Parameters:
circuit (object): The quantum circuit object.
Returns:
None
"""
self.gate_tensors_inverse = []
gates_qubits_inverse = []
@@ -159,6 +198,14 @@ class QiboCircuitToEinsum:
return gates
def expectation_operands(self, pauli_string):
"""Create the operands for pauli string expectation computation in the interleave format.
Args:
pauli_string: A string representating the list of pauli gates.
Returns:
Operands for the contraction in the interleave format.
"""
input_bitstring = "0" * self.circuit.nqubits
input_operands = self._get_bitstring_tensors(input_bitstring)