1# Copyright 2018 The Cirq Developers 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15from cirq import _import 16 17# A module can only depend on modules imported earlier in this list of modules 18# at import time. Pytest will fail otherwise (enforced by 19# dev_tools/import_test.py). 20# Begin dependency order list of sub-modules. 21from cirq import ( 22 # Low level 23 _version, 24 _compat, 25 _doc, 26 type_workarounds, 27) 28 29with _import.delay_import('cirq.protocols'): 30 from cirq import ( 31 # Core 32 protocols, 33 value, 34 linalg, 35 qis, 36 ops, 37 devices, 38 study, 39 ) 40from cirq import ( 41 # Core 42 circuits, 43 # Optimize and run 44 optimizers, 45 work, 46 sim, 47 vis, 48 # Hardware specific 49 ion, 50 neutral_atoms, 51 interop, 52 # Applications 53 experiments, 54 # Extra (nothing should depend on these) 55 testing, 56) 57 58# End dependency order list of sub-modules 59 60from cirq._version import ( 61 __version__, 62) 63 64# Flattened sub-modules. 65 66from cirq.circuits import ( 67 AbstractCircuit, 68 Alignment, 69 Circuit, 70 CircuitDag, 71 CircuitOperation, 72 FrozenCircuit, 73 InsertStrategy, 74 PointOptimizationSummary, 75 PointOptimizer, 76 QasmOutput, 77 QuilOutput, 78 TextDiagramDrawer, 79 Unique, 80) 81 82from cirq.devices import ( 83 ConstantQubitNoiseModel, 84 Device, 85 GridQid, 86 GridQubit, 87 LineQid, 88 LineQubit, 89 NO_NOISE, 90 NOISE_MODEL_LIKE, 91 NoiseModel, 92 SymmetricalQidPair, 93 UNCONSTRAINED_DEVICE, 94 NamedTopology, 95 draw_gridlike, 96 LineTopology, 97 TiltedSquareLattice, 98 get_placements, 99 draw_placements, 100) 101 102from cirq.experiments import ( 103 estimate_parallel_single_qubit_readout_errors, 104 estimate_single_qubit_readout_errors, 105 hog_score_xeb_fidelity_from_probabilities, 106 least_squares_xeb_fidelity_from_expectations, 107 least_squares_xeb_fidelity_from_probabilities, 108 linear_xeb_fidelity, 109 linear_xeb_fidelity_from_probabilities, 110 log_xeb_fidelity, 111 log_xeb_fidelity_from_probabilities, 112 generate_boixo_2018_supremacy_circuits_v2, 113 generate_boixo_2018_supremacy_circuits_v2_bristlecone, 114 generate_boixo_2018_supremacy_circuits_v2_grid, 115 xeb_fidelity, 116) 117 118from cirq.interop import ( 119 quirk_json_to_circuit, 120 quirk_url_to_circuit, 121) 122 123from cirq.linalg import ( 124 all_near_zero, 125 all_near_zero_mod, 126 allclose_up_to_global_phase, 127 apply_matrix_to_slices, 128 axis_angle, 129 AxisAngleDecomposition, 130 bidiagonalize_real_matrix_pair_with_symmetric_products, 131 bidiagonalize_unitary_with_special_orthogonals, 132 block_diag, 133 CONTROL_TAG, 134 deconstruct_single_qubit_matrix_into_angles, 135 diagonalize_real_symmetric_and_sorted_diagonal_matrices, 136 diagonalize_real_symmetric_matrix, 137 dot, 138 expand_matrix_in_orthogonal_basis, 139 hilbert_schmidt_inner_product, 140 is_cptp, 141 is_diagonal, 142 is_hermitian, 143 is_normal, 144 is_orthogonal, 145 is_special_orthogonal, 146 is_special_unitary, 147 is_unitary, 148 kak_canonicalize_vector, 149 kak_decomposition, 150 kak_vector, 151 KakDecomposition, 152 kron, 153 kron_bases, 154 kron_factor_4x4_to_2x2s, 155 kron_with_controls, 156 map_eigenvalues, 157 match_global_phase, 158 matrix_commutes, 159 matrix_from_basis_coefficients, 160 num_cnots_required, 161 partial_trace, 162 partial_trace_of_state_vector_as_mixture, 163 PAULI_BASIS, 164 scatter_plot_normalized_kak_interaction_coefficients, 165 pow_pauli_combination, 166 reflection_matrix_pow, 167 slice_for_qubits_equal_to, 168 so4_to_magic_su2s, 169 sub_state_vector, 170 targeted_conjugate_about, 171 targeted_left_multiply, 172 to_special, 173 unitary_eig, 174) 175 176from cirq.ops import ( 177 amplitude_damp, 178 AmplitudeDampingChannel, 179 AnyIntegerPowerGateFamily, 180 AnyUnitaryGateFamily, 181 ArithmeticOperation, 182 asymmetric_depolarize, 183 AsymmetricDepolarizingChannel, 184 BaseDensePauliString, 185 bit_flip, 186 BitFlipChannel, 187 BooleanHamiltonian, 188 CCX, 189 CCXPowGate, 190 CCZ, 191 CCZPowGate, 192 CCNOT, 193 CCNotPowGate, 194 CNOT, 195 CNotPowGate, 196 ControlledGate, 197 ControlledOperation, 198 cphase, 199 CSWAP, 200 CSwapGate, 201 CX, 202 CXPowGate, 203 CZ, 204 CZPowGate, 205 DensePauliString, 206 depolarize, 207 DepolarizingChannel, 208 DiagonalGate, 209 EigenGate, 210 flatten_op_tree, 211 flatten_to_ops, 212 flatten_to_ops_or_moments, 213 FREDKIN, 214 freeze_op_tree, 215 FSimGate, 216 Gate, 217 GateFamily, 218 GateOperation, 219 Gateset, 220 generalized_amplitude_damp, 221 GeneralizedAmplitudeDampingChannel, 222 givens, 223 GlobalPhaseOperation, 224 H, 225 HPowGate, 226 I, 227 identity_each, 228 IdentityGate, 229 InterchangeableQubitsGate, 230 ISWAP, 231 ISwapPowGate, 232 KrausChannel, 233 LinearCombinationOfGates, 234 LinearCombinationOfOperations, 235 MatrixGate, 236 MixedUnitaryChannel, 237 measure, 238 measure_each, 239 measure_paulistring_terms, 240 measure_single_paulistring, 241 MeasurementGate, 242 Moment, 243 MutableDensePauliString, 244 MutablePauliString, 245 NamedQubit, 246 NamedQid, 247 OP_TREE, 248 Operation, 249 ParallelGate, 250 ParallelGateFamily, 251 parallel_gate_op, 252 ParallelGateOperation, 253 Pauli, 254 PAULI_GATE_LIKE, 255 PAULI_STRING_LIKE, 256 PauliInteractionGate, 257 PauliMeasurementGate, 258 PauliString, 259 PauliStringGateOperation, 260 PauliStringPhasor, 261 PauliSum, 262 PauliSumExponential, 263 PauliSumLike, 264 PauliTransform, 265 phase_damp, 266 phase_flip, 267 PhaseDampingChannel, 268 PhaseGradientGate, 269 PhasedFSimGate, 270 PhasedISwapPowGate, 271 PhasedXPowGate, 272 PhasedXZGate, 273 PhaseFlipChannel, 274 StatePreparationChannel, 275 ProjectorString, 276 ProjectorSum, 277 RandomGateChannel, 278 qft, 279 Qid, 280 QuantumFourierTransformGate, 281 QubitOrder, 282 QubitOrderOrList, 283 QubitPermutationGate, 284 reset, 285 reset_each, 286 ResetChannel, 287 riswap, 288 Rx, 289 Ry, 290 Rz, 291 rx, 292 ry, 293 rz, 294 S, 295 SingleQubitCliffordGate, 296 SingleQubitGate, 297 SingleQubitPauliStringGateOperation, 298 SQRT_ISWAP, 299 SQRT_ISWAP_INV, 300 SWAP, 301 SwapPowGate, 302 T, 303 TaggedOperation, 304 ThreeQubitGate, 305 ThreeQubitDiagonalGate, 306 TOFFOLI, 307 transform_op_tree, 308 TwoQubitDiagonalGate, 309 TwoQubitGate, 310 VirtualTag, 311 wait, 312 WaitGate, 313 X, 314 XPowGate, 315 XX, 316 XXPowGate, 317 Y, 318 YPowGate, 319 YY, 320 YYPowGate, 321 Z, 322 ZPowGate, 323 ZZ, 324 ZZPowGate, 325) 326 327from cirq.optimizers import ( 328 AlignLeft, 329 AlignRight, 330 compute_cphase_exponents_for_fsim_decomposition, 331 ConvertToCzAndSingleGates, 332 decompose_clifford_tableau_to_operations, 333 decompose_cphase_into_two_fsim, 334 decompose_multi_controlled_x, 335 decompose_multi_controlled_rotation, 336 decompose_two_qubit_interaction_into_four_fsim_gates, 337 DropEmptyMoments, 338 DropNegligible, 339 EjectPhasedPaulis, 340 EjectZ, 341 ExpandComposite, 342 is_negligible_turn, 343 merge_single_qubit_gates_into_phased_x_z, 344 merge_single_qubit_gates_into_phxz, 345 MergeInteractions, 346 MergeInteractionsToSqrtIswap, 347 MergeSingleQubitGates, 348 single_qubit_matrix_to_gates, 349 single_qubit_matrix_to_pauli_rotations, 350 single_qubit_matrix_to_phased_x_z, 351 single_qubit_matrix_to_phxz, 352 single_qubit_op_to_framed_phase_form, 353 stratified_circuit, 354 SynchronizeTerminalMeasurements, 355 two_qubit_matrix_to_operations, 356 two_qubit_matrix_to_diagonal_and_operations, 357 two_qubit_matrix_to_sqrt_iswap_operations, 358 three_qubit_matrix_to_operations, 359) 360 361from cirq.qis import ( 362 bloch_vector_from_state_vector, 363 choi_to_kraus, 364 choi_to_superoperator, 365 CliffordTableau, 366 density_matrix, 367 density_matrix_from_state_vector, 368 dirac_notation, 369 entanglement_fidelity, 370 eye_tensor, 371 fidelity, 372 kraus_to_channel_matrix, 373 kraus_to_choi, 374 kraus_to_superoperator, 375 one_hot, 376 operation_to_channel_matrix, 377 operation_to_choi, 378 operation_to_superoperator, 379 QUANTUM_STATE_LIKE, 380 QuantumState, 381 quantum_state, 382 STATE_VECTOR_LIKE, 383 superoperator_to_choi, 384 superoperator_to_kraus, 385 to_valid_density_matrix, 386 to_valid_state_vector, 387 validate_density_matrix, 388 validate_indices, 389 validate_normalized_state_vector, 390 validate_qid_shape, 391 von_neumann_entropy, 392) 393 394from cirq.sim import ( 395 ActOnArgs, 396 ActOnArgsContainer, 397 ActOnCliffordTableauArgs, 398 ActOnDensityMatrixArgs, 399 ActOnStabilizerCHFormArgs, 400 ActOnStateVectorArgs, 401 StabilizerStateChForm, 402 CIRCUIT_LIKE, 403 CliffordSimulator, 404 CliffordState, 405 CliffordSimulatorStepResult, 406 CliffordTrialResult, 407 DensityMatrixSimulator, 408 DensityMatrixSimulatorState, 409 DensityMatrixStepResult, 410 DensityMatrixTrialResult, 411 measure_density_matrix, 412 measure_state_vector, 413 final_density_matrix, 414 final_state_vector, 415 OperationTarget, 416 sample, 417 sample_density_matrix, 418 sample_state_vector, 419 sample_sweep, 420 SimulatesAmplitudes, 421 SimulatesExpectationValues, 422 SimulatesFinalState, 423 SimulatesIntermediateState, 424 SimulatesIntermediateStateVector, 425 SimulatesSamples, 426 SimulationTrialResult, 427 Simulator, 428 SimulatorBase, 429 SparseSimulatorStep, 430 StabilizerSampler, 431 StateVectorMixin, 432 StateVectorSimulatorState, 433 StateVectorStepResult, 434 StateVectorTrialResult, 435 StepResult, 436 StepResultBase, 437) 438 439from cirq.study import ( 440 dict_to_product_sweep, 441 dict_to_zip_sweep, 442 ExpressionMap, 443 flatten, 444 flatten_with_params, 445 flatten_with_sweep, 446 Linspace, 447 ListSweep, 448 ParamDictType, 449 ParamResolver, 450 ParamResolverOrSimilarType, 451 Points, 452 Product, 453 Sweep, 454 Sweepable, 455 to_resolvers, 456 to_sweep, 457 to_sweeps, 458 Result, 459 UnitSweep, 460 Zip, 461) 462 463from cirq.value import ( 464 ABCMetaImplementAnyOneOf, 465 alternative, 466 big_endian_bits_to_int, 467 big_endian_digits_to_int, 468 big_endian_int_to_bits, 469 big_endian_int_to_digits, 470 canonicalize_half_turns, 471 chosen_angle_to_canonical_half_turns, 472 chosen_angle_to_half_turns, 473 Duration, 474 DURATION_LIKE, 475 GenericMetaImplementAnyOneOf, 476 LinearDict, 477 MEASUREMENT_KEY_SEPARATOR, 478 MeasurementKey, 479 PeriodicValue, 480 RANDOM_STATE_OR_SEED_LIKE, 481 state_vector_to_probabilities, 482 Timestamp, 483 TParamKey, 484 TParamVal, 485 validate_probability, 486 value_equality, 487 KET_PLUS, 488 KET_MINUS, 489 KET_IMAG, 490 KET_MINUS_IMAG, 491 KET_ZERO, 492 KET_ONE, 493 PAULI_STATES, 494 ProductState, 495) 496 497# pylint: disable=redefined-builtin 498from cirq.protocols import ( 499 act_on, 500 apply_channel, 501 apply_mixture, 502 apply_unitaries, 503 apply_unitary, 504 ApplyChannelArgs, 505 ApplyMixtureArgs, 506 ApplyUnitaryArgs, 507 approx_eq, 508 circuit_diagram_info, 509 CircuitDiagramInfo, 510 CircuitDiagramInfoArgs, 511 commutes, 512 decompose, 513 decompose_once, 514 decompose_once_with_qubits, 515 DEFAULT_RESOLVERS, 516 definitely_commutes, 517 equal_up_to_global_phase, 518 has_kraus, 519 has_mixture, 520 has_stabilizer_effect, 521 has_unitary, 522 inverse, 523 is_measurement, 524 is_parameterized, 525 JsonResolver, 526 json_serializable_dataclass, 527 dataclass_json_dict, 528 kraus, 529 measurement_key_name, 530 measurement_key_obj, 531 measurement_key_names, 532 measurement_key_objs, 533 mixture, 534 mul, 535 num_qubits, 536 parameter_names, 537 parameter_symbols, 538 pauli_expansion, 539 phase_by, 540 pow, 541 qasm, 542 QasmArgs, 543 qid_shape, 544 quil, 545 QuilFormatter, 546 read_json_gzip, 547 read_json, 548 resolve_parameters, 549 resolve_parameters_once, 550 SerializableByKey, 551 SupportsActOn, 552 SupportsActOnQubits, 553 SupportsApplyChannel, 554 SupportsApplyMixture, 555 SupportsApproximateEquality, 556 SupportsConsistentApplyUnitary, 557 SupportsCircuitDiagramInfo, 558 SupportsCommutes, 559 SupportsDecompose, 560 SupportsDecomposeWithQubits, 561 SupportsEqualUpToGlobalPhase, 562 SupportsExplicitHasUnitary, 563 SupportsExplicitQidShape, 564 SupportsExplicitNumQubits, 565 SupportsJSON, 566 SupportsKraus, 567 SupportsMeasurementKey, 568 SupportsMixture, 569 SupportsParameterization, 570 SupportsPauliExpansion, 571 SupportsPhase, 572 SupportsQasm, 573 SupportsQasmWithArgs, 574 SupportsQasmWithArgsAndQubits, 575 SupportsTraceDistanceBound, 576 SupportsUnitary, 577 to_json_gzip, 578 to_json, 579 obj_to_dict_helper, 580 trace_distance_bound, 581 trace_distance_from_angle_list, 582 unitary, 583 validate_mixture, 584 with_key_path, 585 with_measurement_key_mapping, 586) 587 588from cirq.ion import ( 589 ConvertToIonGates, 590 IonDevice, 591 ms, 592 two_qubit_matrix_to_ion_operations, 593) 594from cirq.neutral_atoms import ( 595 ConvertToNeutralAtomGates, 596 is_native_neutral_atom_gate, 597 is_native_neutral_atom_op, 598 NeutralAtomDevice, 599) 600 601from cirq.vis import ( 602 Heatmap, 603 TwoQubitInteractionHeatmap, 604 get_state_histogram, 605 integrated_histogram, 606) 607 608from cirq.work import ( 609 CircuitSampleJob, 610 PauliSumCollector, 611 Sampler, 612 Collector, 613 ZerosSampler, 614) 615 616# pylint: enable=redefined-builtin 617 618# Unflattened sub-modules. 619 620from cirq import ( 621 testing, 622) 623 624_compat.deprecated_submodule( 625 new_module_name='cirq_google', 626 old_parent=__name__, 627 old_child='google', 628 deadline="v0.14", 629 create_attribute=True, 630) 631 632_compat.deprecated_submodule( 633 new_module_name='cirq_aqt', 634 old_parent=__name__, 635 old_child='aqt', 636 deadline="v0.14", 637 create_attribute=True, 638) 639 640 641_compat.deprecated_submodule( 642 new_module_name='cirq_ionq', 643 old_parent=__name__, 644 old_child='ionq', 645 deadline="v0.14", 646 create_attribute=True, 647) 648 649_compat.deprecated_submodule( 650 new_module_name='cirq_pasqal', 651 old_parent=__name__, 652 old_child='pasqal', 653 deadline="v0.14", 654 create_attribute=True, 655) 656 657 658# Registers cirq-core's public classes for JSON serialization. 659# pylint: disable=wrong-import-position 660from cirq.protocols.json_serialization import _register_resolver 661from cirq.json_resolver_cache import _class_resolver_dictionary 662 663 664_register_resolver(_class_resolver_dictionary) 665 666# contrib's json resolver cache depends on cirq.DEFAULT_RESOLVER 667 668from cirq import ( 669 contrib, 670) 671 672# pylint: enable=wrong-import-position 673