Skip to content

Commit

Permalink
Merge pull request qiskit-community/qiskit-aqua#794 from richardyoung…
Browse files Browse the repository at this point in the history
…00/master

qiskit-community/qiskit-aqua#793 support Quantum Post-Selection for processing counts
  • Loading branch information
woodsp-ibm authored Jan 31, 2020
2 parents 66b4e8c + 1c95764 commit 985a848
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions qiskit/aqua/utils/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2019.
# (C) Copyright IBM 2018, 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -64,7 +64,7 @@ def get_subsystem_fidelity(statevector, trace_systems, subsystem_state):
return fidelity


def get_subsystems_counts(complete_system_counts):
def get_subsystems_counts(complete_system_counts, post_select_index=None, post_select_flag=None):
"""
Extract all subsystems' counts from the single complete system count dictionary.
Expand All @@ -76,11 +76,19 @@ def get_subsystems_counts(complete_system_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'.
If the post_select_index and post_select_flag parameter are specified, the counts are
returned subject to that specific post selection, that is, the counts for all subsystems where
the subsystem at index post_select_index is equal to post_select_flag.
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.
post_select_index (int): Optional, the index of the subsystem to apply the post selection
to.
post_select_flag (str): Optional, the post selection value to apply to the subsystem
at index post_select_index.
Returns:
list: A list of measurement count dictionaries corresponding to
Expand All @@ -90,6 +98,9 @@ def get_subsystems_counts(complete_system_counts):
subsystems_counts = [defaultdict(int) for _ in mixed_measurements[0].split()]
for mixed_measurement in mixed_measurements:
count = complete_system_counts[mixed_measurement]
for k, d_l in zip(mixed_measurement.split(), subsystems_counts):
d_l[k] += count
subsystem_measurements = mixed_measurement.split()
for k, d_l in zip(subsystem_measurements, subsystems_counts):
if (post_select_index is None or
subsystem_measurements[post_select_index] == post_select_flag):
d_l[k] += count
return [dict(d) for d in subsystems_counts]

0 comments on commit 985a848

Please sign in to comment.