From e065334a1548da34619e2635219b7130a2457d4b Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Wed, 18 May 2022 15:16:38 -0700 Subject: [PATCH 1/8] Add zphase, step one --- .../devices/calibrations/rainbow_zphase.json | 326 +++++++ .../devices/calibrations/weber_zphase.json | 846 ++++++++++++++++++ cirq-google/cirq_google/engine/__init__.py | 1 + .../engine/calibration_to_noise_properties.py | 23 +- .../calibration_to_noise_properties_test.py | 5 + .../engine/virtual_engine_factory.py | 40 +- .../engine/virtual_engine_factory_test.py | 5 + 7 files changed, 1242 insertions(+), 4 deletions(-) create mode 100644 cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json create mode 100644 cirq-google/cirq_google/devices/calibrations/weber_zphase.json diff --git a/cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json b/cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json new file mode 100644 index 00000000000..713fab4f8b3 --- /dev/null +++ b/cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json @@ -0,0 +1,326 @@ +{ + "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_zphase.json b/cirq-google/cirq_google/devices/calibrations/weber_zphase.json new file mode 100644 index 00000000000..9eed469a7b9 --- /dev/null +++ b/cirq-google/cirq_google/devices/calibrations/weber_zphase.json @@ -0,0 +1,846 @@ +{ + "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 0bbcbdde75a..ba66e65abdf 100644 --- a/cirq-google/cirq_google/engine/__init__.py +++ b/cirq-google/cirq_google/engine/__init__.py @@ -77,6 +77,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..aaed6c244eb 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 @@ -37,6 +37,8 @@ if TYPE_CHECKING: import cirq +_ZPhaseData = Dict[str, Dict[Tuple[ops.Qid, ops.Qid], float]] + def _unpack_1q_from_calibration( metric_name: str, calibration: engine.Calibration @@ -64,6 +66,7 @@ def _unpack_2q_from_calibration( def noise_properties_from_calibration( calibration: engine.Calibration, + zphase_data: Optional[_ZPhaseData], ) -> google_noise_properties.GoogleNoiseProperties: """Translates between `cirq_google.Calibration` and NoiseProperties. @@ -80,6 +83,9 @@ 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. Returns: A `cirq_google.GoogleNoiseProperties` which represents the error @@ -163,14 +169,25 @@ def noise_properties_from_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()) + zeta_errors = zphase_data["zeta"] if zphase_data else {} + gamma_errors = zphase_data["gamma"] if zphase_data else {} + angle_keys = ( + set(theta_errors.keys()) | + set(phi_errors.keys()) | + set(zeta_errors.keys()) | + set(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) 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] = ops.PhasedFSimGate( + theta=theta, phi=phi, zeta=zeta, gamma=gamma, + ) # Known false positive: https://github.com/PyCQA/pylint/issues/5857 return google_noise_properties.GoogleNoiseProperties( # pylint: disable=unexpected-keyword-arg 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..bf98921df77 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 @@ -247,6 +247,11 @@ def test_noise_properties_from_calibration(): assert prop.fsim_errors[OpIdentifier(gate, *qs[::-1])] == values[i] +def test_zphase_data(): + # TODO: test injection of Z phase data. + assert False + + 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/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index 7e3a33a917e..e04f30ee002 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -13,7 +13,8 @@ # limitations under the License. """Functions to instantiate SimulatedLocalEngines to simulate various Google Devices.""" -from typing import cast, Iterable, List, Optional, Union +import json +from typing import Dict, Tuple, cast, Iterable, List, Optional, Union import pathlib import time @@ -42,6 +43,11 @@ 'weber': 1635923188204, # 2021-11-03 07:06:28.204 UTC } +ZPHASE_DATA = { + 'rainbow': 'rainbow_zphase.json', + 'weber': 'weber_zphase.json', +} + METRICS_1Q = [ 'single_qubit_p00_error', 'single_qubit_p11_error', @@ -123,6 +129,38 @@ def load_median_device_calibration(processor_id: str) -> calibration.Calibration return cal +def load_sample_device_zphase( + processor_id: str, +) -> Dict[str, Dict[Tuple[cirq.Qid, cirq.Qid], float]]: + """Loads sample Z phase errors for the given device. + + Output is of the form {angle_type: {qubit_pair: error}}, where angle_type + is "zeta" or "gamma" and "qubit_pair" is a tuple of qubits. + + Args: + processor_id: name of the processor to simulate. + + 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) + def to_grid_qid(qstr: str): + row, col = map(int, qstr.split("_")) + return cirq.GridQubit(row, col) + nested_data = { + k: {(to_grid_qid(q0), to_grid_qid(q1)): vals for q0, q1, vals in triples} + for k, triples 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..0b7acdfe9ab 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,11 @@ def test_median_device_bad_processor(): _ = factory.load_median_device_calibration('bad_processor') +def test_sample_device_zphase(): + # Test extraction of zphase data. + assert False + + def test_create_from_proto(): # Create a minimal gate specification that can handle the test. From 6a08ac158df6922f90a60a7bcff871f3b4493c72 Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Thu, 19 May 2022 10:50:53 -0700 Subject: [PATCH 2/8] Split gates and add tests --- .../devices/calibrations/rainbow_zphase.json | 648 +++---- .../devices/calibrations/weber_zphase.json | 1688 +++++++++-------- .../engine/calibration_to_noise_properties.py | 34 +- .../calibration_to_noise_properties_test.py | 132 +- .../engine/virtual_engine_factory.py | 7 +- .../engine/virtual_engine_factory_test.py | 14 +- 6 files changed, 1317 insertions(+), 1206 deletions(-) diff --git a/cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json b/cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json index 713fab4f8b3..51caa3862b8 100644 --- a/cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json +++ b/cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json @@ -1,326 +1,328 @@ { - "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 + "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_zphase.json b/cirq-google/cirq_google/devices/calibrations/weber_zphase.json index 9eed469a7b9..0ee06132dbc 100644 --- a/cirq-google/cirq_google/devices/calibrations/weber_zphase.json +++ b/cirq-google/cirq_google/devices/calibrations/weber_zphase.json @@ -1,846 +1,848 @@ { - "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 + "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/calibration_to_noise_properties.py b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py index aaed6c244eb..f9b6f1683ef 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py @@ -66,7 +66,7 @@ def _unpack_2q_from_calibration( def noise_properties_from_calibration( calibration: engine.Calibration, - zphase_data: Optional[_ZPhaseData], + zphase_data: Optional[_ZPhaseData] = None, ) -> google_noise_properties.GoogleNoiseProperties: """Translates between `cirq_google.Calibration` and NoiseProperties. @@ -162,6 +162,10 @@ def noise_properties_from_calibration( # 5. Extract entangling angle errors. fsim_errors = {} + gate_zphase_code_pairs: Dict[Type['cirq.Gate'], str] = { + cg_ops.SycamoreGate: 'syc', + ops.ISwapPowGate: 'sqrt_iswap', + } for gate, prefix in gate_prefix_pairs.items(): theta_errors = _unpack_2q_from_calibration( prefix + '_xeb_entangler_theta_error_per_cycle', calibration @@ -169,25 +173,31 @@ def noise_properties_from_calibration( phi_errors = _unpack_2q_from_calibration( prefix + '_xeb_entangler_phi_error_per_cycle', calibration ) - zeta_errors = zphase_data["zeta"] if zphase_data else {} - gamma_errors = zphase_data["gamma"] if zphase_data else {} - angle_keys = ( - set(theta_errors.keys()) | - set(phi_errors.keys()) | - set(zeta_errors.keys()) | - set(gamma_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) - op_id_reverse = noise_utils.OpIdentifier(gate, *qubits[::-1]) - fsim_errors[op_id_reverse] = ops.PhasedFSimGate( + 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] = error_gate # Known false positive: https://github.com/PyCQA/pylint/issues/5857 return google_noise_properties.GoogleNoiseProperties( # pylint: disable=unexpected-keyword-arg 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 bf98921df77..b1ecae66e16 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,26 +20,18 @@ 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), - ] - - _CALIBRATION_DATA = Merge( - f""" +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, metrics: [{{ name: 'single_qubit_rb_pauli_error_per_gate', @@ -208,8 +200,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): @@ -248,8 +271,71 @@ def test_noise_properties_from_calibration(): def test_zphase_data(): - # TODO: test injection of Z phase data. - assert False + 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(): diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index e04f30ee002..a043a4f9a2e 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -155,8 +155,11 @@ def to_grid_qid(qstr: str): row, col = map(int, qstr.split("_")) return cirq.GridQubit(row, col) nested_data = { - k: {(to_grid_qid(q0), to_grid_qid(q1)): vals for q0, q1, vals in triples} - for k, triples in raw_data.items() + gate_type: { + angle: {(to_grid_qid(q0), to_grid_qid(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 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 0b7acdfe9ab..500e9587084 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory_test.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory_test.py @@ -101,9 +101,17 @@ def test_median_device_bad_processor(): _ = factory.load_median_device_calibration('bad_processor') -def test_sample_device_zphase(): - # Test extraction of zphase data. - assert False +@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_create_from_proto(): From 51dc924e70f428815b7cbb61abbab16453324bd0 Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Thu, 19 May 2022 11:16:53 -0700 Subject: [PATCH 3/8] Fix checks and docs --- .../engine/calibration_to_noise_properties.py | 9 +++---- .../calibration_to_noise_properties_test.py | 26 +++++-------------- .../engine/virtual_engine_factory.py | 14 +++++----- .../engine/virtual_engine_factory_test.py | 5 ++++ 4 files changed, 22 insertions(+), 32 deletions(-) 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 f9b6f1683ef..62cb2f64ff4 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py @@ -37,7 +37,7 @@ if TYPE_CHECKING: import cirq -_ZPhaseData = Dict[str, Dict[Tuple[ops.Qid, ops.Qid], float]] +_ZPhaseData = Dict[str, Dict[str, Dict[Tuple[ops.Qid, ...], float]]] def _unpack_1q_from_calibration( @@ -65,8 +65,7 @@ def _unpack_2q_from_calibration( def noise_properties_from_calibration( - calibration: engine.Calibration, - zphase_data: Optional[_ZPhaseData] = None, + calibration: engine.Calibration, zphase_data: Optional[_ZPhaseData] = None ) -> google_noise_properties.GoogleNoiseProperties: """Translates between `cirq_google.Calibration` and NoiseProperties. @@ -192,9 +191,7 @@ def noise_properties_from_calibration( zeta = zeta_errors.get(qubits, 0) gamma = gamma_errors.get(qubits, 0) op_id = noise_utils.OpIdentifier(gate, *qubits) - error_gate = ops.PhasedFSimGate( - theta=theta, phi=phi, zeta=zeta, gamma=gamma, - ) + 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] = error_gate 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 b1ecae66e16..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 @@ -31,7 +31,8 @@ def get_mock_calibration( syc_angles, iswap_angles, ) -> cirq_google.Calibration: - _CALIBRATION_DATA = Merge(f""" + _CALIBRATION_DATA = Merge( + f""" timestamp_ms: 1579214873, metrics: [{{ name: 'single_qubit_rb_pauli_error_per_gate', @@ -304,25 +305,13 @@ def test_zphase_data(): 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, - }, + "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, - }, - } + "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) @@ -337,7 +326,6 @@ def test_zphase_data(): 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/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index a043a4f9a2e..ec4fed1ae47 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -43,10 +43,7 @@ 'weber': 1635923188204, # 2021-11-03 07:06:28.204 UTC } -ZPHASE_DATA = { - 'rainbow': 'rainbow_zphase.json', - 'weber': 'weber_zphase.json', -} +ZPHASE_DATA = {'rainbow': 'rainbow_zphase.json', 'weber': 'weber_zphase.json'} METRICS_1Q = [ 'single_qubit_p00_error', @@ -131,11 +128,12 @@ def load_median_device_calibration(processor_id: str) -> calibration.Calibration def load_sample_device_zphase( processor_id: str, -) -> Dict[str, Dict[Tuple[cirq.Qid, cirq.Qid], float]]: +) -> Dict[str, Dict[str, Dict[Tuple[cirq.Qid, ...], float]]]: """Loads sample Z phase errors for the given device. - Output is of the form {angle_type: {qubit_pair: error}}, where angle_type - is "zeta" or "gamma" and "qubit_pair" is a tuple of qubits. + Output is of 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. Args: processor_id: name of the processor to simulate. @@ -151,9 +149,11 @@ def load_sample_device_zphase( path = pathlib.Path(__file__).parent.parent.resolve() with path.joinpath('devices', 'calibrations', zphase_name).open() as f: raw_data = json.load(f) + def to_grid_qid(qstr: str): row, col = map(int, qstr.split("_")) return cirq.GridQubit(row, col) + nested_data = { gate_type: { angle: {(to_grid_qid(q0), to_grid_qid(q1)): vals for q0, q1, vals in triples} 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 500e9587084..73843d80777 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory_test.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory_test.py @@ -114,6 +114,11 @@ def test_sample_device_zphase(processor_id): 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. From a8ef30cd6ff2f73ba0ff77e746306db09d7069f6 Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Thu, 19 May 2022 11:34:29 -0700 Subject: [PATCH 4/8] mypy? --- cirq-google/cirq_google/engine/virtual_engine_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index ec4fed1ae47..79f3674f875 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -154,7 +154,7 @@ def to_grid_qid(qstr: str): row, col = map(int, qstr.split("_")) return cirq.GridQubit(row, col) - nested_data = { + nested_data: Dict[str, Dict[str, Dict[Tuple[cirq.Qid, ...], float]]] = { gate_type: { angle: {(to_grid_qid(q0), to_grid_qid(q1)): vals for q0, q1, vals in triples} for angle, triples in angles.items() From 7e3ea6c661c48f6c5797b080c84e8467f9ee3911 Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Wed, 25 May 2022 13:36:33 -0700 Subject: [PATCH 5/8] Address review comments --- ...se.json => rainbow_2021_08_26_zphase.json} | 0 ...hase.json => weber_2021_04_20_zphase.json} | 0 .../engine/calibration_to_noise_properties.py | 62 ++++++++++--------- cirq-google/cirq_google/engine/util.py | 10 ++- .../engine/virtual_engine_factory.py | 17 +++-- 5 files changed, 50 insertions(+), 39 deletions(-) rename cirq-google/cirq_google/devices/calibrations/{rainbow_zphase.json => rainbow_2021_08_26_zphase.json} (100%) rename cirq-google/cirq_google/devices/calibrations/{weber_zphase.json => weber_2021_04_20_zphase.json} (100%) diff --git a/cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json b/cirq-google/cirq_google/devices/calibrations/rainbow_2021_08_26_zphase.json similarity index 100% rename from cirq-google/cirq_google/devices/calibrations/rainbow_zphase.json rename to cirq-google/cirq_google/devices/calibrations/rainbow_2021_08_26_zphase.json diff --git a/cirq-google/cirq_google/devices/calibrations/weber_zphase.json b/cirq-google/cirq_google/devices/calibrations/weber_2021_04_20_zphase.json similarity index 100% rename from cirq-google/cirq_google/devices/calibrations/weber_zphase.json rename to cirq-google/cirq_google/devices/calibrations/weber_2021_04_20_zphase.json 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 62cb2f64ff4..f661f8771bf 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py @@ -33,11 +33,33 @@ 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 -_ZPhaseData = Dict[str, Dict[str, Dict[Tuple[ops.Qid, ...], float]]] + +# 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( @@ -65,7 +87,9 @@ def _unpack_2q_from_calibration( def noise_properties_from_calibration( - calibration: engine.Calibration, zphase_data: Optional[_ZPhaseData] = None + 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. @@ -90,20 +114,8 @@ def noise_properties_from_calibration( 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 @@ -116,7 +128,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) @@ -133,11 +145,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 ) @@ -161,18 +169,14 @@ def noise_properties_from_calibration( # 5. Extract entangling angle errors. fsim_errors = {} - gate_zphase_code_pairs: Dict[Type['cirq.Gate'], str] = { - cg_ops.SycamoreGate: 'syc', - ops.ISwapPowGate: 'sqrt_iswap', - } - 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 ) - gate_str = gate_zphase_code_pairs[gate] + 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"] @@ -198,7 +202,7 @@ def noise_properties_from_calibration( # 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/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 79f3674f875..74d6abaf2eb 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -21,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 @@ -43,7 +43,7 @@ 'weber': 1635923188204, # 2021-11-03 07:06:28.204 UTC } -ZPHASE_DATA = {'rainbow': 'rainbow_zphase.json', 'weber': 'weber_zphase.json'} +ZPHASE_DATA = {'rainbow': 'rainbow_2021_08_26_zphase.json', 'weber': 'weber_2021_04_20_zphase.json'} METRICS_1Q = [ 'single_qubit_p00_error', @@ -126,18 +126,17 @@ def load_median_device_calibration(processor_id: str) -> calibration.Calibration return cal -def load_sample_device_zphase( - processor_id: str, -) -> Dict[str, Dict[str, Dict[Tuple[cirq.Qid, ...], float]]]: +def load_sample_device_zphase(processor_id: str) -> util.ZPhaseDataType: """Loads sample Z phase errors for the given device. - Output is of 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. - 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. """ From 2e848a01ee48c09207c95cfa5e6e786b4c47e527 Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Wed, 25 May 2022 13:40:32 -0700 Subject: [PATCH 6/8] linter fix --- .../cirq_google/engine/calibration_to_noise_properties.py | 2 ++ 1 file changed, 2 insertions(+) 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 f661f8771bf..31c1f88d3ff 100644 --- a/cirq-google/cirq_google/engine/calibration_to_noise_properties.py +++ b/cirq-google/cirq_google/engine/calibration_to_noise_properties.py @@ -109,6 +109,8 @@ def noise_properties_from_calibration( 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 From 7c9244c0b7f7ab18edcf51fe57ee1e0221f760de Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Wed, 8 Jun 2022 08:26:07 -0700 Subject: [PATCH 7/8] use existing types and methods --- .../cirq_google/engine/virtual_engine_factory.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index 74d6abaf2eb..e51490f8f80 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -149,13 +149,12 @@ def load_sample_device_zphase(processor_id: str) -> util.ZPhaseDataType: with path.joinpath('devices', 'calibrations', zphase_name).open() as f: raw_data = json.load(f) - def to_grid_qid(qstr: str): - row, col = map(int, qstr.split("_")) - return cirq.GridQubit(row, col) - - nested_data: Dict[str, Dict[str, Dict[Tuple[cirq.Qid, ...], float]]] = { + nested_data: util.ZPhaseDataType = { gate_type: { - angle: {(to_grid_qid(q0), to_grid_qid(q1)): vals for q0, q1, vals in triples} + 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() From b6b0ab03cb4da3c68a679420cefa25ead4654c5e Mon Sep 17 00:00:00 2001 From: Orion Martin <40585662+95-martin-orion@users.noreply.github.com> Date: Wed, 8 Jun 2022 08:30:06 -0700 Subject: [PATCH 8/8] thanks pylint --- cirq-google/cirq_google/engine/virtual_engine_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cirq-google/cirq_google/engine/virtual_engine_factory.py b/cirq-google/cirq_google/engine/virtual_engine_factory.py index e51490f8f80..b0af27789d5 100644 --- a/cirq-google/cirq_google/engine/virtual_engine_factory.py +++ b/cirq-google/cirq_google/engine/virtual_engine_factory.py @@ -14,7 +14,7 @@ """Functions to instantiate SimulatedLocalEngines to simulate various Google Devices.""" import json -from typing import Dict, Tuple, cast, Iterable, List, Optional, Union +from typing import cast, Iterable, List, Optional, Union import pathlib import time