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

Utilities for approximate hardware noise #4671

Merged
merged 5 commits into from
Dec 13, 2021

Conversation

95-martin-orion
Copy link
Collaborator

@95-martin-orion 95-martin-orion commented Nov 12, 2021

This PR is part of #4640. It adds utility functions and objects for use in noise model generation.

Key changes include:

  • Extraction of noise metric conversion methods from NoiseProperties. All top-level functions in this PR except decoherence_pauli_error were copied directly from the existing NoiseProperties class. These methods will be removed from NoiseProperties in an upcoming PR.
  • Addition of decoherence_pauli_error. This method is copied from internal noise-generation tools.
  • Addition of OpIdentifier class. This class is used as a key for noise-insertion maps.
  • Addition of PHYSICAL_GATE_TAG. This tag is applied to "real" gates during noise model generation to prevent sequential noise models from applying noise to noise generated by a previous noise model.

@95-martin-orion 95-martin-orion requested review from cduck, vtomole and a team as code owners November 12, 2021 17:35
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 12, 2021
@CirqBot CirqBot added the size: L 250< lines changed <1000 label Nov 12, 2021
@MichaelBroughton MichaelBroughton self-assigned this Nov 12, 2021
cirq-core/cirq/devices/noise_utils.py Outdated Show resolved Hide resolved


@dataclass(frozen=True)
class OpIdentifier:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this class really needed ? (having looked at other PRs as well).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could probably get away without it, but the result would be a lot messier. Here are the alternatives I considered:

  • Just use Operation (it's hashable and contains the required info): this requires every current OpIdentifier reference to have some concept of "canonical" gates for each type supported in noise model generation (e.g. the PhasedXZGate constructor requires (x|z|axis_phase)_exponent args). This is considerably less convenient than just converting OpIDs to Operations during serialization.
  • Use a (Gate, qubits) tuple: this works about the same as OpIdentifier, but it's ultimately less readable to be saying op_id[0] and op_id[1:] instead of op_id.gate_type and op_id.qubits

If you have any other recommendations, I'm happy to consider them, but my sense from working through this is that OpIdentifier adds readability for relatively little cost. I opted not to surface OpIdentifier at the cirq package level to avoid any potential confusion.

cirq-core/cirq/devices/noise_utils.py Outdated Show resolved Hide resolved
cirq-core/cirq/devices/noise_utils.py Show resolved Hide resolved
@95-martin-orion
Copy link
Collaborator Author

Needed some force-pushing to bring in the GateFamily changes, but OpIdentifier now relies on a GateFamily under the hood for matching operations.

Copy link
Collaborator

@dkafri dkafri left a comment

Choose a reason for hiding this comment

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

Couple more comments

cirq-core/cirq/devices/noise_utils.py Outdated Show resolved Hide resolved
)

def __contains__(self, item: Union[ops.Gate, ops.Operation]) -> bool:
if isinstance(item, ops.Gate):
Copy link
Collaborator

Choose a reason for hiding this comment

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

What would we do if we want an OpIdentifier for an Operation without a gate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

None of the models from noise required that, so I opted not to support it. Is there a particular case you have in mind?

(CircuitOperations are a definite complication as far as matching is concerned, but I don't expect them to be used as the match target for an OpIdentifier.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

In my use cases I had custom Operations that were not constructed using a Gate. I suppose the user could always generate a placeholder Gate object to identify any such Operation.

I can't give any native cirq Operation where this may be an issue since I am not so familiar with all the native cirq ops. One place you may have issues is with measurement operations. I.e. the output of cirq.measure has a gate output that is key dependent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That case should be OK - this only checks against qubits and gate types, both of which are defined explictly in the cirq.measure call. On a more general note, Cirq has been moving towards an "all operations have gates" structure (#4683), which should help with any remaining problem cases.

@95-martin-orion
Copy link
Collaborator Author

Pinging @MichaelBroughton for re-review.

Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

LGTM after snake case fix in a few of the helper functions there.

cirq-core/cirq/devices/noise_utils.py Outdated Show resolved Hide resolved
@95-martin-orion 95-martin-orion added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Dec 13, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Dec 13, 2021
@CirqBot
Copy link
Collaborator

CirqBot commented Dec 13, 2021

Automerge cancelled: A required status check is not present.

Missing statuses: ['Misc check', 'Pytest MacOS (3.7)', 'Pytest MacOS (3.8)', 'Pytest MacOS (3.9)', 'Pytest Windows (3.7)', 'Pytest Windows (3.8)', 'Pytest Windows (3.9)', 'Typescript lint check', 'Typescript tests', 'Typescript tests coverage']

@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Dec 13, 2021
@95-martin-orion 95-martin-orion merged commit 132005a into quantumlib:master Dec 13, 2021
CirqBot pushed a commit that referenced this pull request Dec 14, 2021
This PR is part of #4640. It adds the `InsertionNoiseModel`, which injects noise based on a user-defined map.

#4671 is a prerequisite for this PR. The only files that need to be reviewed in this PR are:

- `cirq-core/cirq/devices/...`
    - `__init__.py`
    - `insertion_noise_model[_test].py`
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
* Remove files for subsequent PRs

* Add coverage for OpId

* Clarify if-case

* snake_case_gamma

Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this pull request Jan 22, 2022
This PR is part of quantumlib#4640. It adds the `InsertionNoiseModel`, which injects noise based on a user-defined map.

quantumlib#4671 is a prerequisite for this PR. The only files that need to be reviewed in this PR are:

- `cirq-core/cirq/devices/...`
    - `__init__.py`
    - `insertion_noise_model[_test].py`
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
* Remove files for subsequent PRs

* Add coverage for OpId

* Clarify if-case

* snake_case_gamma

Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
This PR is part of quantumlib#4640. It adds the `InsertionNoiseModel`, which injects noise based on a user-defined map.

quantumlib#4671 is a prerequisite for this PR. The only files that need to be reviewed in this PR are:

- `cirq-core/cirq/devices/...`
    - `__init__.py`
    - `insertion_noise_model[_test].py`
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
* Remove files for subsequent PRs

* Add coverage for OpId

* Clarify if-case

* snake_case_gamma

Co-authored-by: Cirq Bot <craiggidney+github+cirqbot@google.com>
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
This PR is part of quantumlib#4640. It adds the `InsertionNoiseModel`, which injects noise based on a user-defined map.

quantumlib#4671 is a prerequisite for this PR. The only files that need to be reviewed in this PR are:

- `cirq-core/cirq/devices/...`
    - `__init__.py`
    - `insertion_noise_model[_test].py`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants