Skip to content

Commit

Permalink
Add json serialization to SycamoreTargetGateset.
Browse files Browse the repository at this point in the history
A repr/json with tabulation set is omitted because the repr of cirq.two_qubit_gate_product_tabulation() is very long.
  • Loading branch information
verult committed Apr 29, 2022
1 parent 614d4e0 commit 512182b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions cirq-google/cirq_google/json_resolver_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _class_resolver_dictionary() -> Dict[str, ObjectFactory]:
'FloquetPhasedFSimCalibrationRequest': cirq_google.FloquetPhasedFSimCalibrationRequest,
'PhasedFSimCalibrationResult': cirq_google.PhasedFSimCalibrationResult,
'PhasedFSimCharacterization': cirq_google.PhasedFSimCharacterization,
'SycamoreTargetGateset': cirq_google.SycamoreTargetGateset,
'XEBPhasedFSimCalibrationOptions': cirq_google.XEBPhasedFSimCalibrationOptions,
'XEBPhasedFSimCalibrationRequest': cirq_google.XEBPhasedFSimCalibrationRequest,
'LocalXEBPhasedFSimCalibrationOptions': cirq_google.LocalXEBPhasedFSimCalibrationOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cirq_type": "SycamoreTargetGateset",
"atol": 1e-08,
"tabulation": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cirq_google.SycamoreTargetGateset(atol=1e-08, tabulation=None)
1 change: 0 additions & 1 deletion cirq-google/cirq_google/json_test_data/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
'WITHOUT_CHI_FLOQUET_PHASED_FSIM_CHARACTERIZATION',
'XmonDevice',
'XMON',
'SycamoreTargetGateset',
],
should_not_be_serialized=[
'AnnealSequenceSearchStrategy',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Target gateset used for compiling circuits to Sycamore + 1-q rotations + measurement gates."""

import itertools
from typing import cast, List, Optional, Sequence
from typing import cast, Any, Dict, List, Optional, Sequence

import cirq
from cirq.protocols.decompose_protocol import DecomposeResult
Expand Down Expand Up @@ -165,6 +165,12 @@ def __repr__(self) -> str:
return (
f'cirq_google.SycamoreTargetGateset('
f'atol={self.atol}, '
f'tabulation={self.tabulation}, '
f')'
f'tabulation={self.tabulation})'
)

def _json_dict_(self) -> Dict[str, Any]:
return {'atol': self.atol, 'tabulation': self.tabulation}

@classmethod
def _from_json_dict_(cls, atol, tabulation, **kwargs):
return cls(atol=atol, tabulation=tabulation)

0 comments on commit 512182b

Please sign in to comment.