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

cirq-google: Remove SerializableGateSet #5762

Merged
Show file tree
Hide file tree
Changes from 6 commits
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
6 changes: 0 additions & 6 deletions cirq-google/cirq_google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@
GateOpSerializer,
Serializer,
SerializingArg,
SerializableGateSet,
XMON,
FSIM_GATESET,
SQRT_ISWAP_GATESET,
SYC_GATESET,
NAMED_GATESETS,
)

from cirq_google.workflow import (
Expand Down
93 changes: 46 additions & 47 deletions cirq-google/cirq_google/calibration/phased_fsim_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,55 +222,54 @@ def test_floquet_to_calibration_layer_with_measure_qubits():


def test_xeb_to_calibration_layer():
with cirq.testing.assert_deprecated('SerializableGateSet', deadline='v0.16', count=None):
q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)]
gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
request = XEBPhasedFSimCalibrationRequest(
gate=gate,
pairs=((q_00, q_01), (q_02, q_03)),
options=XEBPhasedFSimCalibrationOptions(
n_library_circuits=22,
fsim_options=XEBPhasedFSimCharacterizationOptions(
characterize_theta=True,
characterize_zeta=True,
characterize_chi=False,
characterize_gamma=False,
characterize_phi=True,
),
q_00, q_01, q_02, q_03 = [cirq.GridQubit(0, index) for index in range(4)]
gate = cirq.FSimGate(theta=np.pi / 4, phi=0.0)
request = XEBPhasedFSimCalibrationRequest(
gate=gate,
pairs=((q_00, q_01), (q_02, q_03)),
options=XEBPhasedFSimCalibrationOptions(
n_library_circuits=22,
fsim_options=XEBPhasedFSimCharacterizationOptions(
characterize_theta=True,
characterize_zeta=True,
characterize_chi=False,
characterize_gamma=False,
characterize_phi=True,
),
)
layer = request.to_calibration_layer()
assert layer == cirq_google.CalibrationLayer(
calibration_type='xeb_phased_fsim_characterization',
program=cirq.Circuit([gate.on(q_00, q_01), gate.on(q_02, q_03)]),
args={
'n_library_circuits': 22,
'n_combinations': 10,
'cycle_depths': '5_25_50_100_200_300',
'fatol': 5e-3,
'xatol': 5e-3,
'characterize_theta': True,
'characterize_zeta': True,
'characterize_chi': False,
'characterize_gamma': False,
'characterize_phi': True,
},
)
),
)
layer = request.to_calibration_layer()
assert layer == cirq_google.CalibrationLayer(
calibration_type='xeb_phased_fsim_characterization',
program=cirq.Circuit([gate.on(q_00, q_01), gate.on(q_02, q_03)]),
args={
'n_library_circuits': 22,
'n_combinations': 10,
'cycle_depths': '5_25_50_100_200_300',
'fatol': 5e-3,
'xatol': 5e-3,
'characterize_theta': True,
'characterize_zeta': True,
'characterize_chi': False,
'characterize_gamma': False,
'characterize_phi': True,
},
)

# Serialize to proto
calibration = v2.calibration_pb2.FocusedCalibration()
new_layer = calibration.layers.add()
new_layer.calibration_type = layer.calibration_type
for arg in layer.args:
arg_to_proto(layer.args[arg], out=new_layer.args[arg])
cirq_google.SQRT_ISWAP_GATESET.serialize(layer.program, msg=new_layer.layer)
with open(os.path.dirname(__file__) + '/test_data/xeb_calibration_layer.textproto') as f:
desired_textproto = f.read()

layer_str = str(new_layer)
# Fix precision issues
layer_str = re.sub(r'0.004999\d+', '0.005', layer_str)
assert layer_str == desired_textproto
# Serialize to proto
calibration = v2.calibration_pb2.FocusedCalibration()
new_layer = calibration.layers.add()
new_layer.calibration_type = layer.calibration_type
for arg in layer.args:
arg_to_proto(layer.args[arg], out=new_layer.args[arg])
cirq_google.CIRCUIT_SERIALIZER.serialize(layer.program, msg=new_layer.layer)
with open(os.path.dirname(__file__) + '/test_data/xeb_calibration_layer.textproto') as f:
desired_textproto = f.read()

layer_str = str(new_layer)
# Fix precision issues
layer_str = re.sub(r'0.004999\d+', '0.005', layer_str)
assert layer_str == desired_textproto


def test_from_moment():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,58 @@
calibration_type: "xeb_phased_fsim_characterization"
layer {
language {
gate_set: "sqrt_iswap"
gate_set: "v2_5"
arg_function_language: "exp"
}
circuit {
scheduling_strategy: MOMENT_BY_MOMENT
moments {
operations {
gate {
id: "fsim_pi_4"
}
qubits {
id: "0_0"
}
qubits {
id: "0_1"
qubit_constant_index: 0
qubit_constant_index: 1
fsimgate {
theta {
float_value: 0.7853981852531433
}
phi {
float_value: 0.0
}
}
}
operations {
gate {
id: "fsim_pi_4"
}
qubits {
id: "0_2"
}
qubits {
id: "0_3"
qubit_constant_index: 2
qubit_constant_index: 3
fsimgate {
theta {
float_value: 0.7853981852531433
}
phi {
float_value: 0.0
}
}
}
}
}
constants {
qubit {
id: "0_0"
}
}
constants {
qubit {
id: "0_1"
}
}
constants {
qubit {
id: "0_2"
}
}
constants {
qubit {
id: "0_3"
}
}
}
args {
key: "characterize_chi"
Expand Down
19 changes: 2 additions & 17 deletions cirq-google/cirq_google/engine/engine_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,12 @@
from cirq_google.engine.result_type import ResultType
from cirq_google.api import v2
from cirq_google.engine import engine_job
from cirq_google.serialization import gate_sets
from cirq_google.serialization import circuit_serializer

if TYPE_CHECKING:
import cirq_google.engine.engine as engine_base


_GOOGLE_GATESETS = [
gate_sets.SYC_GATESET,
gate_sets.SQRT_ISWAP_GATESET,
gate_sets.FSIM_GATESET,
gate_sets.XMON,
]


class EngineProgram(abstract_program.AbstractProgram):
"""A program created via the Quantum Engine API.

Expand Down Expand Up @@ -563,13 +555,6 @@ def _deserialize_program(code: any_pb2.Any, program_num: Optional[int] = None) -

program = batch.programs[program_num]
if program is not None:
# TODO(#5050) Move to CircuitSerializer
gate_set_map = {g.name: g for g in _GOOGLE_GATESETS}
if program.language.gate_set not in gate_set_map:
raise ValueError(
f'Unknown gateset {program.language.gate_set}. '
f'Supported gatesets: {list(gate_set_map.keys())}.'
)
return gate_set_map[program.language.gate_set].deserialize(program)
return circuit_serializer.CIRCUIT_SERIALIZER.deserialize(program)

raise ValueError(f'unsupported program type: {code_type}')
112 changes: 40 additions & 72 deletions cirq-google/cirq_google/engine/engine_program_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,64 +33,48 @@
_BATCH_PROGRAM_V2 = util.pack_any(
Merge(
"""programs { language {
gate_set: "xmon"
gate_set: "v2_5"
arg_function_language: "exp"
}
circuit {
scheduling_strategy: MOMENT_BY_MOMENT
moments {
operations {
gate {
id: "xy"
}
args {
key: "axis_half_turns"
value {
arg_value {
float_value: 0.0
}
qubit_constant_index: 0
phasedxpowgate {
phase_exponent {
float_value: 0.0
}
}
args {
key: "half_turns"
value {
arg_value {
float_value: 0.5
}
exponent {
float_value: 0.5
}
}
qubits {
id: "5_2"
}
}
}
moments {
operations {
gate {
id: "meas"
}
args {
key: "invert_mask"
value {
qubit_constant_index: 0
measurementgate {
key {
arg_value {
bool_values {
}
string_value: "result"
}
}
}
args {
key: "key"
value {
invert_mask {
arg_value {
string_value: "result"
bool_values {
}
}
}
}
qubits {
id: "5_2"
}
}
}
}
constants {
qubit {
id: "5_2"
}
}
}
""",
v2.batch_pb2.BatchProgram(),
Expand All @@ -100,64 +84,48 @@
_PROGRAM_V2 = util.pack_any(
Merge(
"""language {
gate_set: "xmon"
gate_set: "v2_5"
arg_function_language: "exp"
}
circuit {
scheduling_strategy: MOMENT_BY_MOMENT
moments {
operations {
gate {
id: "xy"
}
args {
key: "axis_half_turns"
value {
arg_value {
float_value: 0.0
}
qubit_constant_index: 0
phasedxpowgate {
phase_exponent {
float_value: 0.0
}
}
args {
key: "half_turns"
value {
arg_value {
float_value: 0.5
}
exponent {
float_value: 0.5
}
}
qubits {
id: "5_2"
}
}
}
moments {
operations {
gate {
id: "meas"
}
args {
key: "invert_mask"
value {
qubit_constant_index: 0
measurementgate {
key {
arg_value {
bool_values {
}
string_value: "result"
}
}
}
args {
key: "key"
value {
invert_mask {
arg_value {
string_value: "result"
bool_values {
}
}
}
}
qubits {
id: "5_2"
}
}
}
}
constants {
qubit {
id: "5_2"
}
}
""",
v2.program_pb2.Program(),
)
Expand Down
Loading