Skip to content

Commit

Permalink
fix: partial measurement error
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaoyilunnn committed Aug 11, 2023
1 parent 6ea2a8c commit e1c56e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

setup(
name="pyquafu",
version="0.3.4",
version="0.3.5",
author="ssli",
author_email="[email protected]",
url="https://github.com/ScQ-Cloud/pyquafu",
Expand Down
14 changes: 8 additions & 6 deletions src/quafu/results/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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']
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e1c56e5

Please sign in to comment.