improve/add subsystem docstrings
@@ -23,8 +23,17 @@ from qiskit.tools.qi.qi import partial_trace
def get_subsystem_statevector(statevector, trace_systems):
- # trace system is a list of qubits one wants to trace. E.g.
- # to trace qubits 0 and 4 trace_systems = [0,4]
+ """
+ Compute the statevector of the quantum subsystem.
+
+ Args:
+ statevector (list|array): The state vector of the complete system
+ trace_systems (list|range): The indices of the qubits to be traced.
+ to trace qubits 0 and 4 trace_systems = [0,4]
+
+ Returns:
+ The state vector of the desired subsystem
+ """
rho = np.outer(statevector, statevector)
rho_sub = partial_trace(rho, trace_systems)
u, s, v = np.linalg.svd(rho_sub)
@@ -33,6 +42,18 @@ def get_subsystem_statevector(statevector, trace_systems):
def get_subsystem_fidelity(statevector, trace_systems, subsystem_state):
+ """
+ Compute the fidelity of the quantum subsystem.
+
+ Args:
+ statevector (list|array): The state vector of the complete system
+ trace_systems (list|range): The indices of the qubits to be traced.
+ to trace qubits 0 and 4 trace_systems = [0,4]
+ subsystem_state (list|array): The ground-truth state vector of the subsystem
+
+ Returns:
+ The subsystem fidelity
+ """
rho = np.outer(np.conj(statevector), statevector)
rho_sub = partial_trace(rho, trace_systems)
rho_sub_in = np.outer(np.conj(subsystem_state), subsystem_state)
@@ -48,6 +69,26 @@ def get_subsystem_fidelity(statevector, trace_systems, subsystem_state):
def get_subsystems_counts(complete_system_counts):
+ """
+ Extract all subsystems' counts from the single complete system count dictionary.
+
+ If multiple classical registers are used to measure various parts of a quantum system,
+ Each of the measurement dictionary's keys would contain spaces as delimiters to separate
+ the various parts being measured. For example, you might have three keys
+ '11 010', '01 011' and '11 011', among many other, in the count dictionary of the
+ 5-qubit complete system, and would like to get the two subsystems' counts
+ (one 2-qubit, and the other 3-qubit) in order to get the counts for the 2-qubit
+ partial measurement '11' or the 3-qubit partial measurement '011'.
+
+
+ Args:
+ complete_system_counts (dict): The measurement count dictionary of a complete system
+ that contains multiple classical registers for measurements s.t. the dictionary's
+ keys have space delimiters.
+
+ Returns:
+ A list of measurement count dictionaries corresponding to each of the subsystems measured.
+ """
mixed_measurements = list(complete_system_counts)
subsystems_counts = [defaultdict(int) for _ in mixed_measurements[0].split()]
for mixed_measurement in mixed_measurements:
