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

refactor: drop BasePrimitiveResult.experiments and BasePrimitiveResult.num_experiments #63

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zne/meta/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def result(self) -> EstimatorResult:
result: EstimatorResult = self.base_job.result()
if self.zne_strategy.performs_zne:
result = self.zne_strategy.mitigate_noisy_result(result)
if result.num_experiments != self.target_num_experiments:
if len(result.values) != self.target_num_experiments:
# TODO: consider warning instead -> should be in integration tests
raise RuntimeError(
"Number of experiments in EstimatorResult object does not match "
Expand Down
10 changes: 5 additions & 5 deletions zne/zne_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ def _generate_noisy_result_groups(
but same circuit-observable combinations.

Raises:
ValueError: If the number of performed experiments is not an integer mutliple of
ValueError: If the number of performed experiments is not an integer multiple of
the number of noise factors.
"""
if noisy_result.num_experiments % self.num_noise_factors != 0:
if len(noisy_result.values) % self.num_noise_factors != 0:
raise ValueError("Inconsistent number of noisy experiments and noise factors.")
for group in group_elements_gen(
noisy_result.experiments, group_size=self.num_noise_factors
[ {'value': v, 'metadata': noisy_result.metadata[i]} for i,v in enumerate(noisy_result.values)], group_size=self.num_noise_factors
1ucian0 marked this conversation as resolved.
Show resolved Hide resolved
): # type: tuple[EstimatorResultData, ...]
values, metadata = zip(*[data.values() for data in group])
yield EstimatorResult(values=array(values), metadata=list(metadata))
Expand All @@ -290,7 +290,7 @@ def _regression_data_from_result_group(
Returns:
Regression data
"""
if result_group.num_experiments != self.num_noise_factors:
if len(result_group.values) != self.num_noise_factors:
raise ValueError("Inconsistent number of noisy experiments and noise factors.")
x_data = list(self.noise_factors) # TODO: get actual noise factors achieved
y_data = result_group.values.tolist()
Expand All @@ -316,7 +316,7 @@ def build_zne_metadata(
"""
if extrapolation is None:
extrapolation = {}
if result_group.num_experiments != self.num_noise_factors:
if len(result_group.values) != self.num_noise_factors:
raise ValueError("Inconsistent number of noisy experiments and noise factors.")
noise_amplification: Metadata = {
"noise_amplifier": self.noise_amplifier,
Expand Down
Loading