From e1c56e59d63eceaef84991e447068bd17c08784c Mon Sep 17 00:00:00 2001 From: Zhaoyilunnn Date: Fri, 11 Aug 2023 03:48:53 +0000 Subject: [PATCH] fix: partial measurement error --- setup.py | 2 +- src/quafu/results/results.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 9d86fcc..1edfc48 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setup( name="pyquafu", - version="0.3.4", + version="0.3.5", author="ssli", author_email="ssli@iphy.ac.cn", url="https://github.com/ScQ-Cloud/pyquafu", diff --git a/src/quafu/results/results.py b/src/quafu/results/results.py index 3f3ce69..e78a2b9 100644 --- a/src/quafu/results/results.py +++ b/src/quafu/results/results.py @@ -11,9 +11,9 @@ class Result(object): class ExecResult(Result): - """ + """ Class that save the execute results returned from backend. - + Attributes: counts (dict): Samples counts on each bitstring. probabilities (dict): Calculated probabilities on each bitstring. @@ -29,8 +29,10 @@ def __init__(self, input_dict, measures): self.counts = OrderedDict(sorted(self.res.items(), key=lambda s: s[0])) self.logicalq_res = {} cbits = list(self.measures.values()) + indexed_cbits = {bit: i for i, bit in enumerate(sorted(cbits))} + squeezed_cbits = [indexed_cbits[bit] for bit in cbits] for key, values in self.counts.items(): - newkey = "".join([key[i] for i in cbits]) + newkey = "".join([key[i] for i in squeezed_cbits]) self.logicalq_res[newkey] = values self.taskid = input_dict['task_id'] @@ -49,7 +51,7 @@ def calculate_obs(self, pos): """ Calculate observables Z on input position using probabilities - Args: + Args: pos (list[int]): Positions of observalbes. """ return measure_obs(pos, self.logicalq_res) @@ -89,11 +91,11 @@ def __init__(self, input, input_form): def plot_probabilities(self, full: bool = False, reverse_basis: bool = False, sort: bool = None): """ Plot the probabilities from simulated results, ordered in big endian convention. - + Args: full: Whether plot on the full basis of measured qubits. reverse_basis: Whether reverse the bitstring of basis. (Little endian convention). - sort: Sort the results by probabilities values. Can be `"ascend"` order or `"descend"` order. + sort: Sort the results by probabilities values. Can be `"ascend"` order or `"descend"` order. """ probs = self.probabilities