Skip to content
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

Fix uninitialised attributes in QCVV samples #1075

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

cdbf1
Copy link
Contributor

@cdbf1 cdbf1 commented Sep 24, 2024

Closes #1071

supermarq-benchmarks/supermarq/qcvv/xeb_test.py Outdated Show resolved Hide resolved
}
)
else:
warnings.warn("Sample is missing probabilities. This sample has been omitted.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might not want to repeat this warning for every missing sample


for sample in tqdm.notebook.tqdm(samples, desc="Evaluating circuits"):
sample.target_probabilities = self._simulate_sample(sample)

records = []
for sample in samples:
target_probabilities = {
f"p({key})": value for key, value in sample.target_probabilities.items()
f"p({key})": value
for key, value in sample.target_probabilities.items() # type: ignore[union-attr]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to avoid the type: ignore pragmas? e.g. with

Suggested change
for key, value in sample.target_probabilities.items() # type: ignore[union-attr]
for key, value in sample.target_probabilities.items() if sample.target_probabilities is not None

or by combining this w/ the previous loop

Copy link
Contributor Author

@cdbf1 cdbf1 Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic meant that this case was never actually reached, hence the type: ignore. Just adding the not None check to the list comprehension doesn't work unfortunately so I've added an explicit check in the loop instead.

Copy link
Contributor

@richrines1 richrines1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@cdbf1 cdbf1 merged commit 5efa23d into main Oct 2, 2024
20 checks passed
@cdbf1 cdbf1 deleted the fix/qcvv_sample_missing_components branch October 2, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QCVV sample repr fails if any component hasn't been generated yet
2 participants