-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix Cirq Datasets and LGST Bug #420
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1603,7 +1603,7 @@ def add_count_arrays(self, circuit, outcome_index_array, count_array, | |
self._add_raw_arrays(circuit, outcome_index_array, time_array, count_array, | ||
overwriteExisting, record_zero_counts, aux) | ||
|
||
def add_cirq_trial_result(self, circuit, trial_result, key): | ||
def add_cirq_trial_result(self, circuit, trial_result, key, convert_int_to_binary = True, num_qubits = None): | ||
""" | ||
Add a single circuit's counts --- stored in a Cirq TrialResult --- to this DataSet | ||
|
||
|
@@ -1619,6 +1619,16 @@ def add_cirq_trial_result(self, circuit, trial_result, key): | |
key : str | ||
The string key of the measurement. Set by cirq.measure. | ||
|
||
convert_int_to_binary : bool, optional (defaut True) | ||
By default the keys in the cirq Results object are the integers representing | ||
the bitstrings of the measurements on a set of qubits, in big-endian convention. | ||
If True this uses the cirq function `cirq.big_endian_int_to_bits` to convert back | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering if we were going to get bit by endian-ness... Nice job covering that edge case! |
||
to a binary string before adding the counts as a entry into the pygsti dataset. | ||
|
||
num_qubits : int, optional (default None) | ||
Number of qubits used in the conversion from integers to binary when convert_int_to_binary | ||
is True. If None, then the number of line_labels on the input circuit is used. | ||
|
||
Returns | ||
------- | ||
None | ||
|
@@ -1631,8 +1641,17 @@ def add_cirq_trial_result(self, circuit, trial_result, key): | |
|
||
# TrialResult.histogram returns a collections.Counter object, which is a subclass of dict. | ||
histogram_counter = trial_result.histogram(key=key) | ||
|
||
if num_qubits is None: | ||
num_qubits = len(circuit.line_labels) | ||
|
||
# The keys in histogram_counter are integers, but pyGSTi likes dictionary keys to be strings. | ||
count_dict = {str(key): value for key, value in histogram_counter.items()} | ||
count_dict = {} | ||
for key, value in histogram_counter.items(): | ||
if convert_int_to_binary: | ||
count_dict[_np.binary_repr(key, width= num_qubits)] = value | ||
else: | ||
count_dict[str(key)] = value | ||
self.add_count_dict(circuit, count_dict) | ||
|
||
def add_raw_series_data(self, circuit, outcome_label_list, time_stamp_list, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, exactly the bugfix I was thinking of!