-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update AQT Backend #6441
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
Update AQT Backend #6441
Changes from 27 commits
2a5f6f8
e696864
8b56a64
c318179
783d624
1892647
f762a64
1ca7f1e
f9c0150
95d5368
73e3848
919c037
3a77f78
17ceb6a
86f5eab
7f710ef
22b169d
b6c4a8d
6eedf21
efc7aec
5b8c796
db0522c
ddfc44d
61c9205
8617718
cd39a7a
43972cb
950e84a
4ace5b9
270b833
6ac86f4
c708567
0dac7f0
0f99427
6186b62
3fb723d
8e2eba7
234e38e
e6a32a0
4480c38
dab7e05
fd6e8c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| """ | ||
|
|
||
| import json | ||
| from enum import Enum | ||
| from typing import Any, cast, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Union | ||
|
|
||
| import networkx as nx | ||
|
|
@@ -36,11 +37,18 @@ | |
| gate_dict = {'X': cirq.X, 'Y': cirq.Y, 'Z': cirq.Z, 'MS': cirq.XX, 'R': cirq.PhasedXPowGate} | ||
|
|
||
|
|
||
| class OperationString(Enum): | ||
| MS = "MS" | ||
| Z = "Z" | ||
| R = "R" | ||
| MEASURE = "Meas" | ||
|
|
||
|
|
||
| def get_op_string(op_obj: cirq.Operation) -> str: | ||
| """Find the string representation for a given gate or operation. | ||
|
|
||
| Args: | ||
| op_obj: Gate or operation object. Gate must be one of: XXPowGate, XPowGate, YPowGate, | ||
| op_obj: Gate or operation object. Gate must be one of: XXPowGate, | ||
| ZPowGate, PhasedXPowGate, or MeasurementGate. | ||
|
|
||
| Returns: | ||
|
|
@@ -50,20 +58,16 @@ def get_op_string(op_obj: cirq.Operation) -> str: | |
| ValueError: If the gate is not one of the supported gates. | ||
| """ | ||
| if isinstance(op_obj.gate, cirq.XXPowGate): | ||
| op_str = 'MS' | ||
| elif isinstance(op_obj.gate, cirq.XPowGate): | ||
| op_str = 'X' | ||
| elif isinstance(op_obj.gate, cirq.YPowGate): | ||
| op_str = 'Y' | ||
| op_str = OperationString.MS | ||
| elif isinstance(op_obj.gate, cirq.ZPowGate): | ||
| op_str = 'Z' | ||
| op_str = OperationString.Z | ||
| elif isinstance(op_obj.gate, cirq.PhasedXPowGate): | ||
| op_str = 'R' | ||
| op_str = OperationString.R | ||
| elif isinstance(op_obj.gate, cirq.MeasurementGate): | ||
| op_str = 'Meas' | ||
| op_str = OperationString.MEASURE | ||
| else: | ||
| raise ValueError(f'Got unknown gate on operation: {op_obj}.') | ||
| return op_str | ||
| return str(op_str) | ||
|
|
||
|
|
||
| class AQTNoiseModel(cirq.NoiseModel): | ||
|
|
@@ -97,6 +101,7 @@ def noisy_moment( | |
| for qubit in op.qubits: | ||
| noise_list.append(noise_op.on(qubit)) | ||
| noise_list += self.get_crosstalk_operation(op, system_qubits) | ||
|
|
||
| return list(moment) + noise_list | ||
|
|
||
| def get_crosstalk_operation( | ||
|
|
@@ -108,6 +113,9 @@ def get_crosstalk_operation( | |
| operation: Ideal operation | ||
| system_qubits: Tuple of line qubits | ||
|
|
||
| Raises: | ||
| RuntimeError: if operation applies no gate. | ||
|
|
||
| Returns: | ||
| List of operations including crosstalk | ||
| """ | ||
|
|
@@ -122,16 +130,20 @@ def get_crosstalk_operation( | |
| for neigh_idx in neighbors: | ||
| if neigh_idx >= 0 and neigh_idx < num_qubits: | ||
| xtlk_arr[neigh_idx] = self.noise_op_dict['crosstalk'] | ||
|
|
||
| for idx in idx_list: | ||
| xtlk_arr[idx] = 0 | ||
| xtlk_op_list = [] | ||
| op_str = get_op_string(operation) | ||
| gate = cast(cirq.EigenGate, gate_dict[op_str]) | ||
|
|
||
| if len(operation.qubits) == 1: | ||
| for idx in xtlk_arr.nonzero()[0]: | ||
| exponent = operation.gate.exponent # type:ignore | ||
| exponent = exponent * xtlk_arr[idx] | ||
| xtlk_op = gate.on(system_qubits[idx]) ** exponent | ||
| if operation.gate is None: | ||
| raise RuntimeError("Operation applies no gate.") | ||
| xtlk_op = operation.gate.on(system_qubits[idx]) ** exponent | ||
|
Collaborator
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 think there needs to be a check here and on 138 to exclude the case when operation.gate is None.
Contributor
Author
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. Thanks! Fixed. |
||
| xtlk_op_list.append(xtlk_op) | ||
| elif len(operation.qubits) == 2: | ||
| for op_qubit in operation.qubits: | ||
|
|
@@ -216,10 +228,14 @@ def simulate_samples(self, repetitions: int) -> cirq.Result: | |
| noise_model = cirq.NO_NOISE | ||
| else: | ||
| noise_model = AQTNoiseModel() | ||
|
|
||
| if self.circuit == cirq.Circuit(): | ||
| raise RuntimeError('Simulate called without a valid circuit.') | ||
|
|
||
| sim = cirq.DensityMatrixSimulator(noise=noise_model) | ||
|
|
||
| result = sim.run(self.circuit, repetitions=repetitions) | ||
|
|
||
| return result | ||
|
|
||
|
|
||
|
|
@@ -342,9 +358,8 @@ def get_aqt_device(num_qubits: int) -> Tuple[AQTDevice, List[cirq.LineQubit]]: | |
| def get_default_noise_dict() -> Dict[str, Any]: | ||
| """Returns the current noise parameters""" | ||
| default_noise_dict = { | ||
| 'X': cirq.depolarize(1e-3), | ||
| 'Y': cirq.depolarize(1e-3), | ||
| 'Z': cirq.depolarize(1e-3), | ||
| 'R': cirq.depolarize(1e-3), | ||
| 'Z': cirq.depolarize(0), | ||
|
Collaborator
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. Should this use the enum values?
Contributor
Author
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. Yes! Fixed. Thanks |
||
| 'MS': cirq.depolarize(1e-2), | ||
| 'crosstalk': 0.03, | ||
| } | ||
|
|
||
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.
We should add a short docstring for this enum.
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.
Thanks - fixed.