Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2a5f6f8
Update supported gates, API interface
jbrixon Jan 22, 2024
e696864
Update params for sampler local sim
jbrixon Jan 24, 2024
8b56a64
Update docs
jbrixon Jan 24, 2024
c318179
Remove unsupported match statement
jbrixon Jan 25, 2024
783d624
updated access.md
fg-aqt Jan 25, 2024
1892647
Merge branch 'update-aqt' of github.com:alpine-quantum-technologies/C…
fg-aqt Jan 25, 2024
f762a64
intermediate version of getting started
fg-aqt Jan 25, 2024
1ca7f1e
Add static method to list workspaces and resources
jbrixon Jan 29, 2024
f9c0150
Remove arbitrary host params
jbrixon Jan 29, 2024
95d5368
Update documentation
jbrixon Jan 29, 2024
73e3848
Merge remote-tracking branch 'upstream/main' into update-aqt
jbrixon Jan 29, 2024
919c037
Update noise model
jbrixon Jan 30, 2024
3a77f78
Remove unused cast
jbrixon Feb 1, 2024
17ceb6a
Merge branch 'main' of https://github.com/quantumlib/Cirq into update…
jbrixon Feb 5, 2024
86f5eab
Merge pull request #1 from alpine-quantum-technologies/update-aqt
jbrixon Feb 5, 2024
7f710ef
Improve return type of new method
jbrixon Feb 12, 2024
22b169d
Move default host to constant
jbrixon Feb 12, 2024
b6c4a8d
Raise error if op gate is None
jbrixon Feb 12, 2024
6eedf21
Fix get crosstalk operation
jbrixon Feb 12, 2024
efc7aec
Update docstring for accuracy
jbrixon Feb 12, 2024
5b8c796
Apply formatting
jbrixon Feb 12, 2024
db0522c
Merge branch 'main' of https://github.com/quantumlib/Cirq
jbrixon Feb 12, 2024
ddfc44d
Refactor fetch resource static function
jbrixon Mar 1, 2024
61c9205
Add enum for operation strings
jbrixon Mar 1, 2024
8617718
Fix formatting
jbrixon Mar 1, 2024
cd39a7a
Fix type errors
jbrixon Mar 1, 2024
43972cb
Linting
jbrixon Mar 1, 2024
950e84a
Add enum docs
jbrixon Mar 26, 2024
4ace5b9
Merge branch 'main' of https://github.com/quantumlib/Cirq
jbrixon Mar 26, 2024
270b833
Remove unsupported import
jbrixon Mar 26, 2024
6ac86f4
Fix noise dict keys
jbrixon Mar 26, 2024
c708567
Format
jbrixon Apr 3, 2024
0dac7f0
Fix enum string conversion
jbrixon Apr 3, 2024
0f99427
Merge branch 'main' of https://github.com/quantumlib/Cirq
jbrixon Apr 3, 2024
6186b62
Fix formatting
jbrixon Apr 15, 2024
3fb723d
Remove redundant counter
jbrixon Apr 15, 2024
8e2eba7
Add test for operation with None gate
jbrixon Apr 15, 2024
234e38e
Add tests for static methods
jbrixon Apr 15, 2024
e6a32a0
Remove unreachable code
jbrixon Apr 15, 2024
4480c38
Fix formatting
jbrixon Apr 15, 2024
dab7e05
Merge branch 'main' into main
jbrixon Apr 15, 2024
fd6e8c9
Merge branch 'main' into main
jbrixon Apr 19, 2024
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
43 changes: 29 additions & 14 deletions cirq-aqt/cirq_aqt/aqt_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,11 +37,18 @@
gate_dict = {'X': cirq.X, 'Y': cirq.Y, 'Z': cirq.Z, 'MS': cirq.XX, 'R': cirq.PhasedXPowGate}


class OperationString(Enum):
Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks - fixed.

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:
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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
"""
Expand All @@ -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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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:
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this use the enum values?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes! Fixed. Thanks

'MS': cirq.depolarize(1e-2),
'crosstalk': 0.03,
}
Expand Down
2 changes: 0 additions & 2 deletions cirq-aqt/cirq_aqt/aqt_device_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ def __init__(
self._gate_durations = {
cirq.GateFamily(cirq.MeasurementGate): self._measurement_duration,
cirq.GateFamily(cirq.XXPowGate): self._twoq_gates_duration,
cirq.GateFamily(cirq.XPowGate): self._oneq_gates_duration,
cirq.GateFamily(cirq.YPowGate): self._oneq_gates_duration,
cirq.GateFamily(cirq.ZPowGate): self._oneq_gates_duration,
cirq.GateFamily(cirq.PhasedXPowGate): self._oneq_gates_duration,
}
Expand Down
2 changes: 1 addition & 1 deletion cirq-aqt/cirq_aqt/aqt_device_metadata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_aqtdevice_metadata(metadata, qubits):
assert len(edges) == 10
assert all(q0 != q1 for q0, q1 in edges)
assert AQTTargetGateset() == metadata.gateset
assert len(metadata.gate_durations) == 6
assert len(metadata.gate_durations) == 4


def test_aqtdevice_duration_of(metadata, qubits):
Expand Down
Loading