diff --git a/cirq-google/cirq_google/devices/calibrations/rainbow_2021_08_26_zphase.json b/cirq-google/cirq_google/devices/calibrations/rainbow_2021_08_26_zphase.json new file mode 100644 index 00000000000..51caa3862b8 --- /dev/null +++ b/cirq-google/cirq_google/devices/calibrations/rainbow_2021_08_26_zphase.json @@ -0,0 +1,328 @@ +{ + "sqrt_iswap": { + "zeta": [ + [ + "3_2", + "4_2", + -0.004952147720840733 + ], + [ + "4_1", + "4_2", + 0.010553804246286269 + ], + [ + "4_1", + "5_1", + 0.0334242755563128 + ], + [ + "4_2", + "4_3", + -0.009366202582480007 + ], + [ + "4_2", + "5_2", + -0.03619718613370641 + ], + [ + "4_3", + "5_3", + -0.07274229551976186 + ], + [ + "5_0", + "5_1", + -0.02783814936187625 + ], + [ + "5_1", + "5_2", + -0.12219987958880157 + ], + [ + "5_1", + "6_1", + 0.02586288199026424 + ], + [ + "5_2", + "5_3", + -0.0166820540490719 + ], + [ + "5_2", + "6_2", + -0.002334001359114278 + ], + [ + "5_3", + "5_4", + -0.0017736143810708556 + ], + [ + "5_3", + "6_3", + 0.017359910712353772 + ], + [ + "5_4", + "6_4", + -0.01649046145674231 + ], + [ + "6_1", + "6_2", + -0.05576601274701388 + ], + [ + "6_2", + "6_3", + 0.014224926253997681 + ], + [ + "6_2", + "7_2", + -0.020717536209580424 + ], + [ + "6_3", + "6_4", + -0.022543144430221852 + ], + [ + "6_3", + "7_3", + 0.012427260421862634 + ], + [ + "6_4", + "6_5", + -0.008736766415422943 + ], + [ + "6_4", + "7_4", + 0.0020195760450084977 + ], + [ + "6_5", + "7_5", + 0.007706956027166934 + ], + [ + "7_2", + "7_3", + 0.03836361683306718 + ], + [ + "7_3", + "7_4", + 0.003974500203280128 + ], + [ + "7_3", + "8_3", + -0.005958056194191612 + ], + [ + "7_4", + "7_5", + -0.03552264645905741 + ], + [ + "7_4", + "8_4", + 0.012211418722824604 + ], + [ + "7_5", + "7_6", + 0.08104414423587022 + ], + [ + "7_5", + "8_5", + -0.005197301918565447 + ], + [ + "8_3", + "8_4", + 0.04820984410155822 + ], + [ + "8_4", + "8_5", + -0.16157145322532335 + ], + [ + "8_4", + "9_4", + 0.06450350562336499 + ] + ], + "gamma": [ + [ + "3_2", + "4_2", + -0.04094895320428251 + ], + [ + "4_1", + "4_2", + -0.015941439625201996 + ], + [ + "4_1", + "5_1", + 0.0028594750848207778 + ], + [ + "4_2", + "4_3", + -0.04280439943726443 + ], + [ + "4_2", + "5_2", + 0.0006578297692033978 + ], + [ + "4_3", + "5_3", + -0.03207006519116557 + ], + [ + "5_0", + "5_1", + -0.04610995515603536 + ], + [ + "5_1", + "5_2", + 0.05421888525152299 + ], + [ + "5_1", + "6_1", + -0.03926417093470117 + ], + [ + "5_2", + "5_3", + -0.05174120829160257 + ], + [ + "5_2", + "6_2", + -0.054874409004607584 + ], + [ + "5_3", + "5_4", + -0.045093126146613205 + ], + [ + "5_3", + "6_3", + -0.030809038569665104 + ], + [ + "5_4", + "6_4", + -0.07600603942671341 + ], + [ + "6_1", + "6_2", + -0.056766604975359965 + ], + [ + "6_2", + "6_3", + -0.013900058600947143 + ], + [ + "6_2", + "7_2", + 0.00813621629574698 + ], + [ + "6_3", + "6_4", + -0.0033985855808120833 + ], + [ + "6_3", + "7_3", + -0.08662463755733961 + ], + [ + "6_4", + "6_5", + -0.08738659291705697 + ], + [ + "6_4", + "7_4", + -0.03770733517409878 + ], + [ + "6_5", + "7_5", + -0.08583686199319679 + ], + [ + "7_2", + "7_3", + -0.06216879619978931 + ], + [ + "7_3", + "7_4", + -0.028727080857906827 + ], + [ + "7_3", + "8_3", + -0.0012431994692639226 + ], + [ + "7_4", + "7_5", + -0.05657694228553869 + ], + [ + "7_4", + "8_4", + -0.0739624385266845 + ], + [ + "7_5", + "7_6", + -0.050465987108831475 + ], + [ + "7_5", + "8_5", + -0.08337907095794614 + ], + [ + "8_3", + "8_4", + 0.009458583378995758 + ], + [ + "8_4", + "8_5", + 0.010152617835290378 + ], + [ + "8_4", + "9_4", + -0.09413527546648671 + ] + ] + } +} \ No newline at end of file diff --git a/cirq-google/cirq_google/devices/calibrations/weber_2021_04_20_zphase.json b/cirq-google/cirq_google/devices/calibrations/weber_2021_04_20_zphase.json new file mode 100644 index 00000000000..0ee06132dbc --- /dev/null +++ b/cirq-google/cirq_google/devices/calibrations/weber_2021_04_20_zphase.json @@ -0,0 +1,848 @@ +{ + "sqrt_iswap": { + "zeta": [ + [ + "0_5", + "0_6", + 0.08433343370490282 + ], + [ + "0_5", + "1_5", + 0.26219779676857413 + ], + [ + "0_6", + "1_6", + -0.08343563160186226 + ], + [ + "1_4", + "1_5", + 0.01985327749972433 + ], + [ + "1_4", + "2_4", + -0.01990242868355783 + ], + [ + "1_5", + "1_6", + -0.0679680505770883 + ], + [ + "1_5", + "2_5", + -0.01050370040722336 + ], + [ + "1_6", + "1_7", + -0.04641671444190454 + ], + [ + "1_6", + "2_6", + 0.03138050452644609 + ], + [ + "1_7", + "2_7", + -0.1289241052613712 + ], + [ + "2_4", + "2_5", + 0.10029767570479856 + ], + [ + "2_4", + "3_4", + 0.04361659199680895 + ], + [ + "2_5", + "2_6", + 0.07564319881687485 + ], + [ + "2_5", + "3_5", + 0.1375919801895752 + ], + [ + "2_6", + "2_7", + -0.062414041933036346 + ], + [ + "2_6", + "3_6", + -0.0876570275111541 + ], + [ + "2_7", + "2_8", + -0.03673341564414313 + ], + [ + "2_7", + "3_7", + 0.054369870041308326 + ], + [ + "2_8", + "3_8", + -0.042855793917779966 + ], + [ + "3_2", + "3_3", + -0.014380502997044926 + ], + [ + "3_2", + "4_2", + -0.10303422893651185 + ], + [ + "3_3", + "3_4", + -0.06337347648213867 + ], + [ + "3_3", + "4_3", + 0.003234900947648892 + ], + [ + "3_4", + "3_5", + -0.044945126276104336 + ], + [ + "3_4", + "4_4", + -0.03738142412305203 + ], + [ + "3_5", + "3_6", + 0.015149924398569367 + ], + [ + "3_5", + "4_5", + -0.0012758235314863954 + ], + [ + "3_6", + "3_7", + -0.0038558889972967487 + ], + [ + "3_6", + "4_6", + 0.021971923982998014 + ], + [ + "3_7", + "3_8", + 0.005123141622789048 + ], + [ + "3_7", + "4_7", + 0.016700410481024858 + ], + [ + "3_8", + "3_9", + 0.049577777491990424 + ], + [ + "3_8", + "4_8", + -0.022331388440861376 + ], + [ + "3_9", + "4_9", + -0.06632455592852157 + ], + [ + "4_1", + "4_2", + 0.13359467851229181 + ], + [ + "4_1", + "5_1", + 0.008052935838213246 + ], + [ + "4_2", + "4_3", + -0.009328180587463996 + ], + [ + "4_2", + "5_2", + 0.021019492605705372 + ], + [ + "4_3", + "4_4", + -0.006803665246150787 + ], + [ + "4_3", + "5_3", + 0.0786709425261065 + ], + [ + "4_4", + "4_5", + 0.000989565997348966 + ], + [ + "4_4", + "5_4", + 0.03715495620034204 + ], + [ + "4_5", + "4_6", + -0.02447535226580704 + ], + [ + "4_5", + "5_5", + 0.04209882257151246 + ], + [ + "4_6", + "4_7", + 0.006961595220805071 + ], + [ + "4_6", + "5_6", + 0.12220506151842774 + ], + [ + "4_7", + "4_8", + 0.014766460821150448 + ], + [ + "4_7", + "5_7", + -0.0047840385933552 + ], + [ + "4_8", + "4_9", + 0.07906675938862737 + ], + [ + "4_8", + "5_8", + 0.1159233115596183 + ], + [ + "5_0", + "5_1", + 0.007677926241162274 + ], + [ + "5_1", + "5_2", + 0.023867851960675018 + ], + [ + "5_2", + "5_3", + 0.01982624439726057 + ], + [ + "5_2", + "6_2", + -0.10262746121413324 + ], + [ + "5_3", + "5_4", + -0.007775853925612591 + ], + [ + "5_3", + "6_3", + -0.023722878337731294 + ], + [ + "5_4", + "5_5", + 0.08503068633489208 + ], + [ + "5_4", + "6_4", + 0.024704785537003518 + ], + [ + "5_5", + "5_6", + -0.007339901571041447 + ], + [ + "5_5", + "6_5", + -0.15045334166686322 + ], + [ + "5_6", + "5_7", + -0.07928465408656918 + ], + [ + "5_6", + "6_6", + 0.005496241030779114 + ], + [ + "5_7", + "5_8", + 0.2113696679793105 + ], + [ + "5_7", + "6_7", + 0.16202712863786728 + ], + [ + "6_2", + "6_3", + -0.028892683360100476 + ], + [ + "6_2", + "7_2", + -0.010954035751867205 + ], + [ + "6_3", + "6_4", + -0.11831623614877672 + ], + [ + "6_3", + "7_3", + -0.014518328336043263 + ], + [ + "6_4", + "6_5", + -0.02108222964103739 + ], + [ + "6_4", + "7_4", + 0.004370651418059876 + ], + [ + "6_5", + "6_6", + 0.12139695123974006 + ], + [ + "6_5", + "7_5", + 0.019890686426064223 + ], + [ + "6_6", + "6_7", + 0.03242355245308827 + ], + [ + "6_6", + "7_6", + -0.001551244511476852 + ], + [ + "7_2", + "7_3", + 0.05386768035348279 + ], + [ + "7_3", + "7_4", + -0.08436698475423862 + ], + [ + "7_3", + "8_3", + 0.002919222614240201 + ], + [ + "7_4", + "7_5", + -0.038325113670601645 + ], + [ + "7_4", + "8_4", + 0.011006792569962228 + ], + [ + "7_5", + "7_6", + 0.08224597932807715 + ], + [ + "7_5", + "8_5", + -0.020145079930502713 + ], + [ + "8_3", + "8_4", + 0.12300652968849306 + ], + [ + "8_4", + "8_5", + -0.022541784618057788 + ], + [ + "8_4", + "9_4", + -0.059291317402739796 + ] + ], + "gamma": [ + [ + "0_5", + "0_6", + -0.17807141590661324 + ], + [ + "0_5", + "1_5", + -0.021307775233726733 + ], + [ + "0_6", + "1_6", + 0.019390633888576758 + ], + [ + "1_4", + "1_5", + -0.003202536575683368 + ], + [ + "1_4", + "2_4", + -0.04604014366231057 + ], + [ + "1_5", + "1_6", + -0.02458880937557817 + ], + [ + "1_5", + "2_5", + 0.01958017655613853 + ], + [ + "1_6", + "1_7", + -0.017583470237031662 + ], + [ + "1_6", + "2_6", + 0.017137743255513538 + ], + [ + "1_7", + "2_7", + 0.04699052966963535 + ], + [ + "2_4", + "2_5", + -0.02931435657777426 + ], + [ + "2_4", + "3_4", + -0.046815413951724505 + ], + [ + "2_5", + "2_6", + -0.012486348304117545 + ], + [ + "2_5", + "3_5", + -0.19850992841728932 + ], + [ + "2_6", + "2_7", + 0.03626426026817331 + ], + [ + "2_6", + "3_6", + 0.005465459088858982 + ], + [ + "2_7", + "2_8", + -0.003041928724622167 + ], + [ + "2_7", + "3_7", + 0.0014761619780996327 + ], + [ + "2_8", + "3_8", + -0.03913088656166197 + ], + [ + "3_2", + "3_3", + 0.02470965867155428 + ], + [ + "3_2", + "4_2", + -0.0032040209641905903 + ], + [ + "3_3", + "3_4", + -0.03491092589676459 + ], + [ + "3_3", + "4_3", + 0.02100788402267373 + ], + [ + "3_4", + "3_5", + -0.006620872313225501 + ], + [ + "3_4", + "4_4", + -0.08663589520835258 + ], + [ + "3_5", + "3_6", + -0.015423306426107342 + ], + [ + "3_5", + "4_5", + -0.06292991587873553 + ], + [ + "3_6", + "3_7", + -0.07526321856259122 + ], + [ + "3_6", + "4_6", + -0.09981950462532918 + ], + [ + "3_7", + "3_8", + -0.08276223396249582 + ], + [ + "3_7", + "4_7", + -0.07648379349833467 + ], + [ + "3_8", + "3_9", + -0.12145416738297188 + ], + [ + "3_8", + "4_8", + -0.08013422003546244 + ], + [ + "3_9", + "4_9", + 0.04885074531962097 + ], + [ + "4_1", + "4_2", + -0.05611128805222787 + ], + [ + "4_1", + "5_1", + -0.14535836479833053 + ], + [ + "4_2", + "4_3", + 0.008926734242991952 + ], + [ + "4_2", + "5_2", + 0.1202419961374468 + ], + [ + "4_3", + "4_4", + -0.05736325478879589 + ], + [ + "4_3", + "5_3", + 0.1415519374309553 + ], + [ + "4_4", + "4_5", + -0.1516524423540484 + ], + [ + "4_4", + "5_4", + -0.054914045474009576 + ], + [ + "4_5", + "4_6", + -0.09415454682188473 + ], + [ + "4_5", + "5_5", + -0.03750604467876428 + ], + [ + "4_6", + "4_7", + -0.09402798038671145 + ], + [ + "4_6", + "5_6", + 0.012338940694767153 + ], + [ + "4_7", + "4_8", + -0.11676360165899169 + ], + [ + "4_7", + "5_7", + -0.18476797113334342 + ], + [ + "4_8", + "4_9", + -0.08262822295636463 + ], + [ + "4_8", + "5_8", + -0.14283997075430932 + ], + [ + "5_0", + "5_1", + -0.09393049715178137 + ], + [ + "5_1", + "5_2", + 0.06347733103992725 + ], + [ + "5_2", + "5_3", + 0.03408764800963526 + ], + [ + "5_2", + "6_2", + -0.02557013485995485 + ], + [ + "5_3", + "5_4", + -0.011414077811935375 + ], + [ + "5_3", + "6_3", + 0.01840183013340191 + ], + [ + "5_4", + "5_5", + -0.030268713695438265 + ], + [ + "5_4", + "6_4", + -0.12392996561052527 + ], + [ + "5_5", + "5_6", + 0.05181455777821453 + ], + [ + "5_5", + "6_5", + -0.10190319716454033 + ], + [ + "5_6", + "5_7", + 0.0046112008747694055 + ], + [ + "5_6", + "6_6", + 0.1205812723352997 + ], + [ + "5_7", + "5_8", + -0.16230534570807276 + ], + [ + "5_7", + "6_7", + -0.07442211568159918 + ], + [ + "6_2", + "6_3", + 0.028396788675008278 + ], + [ + "6_2", + "7_2", + 0.06438039617788816 + ], + [ + "6_3", + "6_4", + -0.015869486171794733 + ], + [ + "6_3", + "7_3", + 0.045204226607766795 + ], + [ + "6_4", + "6_5", + -0.1753716253143187 + ], + [ + "6_4", + "7_4", + -0.12691260453297915 + ], + [ + "6_5", + "6_6", + -0.09019876894453782 + ], + [ + "6_5", + "7_5", + -0.05100592318284214 + ], + [ + "6_6", + "6_7", + 0.05269409538389702 + ], + [ + "6_6", + "7_6", + -0.08580339030950013 + ], + [ + "7_2", + "7_3", + -0.03705380709404782 + ], + [ + "7_3", + "7_4", + -0.07555247789555208 + ], + [ + "7_3", + "8_3", + -0.12600462950791824 + ], + [ + "7_4", + "7_5", + -0.15696134744856938 + ], + [ + "7_4", + "8_4", + -0.0446470536119179 + ], + [ + "7_5", + "7_6", + 0.0039205257321586195 + ], + [ + "7_5", + "8_5", + -0.06650716771715715 + ], + [ + "8_3", + "8_4", + -0.14058357608847594 + ], + [ + "8_4", + "8_5", + -0.04813152524340891 + ], + [ + "8_4", + "9_4", + -0.01648643384330928 + ] + ] + } +} \ No newline at end of file diff --git a/cirq-google/cirq_google/engine/__init__.py b/cirq-google/cirq_google/engine/__init__.py index 4f580109773..8925137dc0d 100644 --- a/cirq-google/cirq_google/engine/__init__.py +++ b/cirq-google/cirq_google/engine/__init__.py @@ -78,6 +78,7 @@ create_noiseless_virtual_engine_from_templates, create_noiseless_virtual_engine_from_latest_templates, load_median_device_calibration, + load_sample_device_zphase, ) from cirq_google.engine.engine_result import EngineResult diff --git a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py index 6d102e3b7b7..31c1f88d3ff 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py @@ -25,7 +25,7 @@ # 'result' contains the simulation results """ -from typing import Dict, Tuple, Type, TYPE_CHECKING +from typing import Dict, Optional, Tuple, Type, TYPE_CHECKING import numpy as np from cirq import ops @@ -33,11 +33,35 @@ from cirq_google import engine from cirq_google import ops as cg_ops from cirq_google.devices import google_noise_properties +from cirq_google.engine import util if TYPE_CHECKING: import cirq +# TODO: acquire this based on the target device. +# Default map of gates to their durations. +DEFAULT_GATE_NS: Dict[Type['cirq.Gate'], float] = { + ops.ZPowGate: 25.0, + ops.MeasurementGate: 4000.0, + ops.ResetChannel: 250.0, + ops.PhasedXZGate: 25.0, + ops.FSimGate: 32.0, + ops.ISwapPowGate: 32.0, + ops.CZPowGate: 32.0, + cg_ops.SycamoreGate: 12.0, + # ops.WaitGate is a special case. +} +GATE_PREFIX_PAIRS: Dict[Type['cirq.Gate'], str] = { + cg_ops.SycamoreGate: 'two_qubit_parallel_sycamore_gate', + ops.ISwapPowGate: 'two_qubit_parallel_sqrt_iswap_gate', +} +GATE_ZPHASE_CODE_PAIRS: Dict[Type['cirq.Gate'], str] = { + cg_ops.SycamoreGate: 'syc', + ops.ISwapPowGate: 'sqrt_iswap', +} + + def _unpack_1q_from_calibration( metric_name: str, calibration: engine.Calibration ) -> Dict['cirq.Qid', float]: @@ -64,6 +88,8 @@ def _unpack_2q_from_calibration( def noise_properties_from_calibration( calibration: engine.Calibration, + zphase_data: Optional[util.ZPhaseDataType] = None, + gate_times_ns: Optional[Dict[Type['cirq.Gate'], float]] = None, ) -> google_noise_properties.GoogleNoiseProperties: """Translates between `cirq_google.Calibration` and NoiseProperties. @@ -80,25 +106,18 @@ def noise_properties_from_calibration( Args: calibration: a Calibration object with hardware metrics. + zphase_data: Optional data for Z phases not captured by Calibration - + specifically, zeta and gamma. These values require Floquet + calibration and can be provided here if available. + gate_times_ns: Map of gate durations in nanoseconds. If not provided, + defaults to the Sycamore gate times listed in `known_devices.py`. Returns: A `cirq_google.GoogleNoiseProperties` which represents the error present in the given Calibration object. """ - - # TODO: acquire this based on the target device. - # Default map of gates to their durations. - default_gate_ns: Dict[Type['cirq.Gate'], float] = { - ops.ZPowGate: 25.0, - ops.MeasurementGate: 4000.0, - ops.ResetChannel: 250.0, - ops.PhasedXZGate: 25.0, - ops.FSimGate: 32.0, - ops.ISwapPowGate: 32.0, - ops.CZPowGate: 32.0, - cg_ops.SycamoreGate: 12.0, - # ops.WaitGate is a special case. - } + if gate_times_ns is None: + gate_times_ns = DEFAULT_GATE_NS # Unpack all values from Calibration object # 1. Extract T1 for all qubits @@ -111,7 +130,7 @@ def noise_properties_from_calibration( ) tphi_ns = {} if rb_incoherent_errors: - microwave_time_ns = default_gate_ns[ops.PhasedXZGate] + microwave_time_ns = gate_times_ns[ops.PhasedXZGate] for qubit, q_t1_ns in t1_ns.items(): tphi_err = rb_incoherent_errors[qubit] - microwave_time_ns / (3 * q_t1_ns) q_tphi_ns = 1e10 if tphi_err <= 0 else microwave_time_ns / (3 * tphi_err) @@ -128,11 +147,7 @@ def noise_properties_from_calibration( } # 3b. Extract Pauli error for two-qubit gates. - gate_prefix_pairs: Dict[Type['cirq.Gate'], str] = { - cg_ops.SycamoreGate: 'two_qubit_parallel_sycamore_gate', - ops.ISwapPowGate: 'two_qubit_parallel_sqrt_iswap_gate', - } - for gate, prefix in gate_prefix_pairs.items(): + for gate, prefix in GATE_PREFIX_PAIRS.items(): pauli_error = _unpack_2q_from_calibration( prefix + '_xeb_pauli_error_per_cycle', calibration ) @@ -156,25 +171,40 @@ def noise_properties_from_calibration( # 5. Extract entangling angle errors. fsim_errors = {} - for gate, prefix in gate_prefix_pairs.items(): + for gate, prefix in GATE_PREFIX_PAIRS.items(): theta_errors = _unpack_2q_from_calibration( prefix + '_xeb_entangler_theta_error_per_cycle', calibration ) phi_errors = _unpack_2q_from_calibration( prefix + '_xeb_entangler_phi_error_per_cycle', calibration ) - angle_keys = set(theta_errors.keys()) | set(phi_errors.keys()) + gate_str = GATE_ZPHASE_CODE_PAIRS[gate] + if zphase_data and gate_str in zphase_data: + zeta_errors = zphase_data[gate_str]["zeta"] + gamma_errors = zphase_data[gate_str]["gamma"] + else: + zeta_errors = {} + gamma_errors = {} + angle_keys = { + *theta_errors.keys(), + *phi_errors.keys(), + *zeta_errors.keys(), + *gamma_errors.keys(), + } for qubits in angle_keys: theta = theta_errors.get(qubits, 0) phi = phi_errors.get(qubits, 0) + zeta = zeta_errors.get(qubits, 0) + gamma = gamma_errors.get(qubits, 0) op_id = noise_utils.OpIdentifier(gate, *qubits) - fsim_errors[op_id] = ops.PhasedFSimGate(theta=theta, phi=phi) + error_gate = ops.PhasedFSimGate(theta=theta, phi=phi, zeta=zeta, gamma=gamma) + fsim_errors[op_id] = error_gate op_id_reverse = noise_utils.OpIdentifier(gate, *qubits[::-1]) - fsim_errors[op_id_reverse] = ops.PhasedFSimGate(theta=theta, phi=phi) + fsim_errors[op_id_reverse] = error_gate # Known false positive: https://github.com/PyCQA/pylint/issues/5857 return google_noise_properties.GoogleNoiseProperties( # pylint: disable=unexpected-keyword-arg - gate_times_ns=default_gate_ns, + gate_times_ns=gate_times_ns, t1_ns=t1_ns, tphi_ns=tphi_ns, readout_errors=readout_errors, diff --git a/cirq-google/cirq_google/engine/calibration_to_noise_properties_test.py b/cirq-google/cirq_google/engine/calibration_to_noise_properties_test.py index 1861b67ac29..3d7eb1ed73d 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties_test.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties_test.py @@ -20,24 +20,17 @@ import pytest -def test_noise_properties_from_calibration(): - qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)] - pauli_error = [0.001, 0.002, 0.003] - incoherent_error = [0.0001, 0.0002, 0.0003] - p00_error = [0.004, 0.005, 0.006] - p11_error = [0.007, 0.008, 0.009] - t1_micros = [10, 20, 30] - syc_pauli = [0.01, 0.02] - iswap_pauli = [0.03, 0.04] - syc_angles = [ - cirq.PhasedFSimGate(theta=0.011, phi=-0.021), - cirq.PhasedFSimGate(theta=-0.012, phi=0.022), - ] - iswap_angles = [ - cirq.PhasedFSimGate(theta=-0.013, phi=0.023), - cirq.PhasedFSimGate(theta=0.014, phi=-0.024), - ] - +def get_mock_calibration( + pauli_error, + incoherent_error, + p00_error, + p11_error, + t1_micros, + syc_pauli, + iswap_pauli, + syc_angles, + iswap_angles, +) -> cirq_google.Calibration: _CALIBRATION_DATA = Merge( f""" timestamp_ms: 1579214873, @@ -208,8 +201,39 @@ def test_noise_properties_from_calibration(): cirq_google.api.v2.metrics_pb2.MetricsSnapshot(), ) + return cirq_google.Calibration(_CALIBRATION_DATA) + + +def test_noise_properties_from_calibration(): + qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)] + pauli_error = [0.001, 0.002, 0.003] + incoherent_error = [0.0001, 0.0002, 0.0003] + p00_error = [0.004, 0.005, 0.006] + p11_error = [0.007, 0.008, 0.009] + t1_micros = [10, 20, 30] + syc_pauli = [0.01, 0.02] + iswap_pauli = [0.03, 0.04] + syc_angles = [ + cirq.PhasedFSimGate(theta=0.011, phi=-0.021), + cirq.PhasedFSimGate(theta=-0.012, phi=0.022), + ] + iswap_angles = [ + cirq.PhasedFSimGate(theta=-0.013, phi=0.023), + cirq.PhasedFSimGate(theta=0.014, phi=-0.024), + ] + # Create NoiseProperties object from Calibration - calibration = cirq_google.Calibration(_CALIBRATION_DATA) + calibration = get_mock_calibration( + pauli_error, + incoherent_error, + p00_error, + p11_error, + t1_micros, + syc_pauli, + iswap_pauli, + syc_angles, + iswap_angles, + ) prop = cirq_google.noise_properties_from_calibration(calibration) for i, q in enumerate(qubits): @@ -247,6 +271,61 @@ def test_noise_properties_from_calibration(): assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i] +def test_zphase_data(): + qubits = [cirq.GridQubit(0, 0), cirq.GridQubit(0, 1), cirq.GridQubit(1, 0)] + pauli_error = [0.001, 0.002, 0.003] + incoherent_error = [0.0001, 0.0002, 0.0003] + p00_error = [0.004, 0.005, 0.006] + p11_error = [0.007, 0.008, 0.009] + t1_micros = [10, 20, 30] + syc_pauli = [0.01, 0.02] + iswap_pauli = [0.03, 0.04] + syc_angles = [ + cirq.PhasedFSimGate(theta=0.011, phi=-0.021, zeta=-0.031, gamma=0.043), + cirq.PhasedFSimGate(theta=-0.012, phi=0.022, zeta=0.032, gamma=-0.044), + ] + iswap_angles = [ + cirq.PhasedFSimGate(theta=-0.013, phi=0.023, zeta=0.031, gamma=-0.043), + cirq.PhasedFSimGate(theta=0.014, phi=-0.024, zeta=-0.032, gamma=0.044), + ] + + # Create NoiseProperties object from Calibration + calibration = get_mock_calibration( + pauli_error, + incoherent_error, + p00_error, + p11_error, + t1_micros, + syc_pauli, + iswap_pauli, + syc_angles, + iswap_angles, + ) + + qubit_pairs = [(qubits[0], qubits[1]), (qubits[0], qubits[2])] + zphase_data = { + "syc": { + "zeta": {qubit_pairs[0]: syc_angles[0].zeta, qubit_pairs[1]: syc_angles[1].zeta}, + "gamma": {qubit_pairs[0]: syc_angles[0].gamma, qubit_pairs[1]: syc_angles[1].gamma}, + }, + "sqrt_iswap": { + "zeta": {qubit_pairs[0]: iswap_angles[0].zeta, qubit_pairs[1]: iswap_angles[1].zeta}, + "gamma": {qubit_pairs[0]: iswap_angles[0].gamma, qubit_pairs[1]: iswap_angles[1].gamma}, + }, + } + + prop = cirq_google.noise_properties_from_calibration(calibration, zphase_data) + for i, qs in enumerate(qubit_pairs): + for gate, values in [ + (cirq_google.SycamoreGate, syc_angles), + (cirq.ISwapPowGate, iswap_angles), + ]: + assert prop.fsim_errors[OpIdentifier(gate, *qs)] == values[i] + assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i] + assert prop.fsim_errors[OpIdentifier(gate, *qs)] == values[i] + assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i] + + def test_incomplete_calibration(): pauli_error = [0.001, 0.002, 0.003] p00_error = [0.004, 0.005, 0.006] diff --git a/cirq-google/cirq_google/engine/util.py b/cirq-google/cirq_google/engine/util.py index 4a381b87fb7..14d95660f84 100644 --- a/cirq-google/cirq_google/engine/util.py +++ b/cirq-google/cirq_google/engine/util.py @@ -13,7 +13,7 @@ # limitations under the License. import inspect -from typing import TypeVar +from typing import Dict, Tuple, TypeVar from google.protobuf import any_pb2 from google.protobuf.message import Message @@ -22,6 +22,14 @@ M = TypeVar('M', bound=Message) +# Bundled Z phase errors in the format: +# +# {gate_type: {angle_type: {qubit_pair: error}}} +# +# where gate_type is "syc" or "sqrt_iswap", angle_type is "zeta" or "gamma", +# and "qubit_pair" is a tuple of qubits. +ZPhaseDataType = Dict[str, Dict[str, Dict[Tuple[cirq.Qid, ...], float]]] + def pack_any(message: Message) -> any_pb2.Any: """Packs a message into an Any proto. diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index 7e3a33a917e..b0af27789d5 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -13,6 +13,7 @@ # limitations under the License. """Functions to instantiate SimulatedLocalEngines to simulate various Google Devices.""" +import json from typing import cast, Iterable, List, Optional, Union import pathlib import time @@ -20,7 +21,7 @@ import google.protobuf.text_format as text_format import cirq from cirq_google.api import v2 -from cirq_google.engine import calibration, engine_validator, simulated_local_processor +from cirq_google.engine import calibration, engine_validator, simulated_local_processor, util from cirq_google.devices import serializable_device from cirq_google.serialization.gate_sets import FSIM_GATESET from cirq_google.serialization import serializable_gate_set @@ -42,6 +43,8 @@ 'weber': 1635923188204, # 2021-11-03 07:06:28.204 UTC } +ZPHASE_DATA = {'rainbow': 'rainbow_2021_08_26_zphase.json', 'weber': 'weber_2021_04_20_zphase.json'} + METRICS_1Q = [ 'single_qubit_p00_error', 'single_qubit_p11_error', @@ -123,6 +126,42 @@ def load_median_device_calibration(processor_id: str) -> calibration.Calibration return cal +def load_sample_device_zphase(processor_id: str) -> util.ZPhaseDataType: + """Loads sample Z phase errors for the given device. + + Args: + processor_id: name of the processor to simulate. + + Returns: + Z phases in the form {gate_type: {angle_type: {qubit_pair: error}}}, + where gate_type is "syc" or "sqrt_iswap", angle_type is "zeta" or + "gamma", and "qubit_pair" is a tuple of qubits. + + Raises: + ValueError: if processor_id is not a supported QCS processor. + """ + zphase_name = ZPHASE_DATA.get(processor_id, None) + if zphase_name is None: + raise ValueError( + f"Got processor_id={processor_id}, but no Z phase data is defined for that processor." + ) + path = pathlib.Path(__file__).parent.parent.resolve() + with path.joinpath('devices', 'calibrations', zphase_name).open() as f: + raw_data = json.load(f) + + nested_data: util.ZPhaseDataType = { + gate_type: { + angle: { + (v2.qubit_from_proto_id(q0), v2.qubit_from_proto_id(q1)): vals + for q0, q1, vals in triples + } + for angle, triples in angles.items() + } + for gate_type, angles in raw_data.items() + } + return nested_data + + def _create_virtual_processor_from_device( processor_id: str, device: cirq.Device ) -> simulated_local_processor.SimulatedLocalProcessor: diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory_test.py b/cirq-google/cirq_google/engine/virtual_engine_factory_test.py index cdc09da2b13..73843d80777 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory_test.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory_test.py @@ -101,6 +101,24 @@ def test_median_device_bad_processor(): _ = factory.load_median_device_calibration('bad_processor') +@pytest.mark.parametrize('processor_id', ['rainbow', 'weber']) +def test_sample_device_zphase(processor_id): + zphase_data = factory.load_sample_device_zphase(processor_id) + assert 'sqrt_iswap' in zphase_data + sqrt_iswap_data = zphase_data['sqrt_iswap'] + for angle in ['zeta', 'gamma']: + assert angle in sqrt_iswap_data + for (q0, q1), val in sqrt_iswap_data[angle].items(): + assert isinstance(q0, cirq.Qid) + assert isinstance(q1, cirq.Qid) + assert isinstance(val, float) + + +def test_device_zphase_bad_processor(): + with pytest.raises(ValueError, match='no Z phase data is defined'): + _ = factory.load_sample_device_zphase('bad_processor') + + def test_create_from_proto(): # Create a minimal gate specification that can handle the test.