qiskit 2.1.0rc1__cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qiskit/VERSION.txt +1 -0
- qiskit/__init__.py +159 -0
- qiskit/_accelerate.abi3.so +0 -0
- qiskit/_numpy_compat.py +73 -0
- qiskit/circuit/__init__.py +1335 -0
- qiskit/circuit/_add_control.py +338 -0
- qiskit/circuit/_classical_resource_map.py +154 -0
- qiskit/circuit/_standard_gates_commutations.py +3849 -0
- qiskit/circuit/_utils.py +167 -0
- qiskit/circuit/annotated_operation.py +279 -0
- qiskit/circuit/annotation.py +404 -0
- qiskit/circuit/barrier.py +46 -0
- qiskit/circuit/classical/__init__.py +41 -0
- qiskit/circuit/classical/expr/__init__.py +266 -0
- qiskit/circuit/classical/expr/constructors.py +764 -0
- qiskit/circuit/classical/expr/expr.py +156 -0
- qiskit/circuit/classical/expr/visitors.py +381 -0
- qiskit/circuit/classical/types/__init__.py +113 -0
- qiskit/circuit/classical/types/ordering.py +229 -0
- qiskit/circuit/classical/types/types.py +30 -0
- qiskit/circuit/commutation_checker.py +133 -0
- qiskit/circuit/commutation_library.py +20 -0
- qiskit/circuit/controlflow/__init__.py +59 -0
- qiskit/circuit/controlflow/_builder_utils.py +211 -0
- qiskit/circuit/controlflow/box.py +188 -0
- qiskit/circuit/controlflow/break_loop.py +56 -0
- qiskit/circuit/controlflow/builder.py +791 -0
- qiskit/circuit/controlflow/continue_loop.py +56 -0
- qiskit/circuit/controlflow/control_flow.py +94 -0
- qiskit/circuit/controlflow/for_loop.py +218 -0
- qiskit/circuit/controlflow/if_else.py +498 -0
- qiskit/circuit/controlflow/switch_case.py +411 -0
- qiskit/circuit/controlflow/while_loop.py +166 -0
- qiskit/circuit/controlledgate.py +274 -0
- qiskit/circuit/delay.py +159 -0
- qiskit/circuit/duration.py +80 -0
- qiskit/circuit/equivalence.py +94 -0
- qiskit/circuit/equivalence_library.py +18 -0
- qiskit/circuit/exceptions.py +19 -0
- qiskit/circuit/gate.py +261 -0
- qiskit/circuit/instruction.py +564 -0
- qiskit/circuit/instructionset.py +132 -0
- qiskit/circuit/library/__init__.py +984 -0
- qiskit/circuit/library/arithmetic/__init__.py +40 -0
- qiskit/circuit/library/arithmetic/adders/__init__.py +18 -0
- qiskit/circuit/library/arithmetic/adders/adder.py +235 -0
- qiskit/circuit/library/arithmetic/adders/cdkm_ripple_carry_adder.py +123 -0
- qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py +129 -0
- qiskit/circuit/library/arithmetic/adders/vbe_ripple_carry_adder.py +95 -0
- qiskit/circuit/library/arithmetic/exact_reciprocal.py +131 -0
- qiskit/circuit/library/arithmetic/functional_pauli_rotations.py +114 -0
- qiskit/circuit/library/arithmetic/integer_comparator.py +200 -0
- qiskit/circuit/library/arithmetic/linear_amplitude_function.py +363 -0
- qiskit/circuit/library/arithmetic/linear_pauli_rotations.py +243 -0
- qiskit/circuit/library/arithmetic/multipliers/__init__.py +17 -0
- qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_multiplier.py +145 -0
- qiskit/circuit/library/arithmetic/multipliers/multiplier.py +201 -0
- qiskit/circuit/library/arithmetic/multipliers/rg_qft_multiplier.py +108 -0
- qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +506 -0
- qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py +395 -0
- qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py +501 -0
- qiskit/circuit/library/arithmetic/polynomial_pauli_rotations.py +389 -0
- qiskit/circuit/library/arithmetic/quadratic_form.py +370 -0
- qiskit/circuit/library/arithmetic/weighted_adder.py +428 -0
- qiskit/circuit/library/basis_change/__init__.py +15 -0
- qiskit/circuit/library/basis_change/qft.py +316 -0
- qiskit/circuit/library/bit_flip_oracle.py +130 -0
- qiskit/circuit/library/blueprintcircuit.py +322 -0
- qiskit/circuit/library/boolean_logic/__init__.py +18 -0
- qiskit/circuit/library/boolean_logic/inner_product.py +157 -0
- qiskit/circuit/library/boolean_logic/quantum_and.py +204 -0
- qiskit/circuit/library/boolean_logic/quantum_or.py +206 -0
- qiskit/circuit/library/boolean_logic/quantum_xor.py +167 -0
- qiskit/circuit/library/data_preparation/__init__.py +57 -0
- qiskit/circuit/library/data_preparation/_z_feature_map.py +115 -0
- qiskit/circuit/library/data_preparation/_zz_feature_map.py +150 -0
- qiskit/circuit/library/data_preparation/initializer.py +107 -0
- qiskit/circuit/library/data_preparation/pauli_feature_map.py +656 -0
- qiskit/circuit/library/data_preparation/state_preparation.py +336 -0
- qiskit/circuit/library/fourier_checking.py +160 -0
- qiskit/circuit/library/generalized_gates/__init__.py +30 -0
- qiskit/circuit/library/generalized_gates/diagonal.py +163 -0
- qiskit/circuit/library/generalized_gates/gms.py +179 -0
- qiskit/circuit/library/generalized_gates/gr.py +219 -0
- qiskit/circuit/library/generalized_gates/isometry.py +370 -0
- qiskit/circuit/library/generalized_gates/linear_function.py +318 -0
- qiskit/circuit/library/generalized_gates/mcg_up_to_diagonal.py +143 -0
- qiskit/circuit/library/generalized_gates/mcmt.py +316 -0
- qiskit/circuit/library/generalized_gates/pauli.py +84 -0
- qiskit/circuit/library/generalized_gates/permutation.py +202 -0
- qiskit/circuit/library/generalized_gates/rv.py +96 -0
- qiskit/circuit/library/generalized_gates/uc.py +303 -0
- qiskit/circuit/library/generalized_gates/uc_pauli_rot.py +164 -0
- qiskit/circuit/library/generalized_gates/ucrx.py +32 -0
- qiskit/circuit/library/generalized_gates/ucry.py +32 -0
- qiskit/circuit/library/generalized_gates/ucrz.py +32 -0
- qiskit/circuit/library/generalized_gates/unitary.py +236 -0
- qiskit/circuit/library/graph_state.py +172 -0
- qiskit/circuit/library/grover_operator.py +583 -0
- qiskit/circuit/library/hamiltonian_gate.py +142 -0
- qiskit/circuit/library/hidden_linear_function.py +163 -0
- qiskit/circuit/library/iqp.py +180 -0
- qiskit/circuit/library/n_local/__init__.py +45 -0
- qiskit/circuit/library/n_local/efficient_su2.py +282 -0
- qiskit/circuit/library/n_local/evolved_operator_ansatz.py +520 -0
- qiskit/circuit/library/n_local/excitation_preserving.py +301 -0
- qiskit/circuit/library/n_local/n_local.py +1478 -0
- qiskit/circuit/library/n_local/pauli_two_design.py +246 -0
- qiskit/circuit/library/n_local/qaoa_ansatz.py +367 -0
- qiskit/circuit/library/n_local/real_amplitudes.py +312 -0
- qiskit/circuit/library/n_local/two_local.py +289 -0
- qiskit/circuit/library/overlap.py +183 -0
- qiskit/circuit/library/pauli_evolution.py +202 -0
- qiskit/circuit/library/phase_estimation.py +177 -0
- qiskit/circuit/library/phase_oracle.py +239 -0
- qiskit/circuit/library/quantum_volume.py +179 -0
- qiskit/circuit/library/standard_gates/__init__.py +141 -0
- qiskit/circuit/library/standard_gates/dcx.py +76 -0
- qiskit/circuit/library/standard_gates/ecr.py +126 -0
- qiskit/circuit/library/standard_gates/equivalence_library.py +1936 -0
- qiskit/circuit/library/standard_gates/global_phase.py +83 -0
- qiskit/circuit/library/standard_gates/h.py +230 -0
- qiskit/circuit/library/standard_gates/i.py +76 -0
- qiskit/circuit/library/standard_gates/iswap.py +115 -0
- qiskit/circuit/library/standard_gates/p.py +415 -0
- qiskit/circuit/library/standard_gates/r.py +108 -0
- qiskit/circuit/library/standard_gates/rx.py +269 -0
- qiskit/circuit/library/standard_gates/rxx.py +165 -0
- qiskit/circuit/library/standard_gates/ry.py +268 -0
- qiskit/circuit/library/standard_gates/ryy.py +165 -0
- qiskit/circuit/library/standard_gates/rz.py +290 -0
- qiskit/circuit/library/standard_gates/rzx.py +211 -0
- qiskit/circuit/library/standard_gates/rzz.py +181 -0
- qiskit/circuit/library/standard_gates/s.py +424 -0
- qiskit/circuit/library/standard_gates/swap.py +268 -0
- qiskit/circuit/library/standard_gates/sx.py +303 -0
- qiskit/circuit/library/standard_gates/t.py +169 -0
- qiskit/circuit/library/standard_gates/u.py +379 -0
- qiskit/circuit/library/standard_gates/u1.py +466 -0
- qiskit/circuit/library/standard_gates/u2.py +145 -0
- qiskit/circuit/library/standard_gates/u3.py +412 -0
- qiskit/circuit/library/standard_gates/x.py +1335 -0
- qiskit/circuit/library/standard_gates/xx_minus_yy.py +164 -0
- qiskit/circuit/library/standard_gates/xx_plus_yy.py +197 -0
- qiskit/circuit/library/standard_gates/y.py +253 -0
- qiskit/circuit/library/standard_gates/z.py +331 -0
- qiskit/circuit/library/templates/__init__.py +92 -0
- qiskit/circuit/library/templates/clifford/__init__.py +33 -0
- qiskit/circuit/library/templates/clifford/clifford_2_1.py +34 -0
- qiskit/circuit/library/templates/clifford/clifford_2_2.py +35 -0
- qiskit/circuit/library/templates/clifford/clifford_2_3.py +34 -0
- qiskit/circuit/library/templates/clifford/clifford_2_4.py +34 -0
- qiskit/circuit/library/templates/clifford/clifford_3_1.py +35 -0
- qiskit/circuit/library/templates/clifford/clifford_4_1.py +38 -0
- qiskit/circuit/library/templates/clifford/clifford_4_2.py +37 -0
- qiskit/circuit/library/templates/clifford/clifford_4_3.py +38 -0
- qiskit/circuit/library/templates/clifford/clifford_4_4.py +37 -0
- qiskit/circuit/library/templates/clifford/clifford_5_1.py +40 -0
- qiskit/circuit/library/templates/clifford/clifford_6_1.py +40 -0
- qiskit/circuit/library/templates/clifford/clifford_6_2.py +40 -0
- qiskit/circuit/library/templates/clifford/clifford_6_3.py +40 -0
- qiskit/circuit/library/templates/clifford/clifford_6_4.py +38 -0
- qiskit/circuit/library/templates/clifford/clifford_6_5.py +40 -0
- qiskit/circuit/library/templates/clifford/clifford_8_1.py +42 -0
- qiskit/circuit/library/templates/clifford/clifford_8_2.py +42 -0
- qiskit/circuit/library/templates/clifford/clifford_8_3.py +41 -0
- qiskit/circuit/library/templates/nct/__init__.py +67 -0
- qiskit/circuit/library/templates/nct/template_nct_2a_1.py +34 -0
- qiskit/circuit/library/templates/nct/template_nct_2a_2.py +35 -0
- qiskit/circuit/library/templates/nct/template_nct_2a_3.py +37 -0
- qiskit/circuit/library/templates/nct/template_nct_4a_1.py +43 -0
- qiskit/circuit/library/templates/nct/template_nct_4a_2.py +41 -0
- qiskit/circuit/library/templates/nct/template_nct_4a_3.py +39 -0
- qiskit/circuit/library/templates/nct/template_nct_4b_1.py +41 -0
- qiskit/circuit/library/templates/nct/template_nct_4b_2.py +39 -0
- qiskit/circuit/library/templates/nct/template_nct_5a_1.py +40 -0
- qiskit/circuit/library/templates/nct/template_nct_5a_2.py +40 -0
- qiskit/circuit/library/templates/nct/template_nct_5a_3.py +40 -0
- qiskit/circuit/library/templates/nct/template_nct_5a_4.py +39 -0
- qiskit/circuit/library/templates/nct/template_nct_6a_1.py +40 -0
- qiskit/circuit/library/templates/nct/template_nct_6a_2.py +41 -0
- qiskit/circuit/library/templates/nct/template_nct_6a_3.py +41 -0
- qiskit/circuit/library/templates/nct/template_nct_6a_4.py +41 -0
- qiskit/circuit/library/templates/nct/template_nct_6b_1.py +41 -0
- qiskit/circuit/library/templates/nct/template_nct_6b_2.py +41 -0
- qiskit/circuit/library/templates/nct/template_nct_6c_1.py +41 -0
- qiskit/circuit/library/templates/nct/template_nct_7a_1.py +43 -0
- qiskit/circuit/library/templates/nct/template_nct_7b_1.py +43 -0
- qiskit/circuit/library/templates/nct/template_nct_7c_1.py +43 -0
- qiskit/circuit/library/templates/nct/template_nct_7d_1.py +43 -0
- qiskit/circuit/library/templates/nct/template_nct_7e_1.py +43 -0
- qiskit/circuit/library/templates/nct/template_nct_9a_1.py +45 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_1.py +43 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_10.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_11.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_12.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_2.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_3.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_4.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_5.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_6.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_7.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_8.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9c_9.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_1.py +43 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_10.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_2.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_3.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_4.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_5.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_6.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_7.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_8.py +44 -0
- qiskit/circuit/library/templates/nct/template_nct_9d_9.py +44 -0
- qiskit/circuit/library/templates/rzx/__init__.py +25 -0
- qiskit/circuit/library/templates/rzx/rzx_cy.py +47 -0
- qiskit/circuit/library/templates/rzx/rzx_xz.py +54 -0
- qiskit/circuit/library/templates/rzx/rzx_yz.py +45 -0
- qiskit/circuit/library/templates/rzx/rzx_zz1.py +69 -0
- qiskit/circuit/library/templates/rzx/rzx_zz2.py +59 -0
- qiskit/circuit/library/templates/rzx/rzx_zz3.py +59 -0
- qiskit/circuit/measure.py +53 -0
- qiskit/circuit/operation.py +68 -0
- qiskit/circuit/parameter.py +188 -0
- qiskit/circuit/parameterexpression.py +737 -0
- qiskit/circuit/parametertable.py +119 -0
- qiskit/circuit/parametervector.py +140 -0
- qiskit/circuit/quantumcircuit.py +7610 -0
- qiskit/circuit/quantumcircuitdata.py +137 -0
- qiskit/circuit/random/__init__.py +50 -0
- qiskit/circuit/random/utils.py +755 -0
- qiskit/circuit/reset.py +37 -0
- qiskit/circuit/singleton.py +600 -0
- qiskit/circuit/store.py +89 -0
- qiskit/circuit/tools/__init__.py +16 -0
- qiskit/circuit/tools/pi_check.py +185 -0
- qiskit/circuit/twirling.py +145 -0
- qiskit/compiler/__init__.py +27 -0
- qiskit/compiler/transpiler.py +375 -0
- qiskit/converters/__init__.py +74 -0
- qiskit/converters/circuit_to_dag.py +80 -0
- qiskit/converters/circuit_to_dagdependency.py +49 -0
- qiskit/converters/circuit_to_dagdependency_v2.py +46 -0
- qiskit/converters/circuit_to_gate.py +107 -0
- qiskit/converters/circuit_to_instruction.py +142 -0
- qiskit/converters/dag_to_circuit.py +79 -0
- qiskit/converters/dag_to_dagdependency.py +54 -0
- qiskit/converters/dag_to_dagdependency_v2.py +43 -0
- qiskit/converters/dagdependency_to_circuit.py +40 -0
- qiskit/converters/dagdependency_to_dag.py +48 -0
- qiskit/dagcircuit/__init__.py +44 -0
- qiskit/dagcircuit/collect_blocks.py +403 -0
- qiskit/dagcircuit/dagcircuit.py +24 -0
- qiskit/dagcircuit/dagdependency.py +612 -0
- qiskit/dagcircuit/dagdependency_v2.py +566 -0
- qiskit/dagcircuit/dagdepnode.py +160 -0
- qiskit/dagcircuit/dagnode.py +193 -0
- qiskit/dagcircuit/exceptions.py +42 -0
- qiskit/exceptions.py +153 -0
- qiskit/passmanager/__init__.py +258 -0
- qiskit/passmanager/base_tasks.py +230 -0
- qiskit/passmanager/compilation_status.py +74 -0
- qiskit/passmanager/exceptions.py +19 -0
- qiskit/passmanager/flow_controllers.py +116 -0
- qiskit/passmanager/passmanager.py +353 -0
- qiskit/primitives/__init__.py +490 -0
- qiskit/primitives/backend_estimator_v2.py +530 -0
- qiskit/primitives/backend_sampler_v2.py +339 -0
- qiskit/primitives/base/__init__.py +20 -0
- qiskit/primitives/base/base_estimator.py +247 -0
- qiskit/primitives/base/base_primitive_job.py +78 -0
- qiskit/primitives/base/base_primitive_v1.py +45 -0
- qiskit/primitives/base/base_result_v1.py +65 -0
- qiskit/primitives/base/base_sampler.py +196 -0
- qiskit/primitives/base/estimator_result_v1.py +46 -0
- qiskit/primitives/base/sampler_result_v1.py +45 -0
- qiskit/primitives/base/validation_v1.py +250 -0
- qiskit/primitives/containers/__init__.py +26 -0
- qiskit/primitives/containers/bindings_array.py +391 -0
- qiskit/primitives/containers/bit_array.py +764 -0
- qiskit/primitives/containers/data_bin.py +172 -0
- qiskit/primitives/containers/estimator_pub.py +222 -0
- qiskit/primitives/containers/object_array.py +94 -0
- qiskit/primitives/containers/observables_array.py +380 -0
- qiskit/primitives/containers/primitive_result.py +53 -0
- qiskit/primitives/containers/pub_result.py +51 -0
- qiskit/primitives/containers/sampler_pub.py +193 -0
- qiskit/primitives/containers/sampler_pub_result.py +74 -0
- qiskit/primitives/containers/shape.py +129 -0
- qiskit/primitives/primitive_job.py +100 -0
- qiskit/primitives/statevector_estimator.py +175 -0
- qiskit/primitives/statevector_sampler.py +290 -0
- qiskit/primitives/utils.py +72 -0
- qiskit/providers/__init__.py +677 -0
- qiskit/providers/backend.py +364 -0
- qiskit/providers/basic_provider/__init__.py +47 -0
- qiskit/providers/basic_provider/basic_provider.py +121 -0
- qiskit/providers/basic_provider/basic_provider_job.py +65 -0
- qiskit/providers/basic_provider/basic_provider_tools.py +218 -0
- qiskit/providers/basic_provider/basic_simulator.py +693 -0
- qiskit/providers/basic_provider/exceptions.py +30 -0
- qiskit/providers/exceptions.py +33 -0
- qiskit/providers/fake_provider/__init__.py +69 -0
- qiskit/providers/fake_provider/generic_backend_v2.py +376 -0
- qiskit/providers/fake_provider/utils/__init__.py +15 -0
- qiskit/providers/job.py +147 -0
- qiskit/providers/jobstatus.py +30 -0
- qiskit/providers/options.py +273 -0
- qiskit/providers/providerutils.py +110 -0
- qiskit/qasm/libs/dummy/stdgates.inc +75 -0
- qiskit/qasm/libs/qelib1.inc +266 -0
- qiskit/qasm/libs/stdgates.inc +82 -0
- qiskit/qasm2/__init__.py +669 -0
- qiskit/qasm2/exceptions.py +27 -0
- qiskit/qasm2/export.py +364 -0
- qiskit/qasm2/parse.py +438 -0
- qiskit/qasm3/__init__.py +466 -0
- qiskit/qasm3/ast.py +796 -0
- qiskit/qasm3/exceptions.py +27 -0
- qiskit/qasm3/experimental.py +70 -0
- qiskit/qasm3/exporter.py +1363 -0
- qiskit/qasm3/printer.py +620 -0
- qiskit/qpy/__init__.py +2141 -0
- qiskit/qpy/binary_io/__init__.py +35 -0
- qiskit/qpy/binary_io/circuits.py +1687 -0
- qiskit/qpy/binary_io/parse_sympy_repr.py +126 -0
- qiskit/qpy/binary_io/schedules.py +288 -0
- qiskit/qpy/binary_io/value.py +1183 -0
- qiskit/qpy/common.py +361 -0
- qiskit/qpy/exceptions.py +53 -0
- qiskit/qpy/formats.py +458 -0
- qiskit/qpy/interface.py +384 -0
- qiskit/qpy/type_keys.py +415 -0
- qiskit/quantum_info/__init__.py +172 -0
- qiskit/quantum_info/analysis/__init__.py +17 -0
- qiskit/quantum_info/analysis/average.py +47 -0
- qiskit/quantum_info/analysis/distance.py +104 -0
- qiskit/quantum_info/analysis/make_observable.py +44 -0
- qiskit/quantum_info/analysis/z2_symmetries.py +484 -0
- qiskit/quantum_info/operators/__init__.py +29 -0
- qiskit/quantum_info/operators/base_operator.py +145 -0
- qiskit/quantum_info/operators/channel/__init__.py +29 -0
- qiskit/quantum_info/operators/channel/chi.py +191 -0
- qiskit/quantum_info/operators/channel/choi.py +218 -0
- qiskit/quantum_info/operators/channel/kraus.py +337 -0
- qiskit/quantum_info/operators/channel/ptm.py +204 -0
- qiskit/quantum_info/operators/channel/quantum_channel.py +348 -0
- qiskit/quantum_info/operators/channel/stinespring.py +296 -0
- qiskit/quantum_info/operators/channel/superop.py +373 -0
- qiskit/quantum_info/operators/channel/transformations.py +490 -0
- qiskit/quantum_info/operators/custom_iterator.py +48 -0
- qiskit/quantum_info/operators/dihedral/__init__.py +18 -0
- qiskit/quantum_info/operators/dihedral/dihedral.py +511 -0
- qiskit/quantum_info/operators/dihedral/dihedral_circuits.py +216 -0
- qiskit/quantum_info/operators/dihedral/polynomial.py +313 -0
- qiskit/quantum_info/operators/dihedral/random.py +64 -0
- qiskit/quantum_info/operators/linear_op.py +25 -0
- qiskit/quantum_info/operators/measures.py +418 -0
- qiskit/quantum_info/operators/mixins/__init__.py +52 -0
- qiskit/quantum_info/operators/mixins/adjoint.py +52 -0
- qiskit/quantum_info/operators/mixins/group.py +171 -0
- qiskit/quantum_info/operators/mixins/linear.py +84 -0
- qiskit/quantum_info/operators/mixins/multiply.py +62 -0
- qiskit/quantum_info/operators/mixins/tolerances.py +72 -0
- qiskit/quantum_info/operators/op_shape.py +525 -0
- qiskit/quantum_info/operators/operator.py +869 -0
- qiskit/quantum_info/operators/operator_utils.py +76 -0
- qiskit/quantum_info/operators/predicates.py +183 -0
- qiskit/quantum_info/operators/random.py +154 -0
- qiskit/quantum_info/operators/scalar_op.py +254 -0
- qiskit/quantum_info/operators/symplectic/__init__.py +24 -0
- qiskit/quantum_info/operators/symplectic/base_pauli.py +719 -0
- qiskit/quantum_info/operators/symplectic/clifford.py +1032 -0
- qiskit/quantum_info/operators/symplectic/clifford_circuits.py +584 -0
- qiskit/quantum_info/operators/symplectic/pauli.py +755 -0
- qiskit/quantum_info/operators/symplectic/pauli_list.py +1242 -0
- qiskit/quantum_info/operators/symplectic/pauli_utils.py +40 -0
- qiskit/quantum_info/operators/symplectic/random.py +117 -0
- qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1239 -0
- qiskit/quantum_info/operators/utils/__init__.py +20 -0
- qiskit/quantum_info/operators/utils/anti_commutator.py +36 -0
- qiskit/quantum_info/operators/utils/commutator.py +36 -0
- qiskit/quantum_info/operators/utils/double_commutator.py +76 -0
- qiskit/quantum_info/quaternion.py +156 -0
- qiskit/quantum_info/random.py +26 -0
- qiskit/quantum_info/states/__init__.py +28 -0
- qiskit/quantum_info/states/densitymatrix.py +857 -0
- qiskit/quantum_info/states/measures.py +288 -0
- qiskit/quantum_info/states/quantum_state.py +503 -0
- qiskit/quantum_info/states/random.py +157 -0
- qiskit/quantum_info/states/stabilizerstate.py +805 -0
- qiskit/quantum_info/states/statevector.py +977 -0
- qiskit/quantum_info/states/utils.py +247 -0
- qiskit/result/__init__.py +61 -0
- qiskit/result/counts.py +189 -0
- qiskit/result/distributions/__init__.py +17 -0
- qiskit/result/distributions/probability.py +100 -0
- qiskit/result/distributions/quasi.py +154 -0
- qiskit/result/exceptions.py +40 -0
- qiskit/result/models.py +241 -0
- qiskit/result/postprocess.py +239 -0
- qiskit/result/result.py +385 -0
- qiskit/result/sampled_expval.py +76 -0
- qiskit/result/utils.py +294 -0
- qiskit/synthesis/__init__.py +250 -0
- qiskit/synthesis/arithmetic/__init__.py +18 -0
- qiskit/synthesis/arithmetic/adders/__init__.py +18 -0
- qiskit/synthesis/arithmetic/adders/cdkm_ripple_carry_adder.py +154 -0
- qiskit/synthesis/arithmetic/adders/draper_qft_adder.py +107 -0
- qiskit/synthesis/arithmetic/adders/rv_ripple_carry_adder.py +156 -0
- qiskit/synthesis/arithmetic/adders/vbe_ripple_carry_adder.py +161 -0
- qiskit/synthesis/arithmetic/comparators/__init__.py +16 -0
- qiskit/synthesis/arithmetic/comparators/compare_2s.py +112 -0
- qiskit/synthesis/arithmetic/comparators/compare_greedy.py +66 -0
- qiskit/synthesis/arithmetic/multipliers/__init__.py +16 -0
- qiskit/synthesis/arithmetic/multipliers/hrs_cumulative_multiplier.py +103 -0
- qiskit/synthesis/arithmetic/multipliers/rg_qft_multiplier.py +100 -0
- qiskit/synthesis/arithmetic/weighted_sum.py +155 -0
- qiskit/synthesis/boolean/__init__.py +13 -0
- qiskit/synthesis/boolean/boolean_expression.py +231 -0
- qiskit/synthesis/boolean/boolean_expression_synth.py +124 -0
- qiskit/synthesis/boolean/boolean_expression_visitor.py +96 -0
- qiskit/synthesis/clifford/__init__.py +19 -0
- qiskit/synthesis/clifford/clifford_decompose_ag.py +178 -0
- qiskit/synthesis/clifford/clifford_decompose_bm.py +46 -0
- qiskit/synthesis/clifford/clifford_decompose_full.py +64 -0
- qiskit/synthesis/clifford/clifford_decompose_greedy.py +58 -0
- qiskit/synthesis/clifford/clifford_decompose_layers.py +447 -0
- qiskit/synthesis/cnotdihedral/__init__.py +17 -0
- qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_full.py +52 -0
- qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py +141 -0
- qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.py +266 -0
- qiskit/synthesis/discrete_basis/__init__.py +16 -0
- qiskit/synthesis/discrete_basis/generate_basis_approximations.py +53 -0
- qiskit/synthesis/discrete_basis/solovay_kitaev.py +280 -0
- qiskit/synthesis/evolution/__init__.py +21 -0
- qiskit/synthesis/evolution/evolution_synthesis.py +48 -0
- qiskit/synthesis/evolution/lie_trotter.py +123 -0
- qiskit/synthesis/evolution/matrix_synthesis.py +47 -0
- qiskit/synthesis/evolution/pauli_network.py +80 -0
- qiskit/synthesis/evolution/product_formula.py +316 -0
- qiskit/synthesis/evolution/qdrift.py +133 -0
- qiskit/synthesis/evolution/suzuki_trotter.py +227 -0
- qiskit/synthesis/linear/__init__.py +26 -0
- qiskit/synthesis/linear/cnot_synth.py +69 -0
- qiskit/synthesis/linear/linear_circuits_utils.py +128 -0
- qiskit/synthesis/linear/linear_depth_lnn.py +61 -0
- qiskit/synthesis/linear/linear_matrix_utils.py +27 -0
- qiskit/synthesis/linear_phase/__init__.py +17 -0
- qiskit/synthesis/linear_phase/cnot_phase_synth.py +206 -0
- qiskit/synthesis/linear_phase/cx_cz_depth_lnn.py +61 -0
- qiskit/synthesis/linear_phase/cz_depth_lnn.py +58 -0
- qiskit/synthesis/multi_controlled/__init__.py +29 -0
- qiskit/synthesis/multi_controlled/mcmt_vchain.py +52 -0
- qiskit/synthesis/multi_controlled/mcx_synthesis.py +583 -0
- qiskit/synthesis/multi_controlled/multi_control_rotation_gates.py +205 -0
- qiskit/synthesis/one_qubit/__init__.py +15 -0
- qiskit/synthesis/one_qubit/one_qubit_decompose.py +288 -0
- qiskit/synthesis/permutation/__init__.py +18 -0
- qiskit/synthesis/permutation/permutation_full.py +78 -0
- qiskit/synthesis/permutation/permutation_lnn.py +54 -0
- qiskit/synthesis/permutation/permutation_reverse_lnn.py +93 -0
- qiskit/synthesis/permutation/permutation_utils.py +16 -0
- qiskit/synthesis/qft/__init__.py +16 -0
- qiskit/synthesis/qft/qft_decompose_full.py +97 -0
- qiskit/synthesis/qft/qft_decompose_lnn.py +61 -0
- qiskit/synthesis/stabilizer/__init__.py +16 -0
- qiskit/synthesis/stabilizer/stabilizer_circuit.py +149 -0
- qiskit/synthesis/stabilizer/stabilizer_decompose.py +194 -0
- qiskit/synthesis/two_qubit/__init__.py +20 -0
- qiskit/synthesis/two_qubit/local_invariance.py +63 -0
- qiskit/synthesis/two_qubit/two_qubit_decompose.py +583 -0
- qiskit/synthesis/two_qubit/xx_decompose/__init__.py +19 -0
- qiskit/synthesis/two_qubit/xx_decompose/circuits.py +300 -0
- qiskit/synthesis/two_qubit/xx_decompose/decomposer.py +324 -0
- qiskit/synthesis/two_qubit/xx_decompose/embodiments.py +163 -0
- qiskit/synthesis/two_qubit/xx_decompose/paths.py +412 -0
- qiskit/synthesis/two_qubit/xx_decompose/polytopes.py +262 -0
- qiskit/synthesis/two_qubit/xx_decompose/utilities.py +40 -0
- qiskit/synthesis/two_qubit/xx_decompose/weyl.py +133 -0
- qiskit/synthesis/unitary/__init__.py +13 -0
- qiskit/synthesis/unitary/aqc/__init__.py +177 -0
- qiskit/synthesis/unitary/aqc/approximate.py +116 -0
- qiskit/synthesis/unitary/aqc/aqc.py +175 -0
- qiskit/synthesis/unitary/aqc/cnot_structures.py +300 -0
- qiskit/synthesis/unitary/aqc/cnot_unit_circuit.py +103 -0
- qiskit/synthesis/unitary/aqc/cnot_unit_objective.py +299 -0
- qiskit/synthesis/unitary/aqc/elementary_operations.py +108 -0
- qiskit/synthesis/unitary/aqc/fast_gradient/__init__.py +164 -0
- qiskit/synthesis/unitary/aqc/fast_gradient/fast_grad_utils.py +237 -0
- qiskit/synthesis/unitary/aqc/fast_gradient/fast_gradient.py +226 -0
- qiskit/synthesis/unitary/aqc/fast_gradient/layer.py +370 -0
- qiskit/synthesis/unitary/aqc/fast_gradient/pmatrix.py +312 -0
- qiskit/synthesis/unitary/qsd.py +359 -0
- qiskit/transpiler/__init__.py +1352 -0
- qiskit/transpiler/basepasses.py +190 -0
- qiskit/transpiler/coupling.py +500 -0
- qiskit/transpiler/exceptions.py +59 -0
- qiskit/transpiler/instruction_durations.py +263 -0
- qiskit/transpiler/layout.py +740 -0
- qiskit/transpiler/passes/__init__.py +278 -0
- qiskit/transpiler/passes/analysis/__init__.py +23 -0
- qiskit/transpiler/passes/analysis/count_ops.py +30 -0
- qiskit/transpiler/passes/analysis/count_ops_longest_path.py +26 -0
- qiskit/transpiler/passes/analysis/dag_longest_path.py +24 -0
- qiskit/transpiler/passes/analysis/depth.py +33 -0
- qiskit/transpiler/passes/analysis/num_qubits.py +26 -0
- qiskit/transpiler/passes/analysis/num_tensor_factors.py +26 -0
- qiskit/transpiler/passes/analysis/resource_estimation.py +41 -0
- qiskit/transpiler/passes/analysis/size.py +36 -0
- qiskit/transpiler/passes/analysis/width.py +27 -0
- qiskit/transpiler/passes/basis/__init__.py +19 -0
- qiskit/transpiler/passes/basis/basis_translator.py +138 -0
- qiskit/transpiler/passes/basis/decompose.py +137 -0
- qiskit/transpiler/passes/basis/translate_parameterized.py +175 -0
- qiskit/transpiler/passes/basis/unroll_3q_or_more.py +84 -0
- qiskit/transpiler/passes/basis/unroll_custom_definitions.py +110 -0
- qiskit/transpiler/passes/layout/__init__.py +26 -0
- qiskit/transpiler/passes/layout/_csp_custom_solver.py +65 -0
- qiskit/transpiler/passes/layout/apply_layout.py +128 -0
- qiskit/transpiler/passes/layout/csp_layout.py +132 -0
- qiskit/transpiler/passes/layout/dense_layout.py +197 -0
- qiskit/transpiler/passes/layout/disjoint_utils.py +54 -0
- qiskit/transpiler/passes/layout/enlarge_with_ancilla.py +49 -0
- qiskit/transpiler/passes/layout/full_ancilla_allocation.py +116 -0
- qiskit/transpiler/passes/layout/layout_2q_distance.py +77 -0
- qiskit/transpiler/passes/layout/sabre_layout.py +525 -0
- qiskit/transpiler/passes/layout/sabre_pre_layout.py +225 -0
- qiskit/transpiler/passes/layout/set_layout.py +69 -0
- qiskit/transpiler/passes/layout/trivial_layout.py +66 -0
- qiskit/transpiler/passes/layout/vf2_layout.py +292 -0
- qiskit/transpiler/passes/layout/vf2_post_layout.py +376 -0
- qiskit/transpiler/passes/layout/vf2_utils.py +245 -0
- qiskit/transpiler/passes/optimization/__init__.py +42 -0
- qiskit/transpiler/passes/optimization/_gate_extension.py +80 -0
- qiskit/transpiler/passes/optimization/collect_1q_runs.py +31 -0
- qiskit/transpiler/passes/optimization/collect_2q_blocks.py +35 -0
- qiskit/transpiler/passes/optimization/collect_and_collapse.py +117 -0
- qiskit/transpiler/passes/optimization/collect_cliffords.py +109 -0
- qiskit/transpiler/passes/optimization/collect_linear_functions.py +85 -0
- qiskit/transpiler/passes/optimization/collect_multiqubit_blocks.py +242 -0
- qiskit/transpiler/passes/optimization/commutation_analysis.py +44 -0
- qiskit/transpiler/passes/optimization/commutative_cancellation.py +82 -0
- qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py +140 -0
- qiskit/transpiler/passes/optimization/consolidate_blocks.py +176 -0
- qiskit/transpiler/passes/optimization/contract_idle_wires_in_control_flow.py +104 -0
- qiskit/transpiler/passes/optimization/elide_permutations.py +91 -0
- qiskit/transpiler/passes/optimization/hoare_opt.py +420 -0
- qiskit/transpiler/passes/optimization/inverse_cancellation.py +95 -0
- qiskit/transpiler/passes/optimization/light_cone.py +135 -0
- qiskit/transpiler/passes/optimization/optimize_1q_commutation.py +267 -0
- qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +251 -0
- qiskit/transpiler/passes/optimization/optimize_1q_gates.py +384 -0
- qiskit/transpiler/passes/optimization/optimize_annotated.py +449 -0
- qiskit/transpiler/passes/optimization/optimize_clifford_t.py +68 -0
- qiskit/transpiler/passes/optimization/optimize_cliffords.py +89 -0
- qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py +71 -0
- qiskit/transpiler/passes/optimization/remove_diagonal_gates_before_measure.py +41 -0
- qiskit/transpiler/passes/optimization/remove_final_reset.py +37 -0
- qiskit/transpiler/passes/optimization/remove_identity_equiv.py +70 -0
- qiskit/transpiler/passes/optimization/remove_reset_in_zero_state.py +37 -0
- qiskit/transpiler/passes/optimization/reset_after_measure_simplification.py +50 -0
- qiskit/transpiler/passes/optimization/split_2q_unitaries.py +63 -0
- qiskit/transpiler/passes/optimization/template_matching/__init__.py +19 -0
- qiskit/transpiler/passes/optimization/template_matching/backward_match.py +749 -0
- qiskit/transpiler/passes/optimization/template_matching/forward_match.py +452 -0
- qiskit/transpiler/passes/optimization/template_matching/maximal_matches.py +77 -0
- qiskit/transpiler/passes/optimization/template_matching/template_matching.py +370 -0
- qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +633 -0
- qiskit/transpiler/passes/optimization/template_optimization.py +158 -0
- qiskit/transpiler/passes/routing/__init__.py +21 -0
- qiskit/transpiler/passes/routing/algorithms/__init__.py +33 -0
- qiskit/transpiler/passes/routing/algorithms/token_swapper.py +105 -0
- qiskit/transpiler/passes/routing/algorithms/types.py +46 -0
- qiskit/transpiler/passes/routing/algorithms/util.py +103 -0
- qiskit/transpiler/passes/routing/basic_swap.py +166 -0
- qiskit/transpiler/passes/routing/commuting_2q_gate_routing/__init__.py +25 -0
- qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_block.py +60 -0
- qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +397 -0
- qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +145 -0
- qiskit/transpiler/passes/routing/commuting_2q_gate_routing/swap_strategy.py +306 -0
- qiskit/transpiler/passes/routing/layout_transformation.py +119 -0
- qiskit/transpiler/passes/routing/lookahead_swap.py +390 -0
- qiskit/transpiler/passes/routing/sabre_swap.py +465 -0
- qiskit/transpiler/passes/routing/star_prerouting.py +433 -0
- qiskit/transpiler/passes/routing/utils.py +35 -0
- qiskit/transpiler/passes/scheduling/__init__.py +21 -0
- qiskit/transpiler/passes/scheduling/alignments/__init__.py +79 -0
- qiskit/transpiler/passes/scheduling/alignments/check_durations.py +70 -0
- qiskit/transpiler/passes/scheduling/alignments/reschedule.py +251 -0
- qiskit/transpiler/passes/scheduling/padding/__init__.py +17 -0
- qiskit/transpiler/passes/scheduling/padding/base_padding.py +284 -0
- qiskit/transpiler/passes/scheduling/padding/context_aware_dynamical_decoupling.py +876 -0
- qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +415 -0
- qiskit/transpiler/passes/scheduling/padding/pad_delay.py +90 -0
- qiskit/transpiler/passes/scheduling/scheduling/__init__.py +17 -0
- qiskit/transpiler/passes/scheduling/scheduling/alap.py +93 -0
- qiskit/transpiler/passes/scheduling/scheduling/asap.py +100 -0
- qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +88 -0
- qiskit/transpiler/passes/scheduling/scheduling/set_io_latency.py +64 -0
- qiskit/transpiler/passes/scheduling/time_unit_conversion.py +237 -0
- qiskit/transpiler/passes/synthesis/__init__.py +21 -0
- qiskit/transpiler/passes/synthesis/aqc_plugin.py +153 -0
- qiskit/transpiler/passes/synthesis/clifford_unitary_synth_plugin.py +123 -0
- qiskit/transpiler/passes/synthesis/default_unitary_synth_plugin.py +653 -0
- qiskit/transpiler/passes/synthesis/high_level_synthesis.py +429 -0
- qiskit/transpiler/passes/synthesis/hls_plugins.py +2338 -0
- qiskit/transpiler/passes/synthesis/linear_functions_synthesis.py +41 -0
- qiskit/transpiler/passes/synthesis/plugin.py +738 -0
- qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +318 -0
- qiskit/transpiler/passes/synthesis/unitary_synthesis.py +425 -0
- qiskit/transpiler/passes/utils/__init__.py +32 -0
- qiskit/transpiler/passes/utils/barrier_before_final_measurements.py +41 -0
- qiskit/transpiler/passes/utils/check_gate_direction.py +60 -0
- qiskit/transpiler/passes/utils/check_map.py +78 -0
- qiskit/transpiler/passes/utils/contains_instruction.py +45 -0
- qiskit/transpiler/passes/utils/control_flow.py +61 -0
- qiskit/transpiler/passes/utils/dag_fixed_point.py +36 -0
- qiskit/transpiler/passes/utils/error.py +69 -0
- qiskit/transpiler/passes/utils/filter_op_nodes.py +66 -0
- qiskit/transpiler/passes/utils/fixed_point.py +48 -0
- qiskit/transpiler/passes/utils/gate_direction.py +93 -0
- qiskit/transpiler/passes/utils/gates_basis.py +51 -0
- qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +163 -0
- qiskit/transpiler/passes/utils/minimum_point.py +118 -0
- qiskit/transpiler/passes/utils/remove_barriers.py +50 -0
- qiskit/transpiler/passes/utils/remove_final_measurements.py +121 -0
- qiskit/transpiler/passes/utils/unroll_forloops.py +81 -0
- qiskit/transpiler/passmanager.py +503 -0
- qiskit/transpiler/passmanager_config.py +154 -0
- qiskit/transpiler/preset_passmanagers/__init__.py +93 -0
- qiskit/transpiler/preset_passmanagers/builtin_plugins.py +1114 -0
- qiskit/transpiler/preset_passmanagers/common.py +773 -0
- qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +443 -0
- qiskit/transpiler/preset_passmanagers/level0.py +104 -0
- qiskit/transpiler/preset_passmanagers/level1.py +108 -0
- qiskit/transpiler/preset_passmanagers/level2.py +109 -0
- qiskit/transpiler/preset_passmanagers/level3.py +110 -0
- qiskit/transpiler/preset_passmanagers/plugin.py +346 -0
- qiskit/transpiler/target.py +905 -0
- qiskit/transpiler/timing_constraints.py +59 -0
- qiskit/user_config.py +266 -0
- qiskit/utils/__init__.py +90 -0
- qiskit/utils/classtools.py +146 -0
- qiskit/utils/deprecation.py +382 -0
- qiskit/utils/lazy_tester.py +363 -0
- qiskit/utils/optionals.py +355 -0
- qiskit/utils/parallel.py +318 -0
- qiskit/utils/units.py +146 -0
- qiskit/version.py +84 -0
- qiskit/visualization/__init__.py +290 -0
- qiskit/visualization/array.py +207 -0
- qiskit/visualization/bloch.py +778 -0
- qiskit/visualization/circuit/__init__.py +15 -0
- qiskit/visualization/circuit/_utils.py +677 -0
- qiskit/visualization/circuit/circuit_visualization.py +735 -0
- qiskit/visualization/circuit/latex.py +668 -0
- qiskit/visualization/circuit/matplotlib.py +2041 -0
- qiskit/visualization/circuit/qcstyle.py +130 -0
- qiskit/visualization/circuit/styles/__init__.py +13 -0
- qiskit/visualization/circuit/styles/bw.json +202 -0
- qiskit/visualization/circuit/styles/clifford.json +202 -0
- qiskit/visualization/circuit/styles/iqp-dark.json +214 -0
- qiskit/visualization/circuit/styles/iqp.json +214 -0
- qiskit/visualization/circuit/styles/textbook.json +202 -0
- qiskit/visualization/circuit/text.py +1849 -0
- qiskit/visualization/circuit_visualization.py +19 -0
- qiskit/visualization/counts_visualization.py +487 -0
- qiskit/visualization/dag/__init__.py +13 -0
- qiskit/visualization/dag/dagstyle.py +103 -0
- qiskit/visualization/dag/styles/__init__.py +13 -0
- qiskit/visualization/dag/styles/color.json +10 -0
- qiskit/visualization/dag/styles/plain.json +5 -0
- qiskit/visualization/dag_visualization.py +389 -0
- qiskit/visualization/exceptions.py +21 -0
- qiskit/visualization/gate_map.py +1424 -0
- qiskit/visualization/library.py +40 -0
- qiskit/visualization/pass_manager_visualization.py +312 -0
- qiskit/visualization/state_visualization.py +1546 -0
- qiskit/visualization/style.py +223 -0
- qiskit/visualization/timeline/__init__.py +21 -0
- qiskit/visualization/timeline/core.py +495 -0
- qiskit/visualization/timeline/drawings.py +260 -0
- qiskit/visualization/timeline/generators.py +506 -0
- qiskit/visualization/timeline/interface.py +444 -0
- qiskit/visualization/timeline/layouts.py +115 -0
- qiskit/visualization/timeline/plotters/__init__.py +16 -0
- qiskit/visualization/timeline/plotters/base_plotter.py +58 -0
- qiskit/visualization/timeline/plotters/matplotlib.py +195 -0
- qiskit/visualization/timeline/stylesheet.py +301 -0
- qiskit/visualization/timeline/types.py +148 -0
- qiskit/visualization/transition_visualization.py +369 -0
- qiskit/visualization/utils.py +49 -0
- qiskit-2.1.0rc1.dist-info/METADATA +221 -0
- qiskit-2.1.0rc1.dist-info/RECORD +699 -0
- qiskit-2.1.0rc1.dist-info/WHEEL +6 -0
- qiskit-2.1.0rc1.dist-info/entry_points.txt +88 -0
- qiskit-2.1.0rc1.dist-info/licenses/LICENSE.txt +203 -0
- qiskit-2.1.0rc1.dist-info/top_level.txt +1 -0
qiskit/qpy/__init__.py
ADDED
@@ -0,0 +1,2141 @@
|
|
1
|
+
# This code is part of Qiskit.
|
2
|
+
#
|
3
|
+
# (C) Copyright IBM 2021, 2022.
|
4
|
+
#
|
5
|
+
# This code is licensed under the Apache License, Version 2.0. You may
|
6
|
+
# obtain a copy of this license in the LICENSE.txt file in the root directory
|
7
|
+
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
|
8
|
+
#
|
9
|
+
# Any modifications or derivative works of this code must retain this
|
10
|
+
# copyright notice, and modified files need to carry a notice indicating
|
11
|
+
# that they have been altered from the originals.
|
12
|
+
|
13
|
+
"""
|
14
|
+
=====================================
|
15
|
+
QPY serialization (:mod:`qiskit.qpy`)
|
16
|
+
=====================================
|
17
|
+
|
18
|
+
.. currentmodule:: qiskit.qpy
|
19
|
+
|
20
|
+
QPY is a binary serialization format for :class:`~.QuantumCircuit`
|
21
|
+
objects that is designed to be cross-platform, Python version agnostic,
|
22
|
+
and backwards compatible moving forward. QPY should be used if you need
|
23
|
+
a mechanism to save or copy between systems a :class:`~.QuantumCircuit`
|
24
|
+
that preserves the full Qiskit object structure (except for custom attributes
|
25
|
+
defined outside of Qiskit code). This differs from other serialization formats like
|
26
|
+
`OpenQASM <https://github.com/openqasm/openqasm>`__ (2.0 or 3.0) which has a
|
27
|
+
different abstraction model and can result in a loss of information contained
|
28
|
+
in the original circuit (or is unable to represent some aspects of the
|
29
|
+
Qiskit objects) or Python's `pickle <https://docs.python.org/3/library/pickle.html>`__
|
30
|
+
which will preserve the Qiskit object exactly but will only work for a single Qiskit
|
31
|
+
version (it is also
|
32
|
+
`potentially insecure <https://docs.python.org/3/library/pickle.html#module-pickle>`__).
|
33
|
+
|
34
|
+
Basic Usage
|
35
|
+
===========
|
36
|
+
|
37
|
+
Using QPY is defined to be straightforward and mirror the user API of the
|
38
|
+
serializers in Python's standard library, ``pickle`` and ``json``. There are
|
39
|
+
2 user facing functions: :func:`qiskit.qpy.dump` and
|
40
|
+
:func:`qiskit.qpy.load` which are used to dump QPY data
|
41
|
+
to a file object and load circuits from QPY data in a file object respectively.
|
42
|
+
For example:
|
43
|
+
|
44
|
+
.. plot::
|
45
|
+
:nofigs:
|
46
|
+
:context: reset
|
47
|
+
|
48
|
+
# This code is hidden from users
|
49
|
+
# It's a hack to avoid writing to file when testing the code examples
|
50
|
+
import io
|
51
|
+
bytestream = io.BytesIO()
|
52
|
+
bytestream.close = lambda: bytestream.seek(0)
|
53
|
+
def open(*args):
|
54
|
+
return bytestream
|
55
|
+
|
56
|
+
.. plot::
|
57
|
+
:include-source:
|
58
|
+
:nofigs:
|
59
|
+
:context:
|
60
|
+
|
61
|
+
from qiskit.circuit import QuantumCircuit
|
62
|
+
from qiskit import qpy
|
63
|
+
|
64
|
+
qc = QuantumCircuit(2, name='Bell', metadata={'test': True})
|
65
|
+
qc.h(0)
|
66
|
+
qc.cx(0, 1)
|
67
|
+
qc.measure_all()
|
68
|
+
|
69
|
+
with open('bell.qpy', 'wb') as fd:
|
70
|
+
qpy.dump(qc, fd)
|
71
|
+
|
72
|
+
with open('bell.qpy', 'rb') as fd:
|
73
|
+
new_qc = qpy.load(fd)[0]
|
74
|
+
|
75
|
+
The :func:`qiskit.qpy.dump` function also lets you
|
76
|
+
include multiple circuits in a single QPY file:
|
77
|
+
|
78
|
+
.. plot::
|
79
|
+
:include-source:
|
80
|
+
:nofigs:
|
81
|
+
:context:
|
82
|
+
|
83
|
+
with open('twenty_bells.qpy', 'wb') as fd:
|
84
|
+
qpy.dump([qc] * 20, fd)
|
85
|
+
|
86
|
+
and then loading that file will return a list with all the circuits
|
87
|
+
|
88
|
+
.. plot::
|
89
|
+
:include-source:
|
90
|
+
:nofigs:
|
91
|
+
:context:
|
92
|
+
|
93
|
+
with open('twenty_bells.qpy', 'rb') as fd:
|
94
|
+
twenty_new_bells = qpy.load(fd)
|
95
|
+
|
96
|
+
|
97
|
+
API documentation
|
98
|
+
=================
|
99
|
+
|
100
|
+
.. autofunction:: load
|
101
|
+
.. autofunction:: dump
|
102
|
+
.. autofunction:: get_qpy_version
|
103
|
+
|
104
|
+
These functions will raise a custom subclass of :exc:`.QiskitError` if they encounter problems
|
105
|
+
during serialization or deserialization.
|
106
|
+
|
107
|
+
.. autoexception:: QpyError
|
108
|
+
|
109
|
+
When a lower-than-maximum target QPY version is set for serialization, but the object to be
|
110
|
+
serialized contains features that cannot be represented in that format, a subclass of
|
111
|
+
:exc:`QpyError` is raised:
|
112
|
+
|
113
|
+
.. autoexception:: UnsupportedFeatureForVersion
|
114
|
+
|
115
|
+
Attributes:
|
116
|
+
QPY_VERSION (int): The current QPY format version as of this release. This
|
117
|
+
is the default value of the ``version`` keyword argument on
|
118
|
+
:func:`.qpy.dump` and also the upper bound for accepted values for
|
119
|
+
the same argument. This is also the upper bond on the versions supported
|
120
|
+
by :func:`.qpy.load`.
|
121
|
+
|
122
|
+
QPY_COMPATIBILITY_VERSION (int): The current minimum compatibility QPY
|
123
|
+
format version. This is the minimum version that :func:`.qpy.dump`
|
124
|
+
will accept for the ``version`` keyword argument. :func:`.qpy.load`
|
125
|
+
will be able to load all released format versions of QPY (up until
|
126
|
+
``QPY_VERSION``).
|
127
|
+
|
128
|
+
.. _qpy_compatibility:
|
129
|
+
|
130
|
+
QPY Compatibility
|
131
|
+
=================
|
132
|
+
|
133
|
+
The QPY format is designed to be backwards compatible moving forward. This means
|
134
|
+
you should be able to load a QPY with any newer Qiskit version than the one
|
135
|
+
that generated it. However, loading a QPY file with an older Qiskit version is
|
136
|
+
not supported and may not work.
|
137
|
+
|
138
|
+
For example, if you generated a QPY file using qiskit-terra 0.18.1 you could
|
139
|
+
load that QPY file with qiskit-terra 0.19.0 and a hypothetical qiskit-terra
|
140
|
+
0.29.0. However, loading that QPY file with 0.18.0 is not supported and may not
|
141
|
+
work.
|
142
|
+
|
143
|
+
Note that circuit metadata and custom :class:`.Annotation` objects are serialized and deserialized
|
144
|
+
by user-supplied classes, as the objects themselves are completely user-custom, so the forwards- and
|
145
|
+
backwards-compatibility of these is limited by what the user provides.
|
146
|
+
|
147
|
+
If a feature being loaded is deprecated in the corresponding qiskit release, QPY will
|
148
|
+
raise a :exc:`~.QPYLoadingDeprecatedFeatureWarning` informing of the deprecation period
|
149
|
+
and how the feature will be internally handled.
|
150
|
+
|
151
|
+
.. autoexception:: QPYLoadingDeprecatedFeatureWarning
|
152
|
+
|
153
|
+
.. note::
|
154
|
+
|
155
|
+
With versions of Qiskit before 1.2.4, the ``use_symengine=True`` argument to :func:`.qpy.dump`
|
156
|
+
could cause problems with backwards compatibility if there were :class:`.ParameterExpression`
|
157
|
+
objects to serialize. In particular:
|
158
|
+
|
159
|
+
* When the loading version of Qiskit is 1.2.4 or greater, QPY files generated with any version
|
160
|
+
of Qiskit >= 0.46.0 can be loaded. If a version of Qiskit between 0.45.0 and 0.45.3 was used
|
161
|
+
to generate the files, and the non-default argument ``use_symengine=True`` was given to
|
162
|
+
:func:`.qpy.dump`, the file can only be read if the version of ``symengine`` used in the
|
163
|
+
generating environment was in the 0.11 or 0.13 series, but if the environment was created
|
164
|
+
during the support window of Qiskit 0.45, it is likely that ``symengine==0.9.2`` was used.
|
165
|
+
|
166
|
+
* When the loading version of Qiskit is between 0.46.0 and 1.2.2 inclusive, the file can only be
|
167
|
+
read if the installed version of ``symengine`` in the loading environment matches the version
|
168
|
+
used in the generating environment.
|
169
|
+
|
170
|
+
To recover a QPY file that fails with ``symengine`` version-related errors during a call to
|
171
|
+
:func:`.qpy.load`, first attempt to use Qiskit >= 1.2.4 to load the file. If this still fails,
|
172
|
+
it is likely because Qiskit 0.45.x was used to generate the file with ``use_symengine=True``.
|
173
|
+
In this case, use Qiskit 0.45.3 with ``symengine==0.9.2`` to load the file, and then re-export
|
174
|
+
it to QPY setting ``use_symengine=False``. The resulting file can then be loaded by any later
|
175
|
+
version of Qiskit.
|
176
|
+
|
177
|
+
.. note::
|
178
|
+
|
179
|
+
Starting with Qiskit version 2.0.0, which removed the Pulse module from the library, QPY provides
|
180
|
+
limited support for loading payloads that include pulse data. Loading a ``ScheduleBlock`` payload,
|
181
|
+
a :class:`.QpyError` exception will be raised. Loading a payload for a circuit that contained pulse
|
182
|
+
gates, the output circuit will contain custom instructions **without** calibration data attached
|
183
|
+
for each pulse gate, leaving them undefined.
|
184
|
+
|
185
|
+
QPY format version history
|
186
|
+
--------------------------
|
187
|
+
|
188
|
+
If you're planning to load a QPY file between different Qiskit versions knowing
|
189
|
+
which versions were available in a given release are useful. As the QPY is
|
190
|
+
backwards compatible but not forwards compatible you need to ensure a given
|
191
|
+
QPY format version was released in the release you're calling :func:`.load`
|
192
|
+
with. The following table lists the QPY versions that were supported in every
|
193
|
+
Qiskit (and qiskit-terra prior to Qiskit 1.0.0) release going back to the introduction
|
194
|
+
of QPY in qiskit-terra 0.18.0.
|
195
|
+
|
196
|
+
.. list-table:: QPY Format Version History
|
197
|
+
:header-rows: 1
|
198
|
+
|
199
|
+
* - Qiskit (qiskit-terra for < 1.0.0) version
|
200
|
+
- :func:`.dump` format(s) output versions
|
201
|
+
- :func:`.load` maximum supported version (older format versions can always be read)
|
202
|
+
* - 2.1.0
|
203
|
+
- 13, 14, 15
|
204
|
+
- 15
|
205
|
+
* - 2.0.2
|
206
|
+
- 13, 14
|
207
|
+
- 14
|
208
|
+
* - 2.0.1
|
209
|
+
- 13, 14
|
210
|
+
- 14
|
211
|
+
* - 2.0.0
|
212
|
+
- 13, 14
|
213
|
+
- 14
|
214
|
+
* - 1.4.3
|
215
|
+
- 10, 11, 12, 13
|
216
|
+
- 13
|
217
|
+
* - 1.4.2
|
218
|
+
- 10, 11, 12, 13
|
219
|
+
- 13
|
220
|
+
* - 1.4.1
|
221
|
+
- 10, 11, 12, 13
|
222
|
+
- 13
|
223
|
+
* - 1.4.0
|
224
|
+
- 10, 11, 12, 13
|
225
|
+
- 13
|
226
|
+
* - 1.3.3
|
227
|
+
- 10, 11, 12, 13
|
228
|
+
- 13
|
229
|
+
* - 1.3.2
|
230
|
+
- 10, 11, 12, 13
|
231
|
+
- 13
|
232
|
+
* - 1.3.1
|
233
|
+
- 10, 11, 12, 13
|
234
|
+
- 13
|
235
|
+
* - 1.3.0
|
236
|
+
- 10, 11, 12, 13
|
237
|
+
- 13
|
238
|
+
* - 1.2.4
|
239
|
+
- 10, 11, 12
|
240
|
+
- 12
|
241
|
+
* - 1.2.3 (yanked)
|
242
|
+
- 10, 11, 12
|
243
|
+
- 12
|
244
|
+
* - 1.2.2
|
245
|
+
- 10, 11, 12
|
246
|
+
- 12
|
247
|
+
* - 1.2.1
|
248
|
+
- 10, 11, 12
|
249
|
+
- 12
|
250
|
+
* - 1.2.0
|
251
|
+
- 10, 11, 12
|
252
|
+
- 12
|
253
|
+
* - 1.1.0
|
254
|
+
- 10, 11, 12
|
255
|
+
- 12
|
256
|
+
* - 1.0.2
|
257
|
+
- 10, 11
|
258
|
+
- 11
|
259
|
+
* - 1.0.1
|
260
|
+
- 10, 11
|
261
|
+
- 11
|
262
|
+
* - 1.0.0
|
263
|
+
- 10, 11
|
264
|
+
- 11
|
265
|
+
* - 0.46.1
|
266
|
+
- 10
|
267
|
+
- 10
|
268
|
+
* - 0.45.3
|
269
|
+
- 10
|
270
|
+
- 10
|
271
|
+
* - 0.45.2
|
272
|
+
- 10
|
273
|
+
- 10
|
274
|
+
* - 0.45.1
|
275
|
+
- 10
|
276
|
+
- 10
|
277
|
+
* - 0.45.0
|
278
|
+
- 10
|
279
|
+
- 10
|
280
|
+
* - 0.25.3
|
281
|
+
- 9
|
282
|
+
- 9
|
283
|
+
* - 0.25.2
|
284
|
+
- 9
|
285
|
+
- 9
|
286
|
+
* - 0.25.1
|
287
|
+
- 9
|
288
|
+
- 9
|
289
|
+
* - 0.24.2
|
290
|
+
- 8
|
291
|
+
- 8
|
292
|
+
* - 0.24.1
|
293
|
+
- 7
|
294
|
+
- 7
|
295
|
+
* - 0.24.0
|
296
|
+
- 7
|
297
|
+
- 7
|
298
|
+
* - 0.23.3
|
299
|
+
- 6
|
300
|
+
- 6
|
301
|
+
* - 0.23.2
|
302
|
+
- 6
|
303
|
+
- 6
|
304
|
+
* - 0.23.1
|
305
|
+
- 6
|
306
|
+
- 6
|
307
|
+
* - 0.23.0
|
308
|
+
- 6
|
309
|
+
- 6
|
310
|
+
* - 0.22.4
|
311
|
+
- 5
|
312
|
+
- 5
|
313
|
+
* - 0.22.3
|
314
|
+
- 5
|
315
|
+
- 5
|
316
|
+
* - 0.22.2
|
317
|
+
- 5
|
318
|
+
- 5
|
319
|
+
* - 0.22.1
|
320
|
+
- 5
|
321
|
+
- 5
|
322
|
+
* - 0.22.0
|
323
|
+
- 5
|
324
|
+
- 5
|
325
|
+
* - 0.21.2
|
326
|
+
- 5
|
327
|
+
- 5
|
328
|
+
* - 0.21.1
|
329
|
+
- 5
|
330
|
+
- 5
|
331
|
+
* - 0.21.0
|
332
|
+
- 5
|
333
|
+
- 5
|
334
|
+
* - 0.20.2
|
335
|
+
- 4
|
336
|
+
- 4
|
337
|
+
* - 0.20.1
|
338
|
+
- 4
|
339
|
+
- 4
|
340
|
+
* - 0.20.0
|
341
|
+
- 4
|
342
|
+
- 4
|
343
|
+
* - 0.19.2
|
344
|
+
- 4
|
345
|
+
- 4
|
346
|
+
* - 0.19.1
|
347
|
+
- 3
|
348
|
+
- 3
|
349
|
+
* - 0.19.0
|
350
|
+
- 2
|
351
|
+
- 2
|
352
|
+
* - 0.18.3
|
353
|
+
- 1
|
354
|
+
- 1
|
355
|
+
* - 0.18.2
|
356
|
+
- 1
|
357
|
+
- 1
|
358
|
+
* - 0.18.1
|
359
|
+
- 1
|
360
|
+
- 1
|
361
|
+
* - 0.18.0
|
362
|
+
- 1
|
363
|
+
- 1
|
364
|
+
|
365
|
+
.. _qpy_format:
|
366
|
+
|
367
|
+
QPY Format
|
368
|
+
==========
|
369
|
+
|
370
|
+
The QPY serialization format is a portable cross-platform binary
|
371
|
+
serialization format for :class:`~qiskit.circuit.QuantumCircuit` objects in Qiskit. The basic
|
372
|
+
file format is as follows:
|
373
|
+
|
374
|
+
A QPY file (or memory object) always starts with the following 6
|
375
|
+
byte UTF8 string: ``QISKIT`` which is immediately followed by the overall
|
376
|
+
file header. The contents of the file header as defined as a C struct are:
|
377
|
+
|
378
|
+
.. code-block:: c
|
379
|
+
|
380
|
+
struct {
|
381
|
+
uint8_t qpy_version;
|
382
|
+
uint8_t qiskit_major_version;
|
383
|
+
uint8_t qiskit_minor_version;
|
384
|
+
uint8_t qiskit_patch_version;
|
385
|
+
uint64_t num_circuits;
|
386
|
+
}
|
387
|
+
|
388
|
+
|
389
|
+
From V10 on, a new field is added to the file header struct to represent the
|
390
|
+
encoding scheme used for symbolic expressions:
|
391
|
+
|
392
|
+
.. code-block:: c
|
393
|
+
|
394
|
+
struct {
|
395
|
+
uint8_t qpy_version;
|
396
|
+
uint8_t qiskit_major_version;
|
397
|
+
uint8_t qiskit_minor_version;
|
398
|
+
uint8_t qiskit_patch_version;
|
399
|
+
uint64_t num_circuits;
|
400
|
+
char symbolic_encoding;
|
401
|
+
}
|
402
|
+
|
403
|
+
All values use network byte order [#f1]_ (big endian) for cross platform
|
404
|
+
compatibility.
|
405
|
+
|
406
|
+
The file header is immediately followed by the circuit payloads.
|
407
|
+
Each individual circuit is composed of the following parts in order from top to bottom:
|
408
|
+
|
409
|
+
.. code-block:: text
|
410
|
+
|
411
|
+
HEADER
|
412
|
+
METADATA
|
413
|
+
REGISTERS
|
414
|
+
ANNOTATION_HEADER
|
415
|
+
STANDALONE_VARS
|
416
|
+
CUSTOM_DEFINITIONS
|
417
|
+
INSTRUCTIONS
|
418
|
+
|
419
|
+
.. versionchanged:: QPY 15
|
420
|
+
``ANNOTATION_HEADER`` was added between ``REGISTERS`` and ``STANDALONE_VARS``.
|
421
|
+
|
422
|
+
.. versionchanged:: QPY 12
|
423
|
+
``STANDALONE_VARS`` was added between ``REGISTERS`` and ``CUSTOM_DEFINITIONS``.
|
424
|
+
|
425
|
+
There is a circuit payload for each circuit (where the total number is dictated
|
426
|
+
by ``num_circuits`` in the file header). There is no padding between the
|
427
|
+
circuits in the data.
|
428
|
+
|
429
|
+
.. _qpy_version_15:
|
430
|
+
|
431
|
+
Version 15
|
432
|
+
----------
|
433
|
+
|
434
|
+
Version 15 adds the concept of custom annotations to the payload format. QPY itself does not
|
435
|
+
specify how annotations are serialized or deserialized, as they are custom user objects. The format
|
436
|
+
does co-operate with sub-serializers, however.
|
437
|
+
|
438
|
+
Version 15 adds the ``ANNOTATION_HEADER`` field between the ``STANDALONE_VARS`` and
|
439
|
+
``CUSTOM_DEFINITIONS`` fields in the top level of a single circuit payload. It modifies the
|
440
|
+
interpretation of one field of the ``INSTRUCTION`` struct in an ABI-compatible manner, and adds a
|
441
|
+
``INSTRUCTION_ANNOTATIONS`` trailer to ``INSTRUCTION`` which is present conditional on a set bit in
|
442
|
+
the ``INSTRUCTION`` payload.
|
443
|
+
|
444
|
+
New ANNOTATION_HEADER
|
445
|
+
~~~~~~~~~~~~~~~~~~~~~
|
446
|
+
|
447
|
+
The ``ANNOTATION_HEADER`` field is a variable-size payload in the header. It begins with an
|
448
|
+
instance of ``ANNOTATION_HEADER_STATIC``, which is the C struct:
|
449
|
+
|
450
|
+
.. code-block:: c
|
451
|
+
|
452
|
+
struct ANNOTATION_HEADER_STATIC {
|
453
|
+
uint32_t num_namespaces;
|
454
|
+
}
|
455
|
+
|
456
|
+
This is immediately followed by ``num_namespaces`` instances of the ``ANNOTATION_STATE`` payload.
|
457
|
+
The order of these is important and should be retained during the deserialization process, as
|
458
|
+
subsequent ``INSTRUCTION_ANNOTATION`` payloads will index into it.
|
459
|
+
|
460
|
+
The ``ANNOTATION_STATE`` payload begins with the fixed C struct:
|
461
|
+
|
462
|
+
.. code-block:: c
|
463
|
+
|
464
|
+
struct ANNOTATION_STATE_HEADER {
|
465
|
+
uint32_t namespace_size;
|
466
|
+
uint64_t state_size;
|
467
|
+
}
|
468
|
+
|
469
|
+
This header is immediately followed by ``namespace_size`` bytes of UTF-8 encoded text, which
|
470
|
+
comprise the namespace. Those bytes are immediately followed by ``state_size`` bytes of arbitrary
|
471
|
+
data. The format of this "state" payload is not defined by QPY. Instead, it is the responsibility
|
472
|
+
of an external object associated with the stored namespace. The format does not dictate how to
|
473
|
+
produce these objects; as annotations are entirely custom, the user must supply the serialization
|
474
|
+
and deserialization methods.
|
475
|
+
|
476
|
+
|
477
|
+
.. _qpy_instruction_v15:
|
478
|
+
|
479
|
+
Changes to INSTRUCTION
|
480
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
481
|
+
|
482
|
+
The ``INSTRUCTION`` struct is modified in an ABI compatible manner to :ref:`its previous definition
|
483
|
+
in version 9 <qpy_instruction_v9>`. The new struct is the C struct (recall that there is no padding
|
484
|
+
between any fields, nor at the end of the struct):
|
485
|
+
|
486
|
+
.. code-block:: c
|
487
|
+
|
488
|
+
struct INSTRUCTION {
|
489
|
+
uint16_t name_size;
|
490
|
+
uint16_t label_size;
|
491
|
+
uint16_t num_parameters;
|
492
|
+
uint32_t num_qargs;
|
493
|
+
uint32_t num_cargs;
|
494
|
+
uint8_t extras_key;
|
495
|
+
uint16_t conditional_reg_name_size;
|
496
|
+
int64_t conditional_value;
|
497
|
+
uint32_t num_ctrl_qubits;
|
498
|
+
uint32_t ctrl_state;
|
499
|
+
}
|
500
|
+
|
501
|
+
where the field ``uint8_t extras_key`` replaces the previous ``uint8_t conditional_key``. The
|
502
|
+
difference is purely in interpretation. The low two bits of the byte are still interpreted as
|
503
|
+
defining the condition and its type. The high bit of the byte is now a flag, indicated whether an
|
504
|
+
``INSTRUCTION_ANNOTATIONS_HEADER`` field is present (if the bit is set) in the trailing data of the
|
505
|
+
``INSTRUCTION`` struct.
|
506
|
+
|
507
|
+
A complete instruction payload appears in the data stream, including trailing objects and without
|
508
|
+
any padding bytes inbetween elements, as:
|
509
|
+
|
510
|
+
.. code-block:: text
|
511
|
+
|
512
|
+
struct INSTRUCTION;
|
513
|
+
uint8_t name[name_size];
|
514
|
+
uint8_t label[label_size];
|
515
|
+
uint8_t register[conditional_reg_name_size]; (1)
|
516
|
+
struct INSTRUCTION_PARAM; (2)
|
517
|
+
struct INSTRUCTION_ARG[num_qargs];
|
518
|
+
struct INSTRUCTION_ARG[num_cargs];
|
519
|
+
struct INSTRUCTION_PARAM[num_parameters];
|
520
|
+
INSTRUCTION_ANNOTATIONS; (3)
|
521
|
+
|
522
|
+
The following notes apply:
|
523
|
+
|
524
|
+
1. if the two low bits of the ``extras_key`` have the value ``2``, indicating the condition is an
|
525
|
+
``EXPRESSION``, the ``conditional_reg_name_size`` is always zero.
|
526
|
+
2. this field is present if and only if the two low bits of the ``extras_key`` have the value ``2``,
|
527
|
+
indicating the condition is an ``EXPRESSION``.
|
528
|
+
3. this field is present if and only if the high bit of the ``extras_key`` is set. This field has
|
529
|
+
a variable size; see :ref:`qpy_instruction_annotations_v15`.
|
530
|
+
|
531
|
+
.. _qpy_instruction_annotations_v15:
|
532
|
+
|
533
|
+
New INSTRUCTION_ANNOTATIONS
|
534
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
535
|
+
|
536
|
+
The ``INSTRUCTION_ANNOTATIONS`` payload begins with the C struct:
|
537
|
+
|
538
|
+
.. code-block:: c
|
539
|
+
|
540
|
+
struct INSTRUCTION_ANNOTATIONS_HEADER {
|
541
|
+
uint32_t num_annotations;
|
542
|
+
}
|
543
|
+
|
544
|
+
This payload is immediately followed by ``num_annotations`` instances of the
|
545
|
+
``INSTRUCTION_ANNOTATION`` payload, which is of a variable size.
|
546
|
+
|
547
|
+
The ``INSRTUCTION_ANNOTATION`` payload is defined by the following C struct plus a trailing number
|
548
|
+
of bytes equal to the ``payload_size``, called ``ANNOTATION_PAYLOAD``.
|
549
|
+
|
550
|
+
.. code-block:: c
|
551
|
+
|
552
|
+
struct INSTRUCTION_ANNOTATION {
|
553
|
+
uint32_t namespace_index;
|
554
|
+
uint32_t payload_size;
|
555
|
+
}
|
556
|
+
|
557
|
+
The ``namespace_index`` is an integer index into the list of defined ``ANNOTATION_NAMESPACE``
|
558
|
+
objects in the ``ANNOTATION_HEADER``. The serialization namespace for an annotation is the UTF-8
|
559
|
+
encoded string in the relevant payload.
|
560
|
+
|
561
|
+
The format of the ``ANNOTATION_PAYLOAD`` object is not specified by QPY. It is defined by an
|
562
|
+
external serialization object associated with the namespace referred to by the ``namespace_index``
|
563
|
+
and its associated serializer state in the ``ANNOTATION_HEADER``.
|
564
|
+
|
565
|
+
|
566
|
+
Changes within PARAM_EXPR_ELEM_V13
|
567
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
568
|
+
|
569
|
+
The struct itself is unchanged. However, for a ``PARAM_EXPR_ELEM_V13`` representing a
|
570
|
+
:meth:`.ParameterExpression.subs` call (with ``op_code = 15``, and therefore ``lhs_type = 'p'`` and
|
571
|
+
``rhs_type = 'n'``), the trailing :ref:`qpy_mapping` now maps keys of the raw bytes of the
|
572
|
+
:class:`.Parameter` UUIDs to the substituted values. Previously (in QPY versions 13 and 14), this
|
573
|
+
mapping stored the parameter names as the keys.
|
574
|
+
|
575
|
+
|
576
|
+
.. _qpy_version_14:
|
577
|
+
|
578
|
+
Version 14
|
579
|
+
----------
|
580
|
+
|
581
|
+
Version 14 adds a new core DURATION type, support for additional :class:`~.types.Type`
|
582
|
+
classes :class:`~.types.Float` and :class:`~.types.Duration`, and a new expression
|
583
|
+
node type :class:`~.expr.Stretch`.
|
584
|
+
|
585
|
+
DURATION
|
586
|
+
~~~~~~~~
|
587
|
+
|
588
|
+
A :class:`~.circuit.Duration` is encoded by a single-byte ASCII ``char`` that encodes the kind of
|
589
|
+
type, followed by a payload that varies depending on the type. The defined codes are:
|
590
|
+
|
591
|
+
============================== ========= =========================================================
|
592
|
+
Qiskit class Type code Payload
|
593
|
+
============================== ========= =========================================================
|
594
|
+
:class:`~.circuit.Duration.dt` ``t`` One ``unsigned long long value``.
|
595
|
+
|
596
|
+
:class:`~.circuit.Duration.ns` ``n`` One ``double value``.
|
597
|
+
|
598
|
+
:class:`~.circuit.Duration.us` ``u`` One ``double value``.
|
599
|
+
|
600
|
+
:class:`~.circuit.Duration.ms` ``m`` One ``double value``.
|
601
|
+
|
602
|
+
:class:`~.circuit.Duration.s` ``s`` One ``double value``.
|
603
|
+
|
604
|
+
============================== ========= =========================================================
|
605
|
+
|
606
|
+
Changes to EXPR_VAR_DECLARATION
|
607
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
608
|
+
|
609
|
+
The ``EXPR_VAR_DECLARATION`` type is now used to represent both :class:`~.expr.Var` standalone
|
610
|
+
variables and :class:`~.expr.Stretch` identifiers. To support this change, the usage type code has
|
611
|
+
two new possible entries, in addition to the existing ones:
|
612
|
+
|
613
|
+
========= =========================================================================================
|
614
|
+
Type code Meaning
|
615
|
+
========= =========================================================================================
|
616
|
+
``A`` A ``capture`` stretch to the circuit.
|
617
|
+
|
618
|
+
``O`` A locally declared stretch to the circuit.
|
619
|
+
|
620
|
+
========= =========================================================================================
|
621
|
+
|
622
|
+
Changes to EXPRESSION
|
623
|
+
---------------------
|
624
|
+
|
625
|
+
The EXPRESSION type code has a new possible entry, ``s``, corresponding to :class:`.expr.Stretch`
|
626
|
+
nodes.
|
627
|
+
|
628
|
+
======================= ========= ====================================================== ========
|
629
|
+
Qiskit class Type code Payload Children
|
630
|
+
======================= ========= ====================================================== ========
|
631
|
+
:class:`~.expr.Stretch` ``s`` One ``unsigned short var_index`` 0
|
632
|
+
======================= ========= ====================================================== ========
|
633
|
+
|
634
|
+
Changes to EXPR_TYPE
|
635
|
+
~~~~~~~~~~~~~~~~~~~~
|
636
|
+
|
637
|
+
The following table shows the new type classes added in the version:
|
638
|
+
|
639
|
+
========================= ========= ==============================================================
|
640
|
+
Qiskit class Type code Payload
|
641
|
+
========================= ========= ==============================================================
|
642
|
+
:class:`~.types.Float` ``f`` None.
|
643
|
+
|
644
|
+
:class:`~.types.Duration` ``d`` None.
|
645
|
+
|
646
|
+
========================= ========= ==============================================================
|
647
|
+
|
648
|
+
Changes to EXPR_VALUE
|
649
|
+
~~~~~~~~~~~~~~~~~~~~~
|
650
|
+
|
651
|
+
The classical expression's type system now supports new encoding types for value literals, in
|
652
|
+
addition to the existing encodings for int and bool. The new value type encodings are below:
|
653
|
+
|
654
|
+
=========================== ========= ============================================================
|
655
|
+
Python type Type code Payload
|
656
|
+
=========================== ========= ============================================================
|
657
|
+
``float`` ``f`` One ``double value``.
|
658
|
+
|
659
|
+
:class:`~.circuit.Duration` ``t`` One ``DURATION``.
|
660
|
+
|
661
|
+
=========================== ========= ============================================================
|
662
|
+
|
663
|
+
.. _qpy_version_13:
|
664
|
+
|
665
|
+
Version 13
|
666
|
+
----------
|
667
|
+
|
668
|
+
Version 13 added a native Qiskit serialization representation for :class:`.ParameterExpression`.
|
669
|
+
Previous QPY versions relied on either ``sympy`` or ``symengine`` to serialize the underlying symbolic
|
670
|
+
expression. Starting in Version 13, QPY now represents the sequence of API calls used to create the
|
671
|
+
:class:`.ParameterExpression`.
|
672
|
+
|
673
|
+
The main change in the serialization format is in the :ref:`qpy_param_expr_v3` payload. The
|
674
|
+
``expr_size`` bytes following the head now contain an array of ``PARAM_EXPR_ELEM_V13`` structs. The
|
675
|
+
intent is for this array to be read one struct at a time, where each struct describes one of the
|
676
|
+
calls to make to reconstruct the :class:`.ParameterExpression`.
|
677
|
+
|
678
|
+
PARAM_EXPR_ELEM_V13
|
679
|
+
~~~~~~~~~~~~~~~~~~~
|
680
|
+
|
681
|
+
The struct format is defined as:
|
682
|
+
|
683
|
+
.. code-block:: c
|
684
|
+
|
685
|
+
struct {
|
686
|
+
unsigned char op_code;
|
687
|
+
char lhs_type;
|
688
|
+
char lhs[16];
|
689
|
+
char rhs_type;
|
690
|
+
char rhs[16];
|
691
|
+
} PARAM_EXPR_ELEM_V13;
|
692
|
+
|
693
|
+
The ``op_code`` field is used to define the operation added to the :class:`.ParameterExpression`.
|
694
|
+
The value can be:
|
695
|
+
|
696
|
+
.. list-table:: PARAM_EXPR_ELEM_V13 op code values
|
697
|
+
:header-rows: 1
|
698
|
+
|
699
|
+
* - ``op_code``
|
700
|
+
- :class:`.ParameterExpression` method
|
701
|
+
* - 0
|
702
|
+
- :meth:`~.ParameterExpression.__add__`
|
703
|
+
* - 1
|
704
|
+
- :meth:`~.ParameterExpression.__sub__`
|
705
|
+
* - 2
|
706
|
+
- :meth:`~.ParameterExpression.__mul__`
|
707
|
+
* - 3
|
708
|
+
- :meth:`~.ParameterExpression.__truediv__`
|
709
|
+
* - 4
|
710
|
+
- :meth:`~.ParameterExpression.__pow__`
|
711
|
+
* - 5
|
712
|
+
- :meth:`~.ParameterExpression.sin`
|
713
|
+
* - 6
|
714
|
+
- :meth:`~.ParameterExpression.cos`
|
715
|
+
* - 7
|
716
|
+
- :meth:`~.ParameterExpression.tan`
|
717
|
+
* - 8
|
718
|
+
- :meth:`~.ParameterExpression.arcsin`
|
719
|
+
* - 9
|
720
|
+
- :meth:`~.ParameterExpression.arccos`
|
721
|
+
* - 10
|
722
|
+
- :meth:`~.ParameterExpression.exp`
|
723
|
+
* - 11
|
724
|
+
- :meth:`~.ParameterExpression.log`
|
725
|
+
* - 12
|
726
|
+
- :meth:`~.ParameterExpression.sign`
|
727
|
+
* - 13
|
728
|
+
- :meth:`~.ParameterExpression.gradient`
|
729
|
+
* - 14
|
730
|
+
- :meth:`~.ParameterExpression.conjugate`
|
731
|
+
* - 15
|
732
|
+
- :meth:`~.ParameterExpression.subs`
|
733
|
+
* - 16
|
734
|
+
- :meth:`~.ParameterExpression.abs`
|
735
|
+
* - 17
|
736
|
+
- :meth:`~.ParameterExpression.arctan`
|
737
|
+
* - 255
|
738
|
+
- NULL
|
739
|
+
|
740
|
+
The ``NULL`` value of 255 is only used to fill the op code field for
|
741
|
+
entries that are not actual operations but indicate recursive definitions.
|
742
|
+
Then the ``lhs_type`` and ``rhs_type`` fields are used to describe
|
743
|
+
the operand types and can be one of the following UTF-8 encoded
|
744
|
+
characters:
|
745
|
+
|
746
|
+
.. list-table:: PARAM_EXPR_ELEM_V13 operand type values
|
747
|
+
:header-rows: 1
|
748
|
+
|
749
|
+
* - Value
|
750
|
+
- Type
|
751
|
+
* - ``n``
|
752
|
+
- ``None``
|
753
|
+
* - ``p``
|
754
|
+
- :class:`.Parameter`
|
755
|
+
* - ``f``
|
756
|
+
- ``float``
|
757
|
+
* - ``c``
|
758
|
+
- ``complex``
|
759
|
+
* - ``i``
|
760
|
+
- ``int``
|
761
|
+
* - ``s``
|
762
|
+
- Recursive :class:`.ParameterExpression` definition start
|
763
|
+
* - ``e``
|
764
|
+
- Recursive :class:`.ParameterExpression` definition stop
|
765
|
+
* - ``u``
|
766
|
+
- substitution
|
767
|
+
|
768
|
+
If the type value is ``f``, ``c``, or ``i``, the corresponding ``lhs`` or ``rhs``
|
769
|
+
field widths are 128 bits each. In the case of floats, the literal value is encoded as a double
|
770
|
+
with 0 padding, while complex numbers are encoded as real part followed by imaginary part,
|
771
|
+
taking up 64 bits each. For ``i``, the value is encoded as a 64 bit signed integer with 0 padding
|
772
|
+
for the full 128 bit width. ``n`` is used to represent a ``None`` and typically isn't directly used
|
773
|
+
as it indicates an argument that's not used. For ``p`` the data is the UUID for the
|
774
|
+
:class:`.Parameter` which can be looked up in the symbol map described in the
|
775
|
+
``map_elements`` outer :ref:`qpy_param_expr_v3` payload. If the type value is
|
776
|
+
``s`` this marks the start of a a new recursive section for a nested
|
777
|
+
:class:`.ParameterExpression`. For example, in the following snippet there is an inner ``expr``
|
778
|
+
contained in ``final_expr``, constituting a nested expression::
|
779
|
+
|
780
|
+
from qiskit.circuit import Parameter
|
781
|
+
|
782
|
+
x = Parameter("x")
|
783
|
+
y = Parameter("y")
|
784
|
+
z = Parameter("z")
|
785
|
+
|
786
|
+
expr = (x + y) / 2
|
787
|
+
final_expr = z**2 + expr
|
788
|
+
|
789
|
+
When ``s`` is encountered, this indicates that until an ``e` struct is reached, the next structs
|
790
|
+
are used for a recursive definition. For both
|
791
|
+
``s`` and ``e`` types, the data values are not used, and always set to 0. The type value
|
792
|
+
of ``u`` is used to represent a substitution call. This is only used for ``lhs_type``
|
793
|
+
and is always paired with an ``rhs_type`` of ``n``. The data value is the size in bytes of
|
794
|
+
a :ref:`qpy_mapping` encoded mapping of :class:`.Parameter` names to their value for the
|
795
|
+
:meth:`~.ParameterExpression.subs` call. The mapping data is immediately following the
|
796
|
+
struct, and the next struct starts immediately after the mapping data.
|
797
|
+
|
798
|
+
.. _qpy_version_12:
|
799
|
+
|
800
|
+
Version 12
|
801
|
+
----------
|
802
|
+
|
803
|
+
Version 12 adds support for:
|
804
|
+
|
805
|
+
* circuits containing memory-owning :class:`.expr.Var` variables.
|
806
|
+
|
807
|
+
Changes to HEADER
|
808
|
+
~~~~~~~~~~~~~~~~~
|
809
|
+
|
810
|
+
The HEADER struct for an individual circuit has added three ``uint32_t`` counts of the input,
|
811
|
+
captured and locally declared variables in the circuit. The new form looks like:
|
812
|
+
|
813
|
+
.. code-block:: c
|
814
|
+
|
815
|
+
struct {
|
816
|
+
uint16_t name_size;
|
817
|
+
char global_phase_type;
|
818
|
+
uint16_t global_phase_size;
|
819
|
+
uint32_t num_qubits;
|
820
|
+
uint32_t num_clbits;
|
821
|
+
uint64_t metadata_size;
|
822
|
+
uint32_t num_registers;
|
823
|
+
uint64_t num_instructions;
|
824
|
+
uint32_t num_vars;
|
825
|
+
} HEADER_V12;
|
826
|
+
|
827
|
+
The ``HEADER_V12`` struct is followed immediately by the same name, global-phase, metadata
|
828
|
+
and register information as the V2 version of the header. Immediately following the registers is
|
829
|
+
``num_vars`` instances of ``EXPR_VAR_STANDALONE`` that define the variables in this circuit. After
|
830
|
+
that, the data continues with custom definitions and instructions as in prior versions of QPY.
|
831
|
+
|
832
|
+
|
833
|
+
EXPR_VAR_DECLARATION
|
834
|
+
~~~~~~~~~~~~~~~~~~~~
|
835
|
+
|
836
|
+
An ``EXPR_VAR_DECLARATION`` defines an :class:`.expr.Var` instance that is standalone; that is, it
|
837
|
+
represents a self-owned memory location rather than wrapping a :class:`.Clbit` or
|
838
|
+
:class:`.ClassicalRegister`. The payload is a C struct:
|
839
|
+
|
840
|
+
.. code-block:: c
|
841
|
+
|
842
|
+
struct {
|
843
|
+
char uuid_bytes[16];
|
844
|
+
char usage;
|
845
|
+
uint16_t name_size;
|
846
|
+
}
|
847
|
+
|
848
|
+
which is immediately followed by an ``EXPR_TYPE`` payload and then ``name_size`` bytes of UTF-8
|
849
|
+
encoding string data containing the name of the variable.
|
850
|
+
|
851
|
+
The ``char`` usage type code takes the following values:
|
852
|
+
|
853
|
+
========= =========================================================================================
|
854
|
+
Type code Meaning
|
855
|
+
========= =========================================================================================
|
856
|
+
``I`` An ``input`` variable to the circuit.
|
857
|
+
|
858
|
+
``C`` A ``capture`` variable to the circuit.
|
859
|
+
|
860
|
+
``L`` A locally declared variable to the circuit.
|
861
|
+
========= =========================================================================================
|
862
|
+
|
863
|
+
|
864
|
+
Changes to EXPR_VAR
|
865
|
+
~~~~~~~~~~~~~~~~~~~
|
866
|
+
|
867
|
+
The ``EXPR_VAR`` variable has gained a new type code and payload, in addition to the pre-existing ones:
|
868
|
+
|
869
|
+
=========================== ========= ============================================================
|
870
|
+
Python class Type code Payload
|
871
|
+
=========================== ========= ============================================================
|
872
|
+
:class:`.UUID` ``U`` One ``uint32_t`` index of the variable into the series of
|
873
|
+
``EXPR_VAR_STANDALONE`` variables that were written
|
874
|
+
immediately after the circuit header.
|
875
|
+
=========================== ========= ============================================================
|
876
|
+
|
877
|
+
Notably, this new type-code indexes into pre-defined variables from the circuit header, rather than
|
878
|
+
redefining the variable again in each location it is used.
|
879
|
+
|
880
|
+
|
881
|
+
Changes to EXPRESSION
|
882
|
+
---------------------
|
883
|
+
|
884
|
+
The EXPRESSION type code has a new possible entry, ``i``, corresponding to :class:`.expr.Index`
|
885
|
+
nodes.
|
886
|
+
|
887
|
+
====================== ========= ======================================================= ========
|
888
|
+
Qiskit class Type code Payload Children
|
889
|
+
====================== ========= ======================================================= ========
|
890
|
+
:class:`~.expr.Index` ``i`` No additional payload. The children are the target 2
|
891
|
+
and the index, in that order.
|
892
|
+
====================== ========= ======================================================= ========
|
893
|
+
|
894
|
+
|
895
|
+
.. _qpy_version_11:
|
896
|
+
|
897
|
+
Version 11
|
898
|
+
----------
|
899
|
+
|
900
|
+
Version 11 is identical to Version 10 except for the following.
|
901
|
+
First, the names in the CUSTOM_INSTRUCTION blocks
|
902
|
+
have a suffix of the form ``"_{uuid_hex}"`` where ``uuid_hex`` is a uuid
|
903
|
+
hexadecimal string such as returned by :attr:`.UUID.hex`. For example:
|
904
|
+
``"b3ecab5b4d6a4eb6bc2b2dbf18d83e1e"``.
|
905
|
+
Second, it adds support for :class:`.AnnotatedOperation`
|
906
|
+
objects. The base operation of an annotated operation is stored using the INSTRUCTION block,
|
907
|
+
and an additional ``type`` value ``'a'``is added to indicate that the custom instruction is an
|
908
|
+
annotated operation. The list of modifiers are stored as instruction parameters using INSTRUCTION_PARAM,
|
909
|
+
with an additional value ``'m'`` is added to indicate that the parameter is of type
|
910
|
+
:class:`~qiskit.circuit.annotated_operation.Modifier`. Each modifier is stored using the
|
911
|
+
MODIFIER struct.
|
912
|
+
|
913
|
+
.. _modifier_qpy:
|
914
|
+
|
915
|
+
MODIFIER
|
916
|
+
~~~~~~~~
|
917
|
+
|
918
|
+
This represents :class:`~qiskit.circuit.annotated_operation.Modifier`
|
919
|
+
|
920
|
+
.. code-block:: c
|
921
|
+
|
922
|
+
struct {
|
923
|
+
char type;
|
924
|
+
uint32_t num_ctrl_qubits;
|
925
|
+
uint32_t ctrl_state;
|
926
|
+
double power;
|
927
|
+
}
|
928
|
+
|
929
|
+
This is sufficient to store different types of modifiers required for serializing objects
|
930
|
+
of type :class:`.AnnotatedOperation`.
|
931
|
+
The field ``type`` is either ``'i'``, ``'c'`` or ``'p'``, representing whether the modifier
|
932
|
+
is respectively an inverse modifier, a control modifier or a power modifier. In the second
|
933
|
+
case, the fields ``num_ctrl_qubits`` and ``ctrl_state`` specify the control logic of the base
|
934
|
+
operation, and in the third case the field ``power`` represents the power of the base operation.
|
935
|
+
|
936
|
+
.. _qpy_version_10:
|
937
|
+
|
938
|
+
Version 10
|
939
|
+
----------
|
940
|
+
|
941
|
+
Version 10 adds support for:
|
942
|
+
|
943
|
+
* symengine-native serialization for objects of type :class:`~.ParameterExpression` as well as
|
944
|
+
symbolic expressions in Pulse schedule blocks.
|
945
|
+
* new fields in the :class:`~.TranspileLayout` class added in the Qiskit 0.45.0 release.
|
946
|
+
|
947
|
+
The symbolic_encoding field is added to the file header, and a new encoding type char
|
948
|
+
is introduced, mapped to each symbolic library as follows: ``p`` refers to sympy
|
949
|
+
encoding and ``e`` refers to symengine encoding.
|
950
|
+
|
951
|
+
Changes to FILE_HEADER
|
952
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
953
|
+
|
954
|
+
The contents of FILE_HEADER after V10 are defined as a C struct as:
|
955
|
+
|
956
|
+
.. code-block:: c
|
957
|
+
|
958
|
+
struct {
|
959
|
+
uint8_t qpy_version;
|
960
|
+
uint8_t qiskit_major_version;
|
961
|
+
uint8_t qiskit_minor_version;
|
962
|
+
uint8_t qiskit_patch_version;
|
963
|
+
uint64_t num_circuits;
|
964
|
+
char symbolic_encoding;
|
965
|
+
} FILE_HEADER_V10;
|
966
|
+
|
967
|
+
Changes to LAYOUT
|
968
|
+
~~~~~~~~~~~~~~~~~
|
969
|
+
|
970
|
+
The ``LAYOUT`` struct is updated to have an additional ``input_qubit_count`` field.
|
971
|
+
With version 10 the ``LAYOUT`` struct is now:
|
972
|
+
|
973
|
+
.. code-block:: c
|
974
|
+
|
975
|
+
struct {
|
976
|
+
char exists;
|
977
|
+
int32_t initial_layout_size;
|
978
|
+
int32_t input_mapping_size;
|
979
|
+
int32_t final_layout_size;
|
980
|
+
uint32_t extra_registers;
|
981
|
+
int32_t input_qubit_count;
|
982
|
+
}
|
983
|
+
|
984
|
+
The rest of the layout data after the ``LAYOUT`` struct is represented as in previous versions. If
|
985
|
+
``input qubit_count`` is < 0 that indicates that both ``_input_qubit_count``
|
986
|
+
and ``_output_qubit_list`` in the :class:`~.TranspileLayout` object are ``None``.
|
987
|
+
|
988
|
+
.. _qpy_version_9:
|
989
|
+
|
990
|
+
Version 9
|
991
|
+
---------
|
992
|
+
|
993
|
+
Version 9 adds support for classical :class:`~.expr.Expr` nodes and their associated
|
994
|
+
:class:`~.types.Type`\\ s.
|
995
|
+
|
996
|
+
|
997
|
+
EXPRESSION
|
998
|
+
~~~~~~~~~~
|
999
|
+
|
1000
|
+
An :class:`~.expr.Expr` node is represented by a stream of variable-width data. A node itself is
|
1001
|
+
represented by (in order in the byte stream):
|
1002
|
+
|
1003
|
+
#. a one-byte type code discriminator;
|
1004
|
+
#. an EXPR_TYPE object;
|
1005
|
+
#. a type-code-specific additional payload;
|
1006
|
+
#. a type-code-specific number of child EXPRESSION payloads (the number of these is implied by the
|
1007
|
+
type code and not explicitly stored).
|
1008
|
+
|
1009
|
+
Each of these are described in the following table:
|
1010
|
+
|
1011
|
+
====================== ========= ======================================================= ========
|
1012
|
+
Qiskit class Type code Payload Children
|
1013
|
+
====================== ========= ======================================================= ========
|
1014
|
+
:class:`~.expr.Var` ``x`` One ``EXPR_VAR``. 0
|
1015
|
+
|
1016
|
+
:class:`~.expr.Value` ``v`` One ``EXPR_VALUE``. 0
|
1017
|
+
|
1018
|
+
:class:`~.expr.Cast` ``c`` One ``_Bool`` that corresponds to the value of 1
|
1019
|
+
``implicit``.
|
1020
|
+
|
1021
|
+
:class:`~.expr.Unary` ``u`` One ``uint8_t`` with the same numeric value as the 1
|
1022
|
+
:class:`.Unary.Op`.
|
1023
|
+
|
1024
|
+
:class:`~.expr.Binary` ``b`` One ``uint8_t`` with the same numeric value as the 2
|
1025
|
+
:class:`.Binary.Op`.
|
1026
|
+
====================== ========= ======================================================= ========
|
1027
|
+
|
1028
|
+
|
1029
|
+
EXPR_TYPE
|
1030
|
+
~~~~~~~~~
|
1031
|
+
|
1032
|
+
A :class:`~.types.Type` is encoded by a single-byte ASCII ``char`` that encodes the kind of type,
|
1033
|
+
followed by a payload that varies depending on the type. The defined codes are:
|
1034
|
+
|
1035
|
+
====================== ========= =================================================================
|
1036
|
+
Qiskit class Type code Payload
|
1037
|
+
====================== ========= =================================================================
|
1038
|
+
:class:`~.types.Bool` ``b`` None.
|
1039
|
+
|
1040
|
+
:class:`~.types.Uint` ``u`` One ``uint32_t width``.
|
1041
|
+
====================== ========= =================================================================
|
1042
|
+
|
1043
|
+
|
1044
|
+
EXPR_VAR
|
1045
|
+
~~~~~~~~
|
1046
|
+
|
1047
|
+
This represents a runtime variable of a :class:`~.expr.Var` node. These are a type code, followed
|
1048
|
+
by a type-code-specific payload:
|
1049
|
+
|
1050
|
+
=========================== ========= ============================================================
|
1051
|
+
Python class Type code Payload
|
1052
|
+
=========================== ========= ============================================================
|
1053
|
+
:class:`.Clbit` ``C`` One ``uint32_t index`` that is the index of the
|
1054
|
+
:class:`.Clbit` in the containing circuit.
|
1055
|
+
|
1056
|
+
:class:`.ClassicalRegister` ``R`` One ``uint16_t reg_name_size``, followed by that many bytes
|
1057
|
+
of UTF-8 string data of the register name.
|
1058
|
+
=========================== ========= ============================================================
|
1059
|
+
|
1060
|
+
|
1061
|
+
EXPR_VALUE
|
1062
|
+
~~~~~~~~~~
|
1063
|
+
|
1064
|
+
This represents a literal object in the classical type system, such as an integer. Currently there
|
1065
|
+
are very few such literals. These are encoded as a type code, followed by a type-code-specific
|
1066
|
+
payload.
|
1067
|
+
|
1068
|
+
=========== ========= ============================================================================
|
1069
|
+
Python type Type code Payload
|
1070
|
+
=========== ========= ============================================================================
|
1071
|
+
``bool`` ``b`` One ``_Bool value``.
|
1072
|
+
|
1073
|
+
``int`` ``i`` One ``uint8_t num_bytes``, followed by the integer encoded into that many
|
1074
|
+
many bytes (network order) in a two's complement representation.
|
1075
|
+
=========== ========= ============================================================================
|
1076
|
+
|
1077
|
+
|
1078
|
+
.. _qpy_instruction_v9:
|
1079
|
+
|
1080
|
+
Changes to INSTRUCTION
|
1081
|
+
~~~~~~~~~~~~~~~~~~~~~~
|
1082
|
+
|
1083
|
+
To support the use of :class:`~.expr.Expr` nodes in the fields :attr:`.IfElseOp.condition`,
|
1084
|
+
:attr:`.WhileLoopOp.condition` and :attr:`.SwitchCaseOp.target`, the INSTRUCTION struct is changed
|
1085
|
+
in an ABI compatible-manner to :ref:`its previous definition <qpy_instruction_v5>`. The new struct
|
1086
|
+
is the C struct:
|
1087
|
+
|
1088
|
+
.. code-block:: c
|
1089
|
+
|
1090
|
+
struct {
|
1091
|
+
uint16_t name_size;
|
1092
|
+
uint16_t label_size;
|
1093
|
+
uint16_t num_parameters;
|
1094
|
+
uint32_t num_qargs;
|
1095
|
+
uint32_t num_cargs;
|
1096
|
+
uint8_t conditional_key;
|
1097
|
+
uint16_t conditional_reg_name_size;
|
1098
|
+
int64_t conditional_value;
|
1099
|
+
uint32_t num_ctrl_qubits;
|
1100
|
+
uint32_t ctrl_state;
|
1101
|
+
}
|
1102
|
+
|
1103
|
+
where the only change is that a ``uint8_t conditional_key`` entry has replaced ``_Bool
|
1104
|
+
has_conditional``. This new ``conditional_key`` takes the following numeric values, with these
|
1105
|
+
effects:
|
1106
|
+
|
1107
|
+
===== =============================================================================================
|
1108
|
+
Value Effects
|
1109
|
+
===== =============================================================================================
|
1110
|
+
0 The instruction has its ``.condition`` field set to ``None``. The
|
1111
|
+
``conditional_reg_name_size`` and ``conditional_value`` fields should be ignored.
|
1112
|
+
|
1113
|
+
1 The instruction has its ``.condition`` field set to a 2-tuple of either a :class:`.Clbit`
|
1114
|
+
or a :class:`.ClassicalRegister`, and a integer of value ``conditional_value``. The
|
1115
|
+
INSTRUCTION payload, including its trailing data is parsed exactly as it would be in QPY
|
1116
|
+
versions less than 8.
|
1117
|
+
|
1118
|
+
2 The instruction has its ``.condition`` field set to a :class:`~.expr.Expr` node. The
|
1119
|
+
``conditional_reg_name_size`` and ``conditional_value`` fields should be ignored. The data
|
1120
|
+
following the struct is followed (as in QPY versions less than 9) by ``name_size`` bytes of
|
1121
|
+
UTF-8 string data for the class name and ``label_size`` bytes of UTF-8 string data for the
|
1122
|
+
label (if any). Then, there is one INSTRUCTION_PARAM, which will contain an EXPRESSION. After
|
1123
|
+
that, parsing continues with the INSTRUCTION_ARG structs, as in previous versions of QPY.
|
1124
|
+
===== =============================================================================================
|
1125
|
+
|
1126
|
+
|
1127
|
+
Changes to INSTRUCTION_PARAM
|
1128
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1129
|
+
|
1130
|
+
A new type code ``x`` is added that defines an EXPRESSION parameter.
|
1131
|
+
|
1132
|
+
|
1133
|
+
.. _qpy_version_8:
|
1134
|
+
|
1135
|
+
Version 8
|
1136
|
+
---------
|
1137
|
+
|
1138
|
+
Version 8 adds support for handling a :class:`~.TranspileLayout` stored in the
|
1139
|
+
:attr:`.QuantumCircuit.layout` attribute. In version 8 immediately following the
|
1140
|
+
calibrations block at the end of the circuit payload there is now the
|
1141
|
+
``LAYOUT`` struct. This struct outlines the size of the three attributes of a
|
1142
|
+
:class:`~.TranspileLayout` class.
|
1143
|
+
|
1144
|
+
LAYOUT
|
1145
|
+
~~~~~~
|
1146
|
+
|
1147
|
+
.. code-block:: c
|
1148
|
+
|
1149
|
+
struct {
|
1150
|
+
char exists;
|
1151
|
+
int32_t initial_layout_size;
|
1152
|
+
int32_t input_mapping_size;
|
1153
|
+
int32_t final_layout_size;
|
1154
|
+
uint32_t extra_registers;
|
1155
|
+
}
|
1156
|
+
|
1157
|
+
If any of the signed values are ``-1`` this indicates the corresponding
|
1158
|
+
attribute is ``None``.
|
1159
|
+
|
1160
|
+
Immediately following the ``LAYOUT`` struct there is a :ref:`qpy_registers` struct
|
1161
|
+
for ``extra_registers`` (specifically the format introduced in :ref:`qpy_version_4`)
|
1162
|
+
standalone register definitions that aren't present in the circuit. Then there
|
1163
|
+
are ``initial_layout_size`` ``INITIAL_LAYOUT_BIT`` structs to define the
|
1164
|
+
:attr:`.TranspileLayout.initial_layout` attribute.
|
1165
|
+
|
1166
|
+
INITIAL_LAYOUT_BIT
|
1167
|
+
~~~~~~~~~~~~~~~~~~
|
1168
|
+
|
1169
|
+
.. code-block:: c
|
1170
|
+
|
1171
|
+
struct {
|
1172
|
+
int32_t index;
|
1173
|
+
int32_t register_size;
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
Where a value of ``-1`` indicates ``None`` (as in no register is associated
|
1177
|
+
with the bit). Following each ``INITIAL_LAYOUT_BIT`` struct is ``register_size``
|
1178
|
+
bytes for a ``utf8`` encoded string for the register name.
|
1179
|
+
|
1180
|
+
Following the initial layout there is ``input_mapping_size`` array of
|
1181
|
+
``uint32_t`` integers representing the positions of the physical bit from the
|
1182
|
+
initial layout. This enables constructing a list of virtual bits where the
|
1183
|
+
array index is its input mapping position.
|
1184
|
+
|
1185
|
+
Finally, there is an array of ``final_layout_size`` ``uint32_t`` integers. Each
|
1186
|
+
element is an index in the circuit's ``qubits`` attribute which enables building
|
1187
|
+
a mapping from qubit starting position to the output position at the end of the
|
1188
|
+
circuit.
|
1189
|
+
|
1190
|
+
.. _qpy_version_7:
|
1191
|
+
|
1192
|
+
Version 7
|
1193
|
+
---------
|
1194
|
+
|
1195
|
+
Version 7 adds support for :class:`.~Reference` instruction and serialization of
|
1196
|
+
a ``ScheduleBlock`` program while keeping its reference to subroutines::
|
1197
|
+
|
1198
|
+
from qiskit import pulse
|
1199
|
+
from qiskit import qpy
|
1200
|
+
|
1201
|
+
with pulse.build() as schedule:
|
1202
|
+
pulse.reference("cr45p", "q0", "q1")
|
1203
|
+
pulse.reference("x", "q0")
|
1204
|
+
pulse.reference("cr45p", "q0", "q1")
|
1205
|
+
|
1206
|
+
with open('template_ecr.qpy', 'wb') as fd:
|
1207
|
+
qpy.dump(schedule, fd)
|
1208
|
+
|
1209
|
+
The conventional :ref:`qpy_schedule_block` data model is preserved, but in
|
1210
|
+
version 7 it is immediately followed by an extra :ref:`qpy_mapping` utf8 bytes block
|
1211
|
+
representing the data of the referenced subroutines.
|
1212
|
+
|
1213
|
+
New type key character is added to the :ref:`qpy_schedule_instructions` group
|
1214
|
+
for the :class:`.~Reference` instruction.
|
1215
|
+
|
1216
|
+
- ``y``: :class:`~qiskit.pulse.instructions.Reference` instruction
|
1217
|
+
|
1218
|
+
New type key character is added to the :ref:`qpy_schedule_operands` group
|
1219
|
+
for the operands of :class:`.~Reference` instruction,
|
1220
|
+
which is a tuple of strings, e.g. ("cr45p", "q0", "q1").
|
1221
|
+
|
1222
|
+
- ``o``: string (operand string)
|
1223
|
+
|
1224
|
+
Note that this is the same encoding with the built-in Python string, however,
|
1225
|
+
the standard value encoding in QPY uses ``s`` type character for string data,
|
1226
|
+
which conflicts with the :class:`~qiskit.pulse.library.SymbolicPulse` in the scope of
|
1227
|
+
pulse instruction operands. A special type character ``o`` is reserved for
|
1228
|
+
the string data that appears in the pulse instruction operands.
|
1229
|
+
|
1230
|
+
In addition, version 7 adds two new type keys to the INSTRUCTION_PARM struct. ``"d"`` is followed
|
1231
|
+
by no data and represents the literal value :data:`.CASE_DEFAULT` for switch-statement support.
|
1232
|
+
``"R"`` represents a :class:`.ClassicalRegister` or :class:`.Clbit`, and is followed by the same
|
1233
|
+
format as the description of register or classical bit as used in the first element of :ref:`the
|
1234
|
+
condition of an INSTRUCTION field <qpy_instructions>`.
|
1235
|
+
|
1236
|
+
.. _qpy_version_6:
|
1237
|
+
|
1238
|
+
Version 6
|
1239
|
+
---------
|
1240
|
+
|
1241
|
+
Version 6 adds support for :class:`.~ScalableSymbolicPulse`. These objects are saved and read
|
1242
|
+
like `SymbolicPulse` objects, and the class name is added to the data to correctly handle
|
1243
|
+
the class selection.
|
1244
|
+
|
1245
|
+
`SymbolicPulse` block now starts with SYMBOLIC_PULSE_V2 header:
|
1246
|
+
|
1247
|
+
.. code-block:: c
|
1248
|
+
|
1249
|
+
struct {
|
1250
|
+
uint16_t class_name_size;
|
1251
|
+
uint16_t type_size;
|
1252
|
+
uint16_t envelope_size;
|
1253
|
+
uint16_t constraints_size;
|
1254
|
+
uint16_t valid_amp_conditions_size;
|
1255
|
+
_bool amp_limited;
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
The only change compared to :ref:`qpy_version_5` is the addition of `class_name_size`. The header
|
1259
|
+
is then immediately followed by ``class_name_size`` utf8 bytes with the name of the class. Currently,
|
1260
|
+
either `SymbolicPulse` or `ScalableSymbolicPulse` are supported. The rest of the data is then
|
1261
|
+
identical to :ref:`qpy_version_5`.
|
1262
|
+
|
1263
|
+
.. _qpy_version_5:
|
1264
|
+
|
1265
|
+
Version 5
|
1266
|
+
---------
|
1267
|
+
|
1268
|
+
Version 5 changes from :ref:`qpy_version_4` by adding support for ``ScheduleBlock``
|
1269
|
+
and changing two payloads the INSTRUCTION metadata payload and the CUSTOM_INSTRUCTION block.
|
1270
|
+
These now have new fields to better account for :class:`~.ControlledGate` objects in a circuit.
|
1271
|
+
In addition, new payload MAP_ITEM is defined to implement the :ref:`qpy_mapping` block.
|
1272
|
+
|
1273
|
+
With the support of ``ScheduleBlock``, now :class:`~.QuantumCircuit` can be
|
1274
|
+
serialized together with :attr:`~.QuantumCircuit.calibrations`, or
|
1275
|
+
`Pulse Gates <https://quantum.cloud.ibm.com/docs/guides/pulse>`_.
|
1276
|
+
In QPY version 5 and above, :ref:`qpy_circuit_calibrations` payload is
|
1277
|
+
packed after the :ref:`qpy_instructions` block.
|
1278
|
+
|
1279
|
+
In QPY version 5 and above,
|
1280
|
+
|
1281
|
+
.. code-block:: c
|
1282
|
+
|
1283
|
+
struct {
|
1284
|
+
char type;
|
1285
|
+
}
|
1286
|
+
|
1287
|
+
immediately follows the file header block to represent the program type stored in the file.
|
1288
|
+
|
1289
|
+
- When ``type==c``, :class:`~.QuantumCircuit` payload follows
|
1290
|
+
- When ``type==s``, ``ScheduleBlock`` payload follows
|
1291
|
+
|
1292
|
+
.. note::
|
1293
|
+
|
1294
|
+
Different programs cannot be packed together in the same file.
|
1295
|
+
You must create different files for different program types.
|
1296
|
+
Multiple objects with the same type can be saved in a single file.
|
1297
|
+
|
1298
|
+
.. _qpy_schedule_block:
|
1299
|
+
|
1300
|
+
SCHEDULE_BLOCK
|
1301
|
+
~~~~~~~~~~~~~~
|
1302
|
+
|
1303
|
+
``ScheduleBlock`` is first supported in QPY Version 5. This allows
|
1304
|
+
users to save pulse programs in the QPY binary format as follows:
|
1305
|
+
|
1306
|
+
.. code-block:: python
|
1307
|
+
|
1308
|
+
from qiskit import pulse, qpy
|
1309
|
+
|
1310
|
+
with pulse.build() as schedule:
|
1311
|
+
pulse.play(pulse.Gaussian(160, 0.1, 40), pulse.DriveChannel(0))
|
1312
|
+
|
1313
|
+
with open('schedule.qpy', 'wb') as fd:
|
1314
|
+
qpy.dump(schedule, fd)
|
1315
|
+
|
1316
|
+
with open('schedule.qpy', 'rb') as fd:
|
1317
|
+
new_schedule = qpy.load(fd)[0]
|
1318
|
+
|
1319
|
+
Note that circuit and schedule block are serialized and deserialized through
|
1320
|
+
the same QPY interface. Input data type is implicitly analyzed and
|
1321
|
+
no extra option is required to save the schedule block.
|
1322
|
+
|
1323
|
+
.. _qpy_schedule_block_header:
|
1324
|
+
|
1325
|
+
SCHEDULE_BLOCK_HEADER
|
1326
|
+
~~~~~~~~~~~~~~~~~~~~~
|
1327
|
+
|
1328
|
+
``ScheduleBlock`` block starts with the following header:
|
1329
|
+
|
1330
|
+
.. code-block:: c
|
1331
|
+
|
1332
|
+
struct {
|
1333
|
+
uint16_t name_size;
|
1334
|
+
uint64_t metadata_size;
|
1335
|
+
uint16_t num_element;
|
1336
|
+
}
|
1337
|
+
|
1338
|
+
which is immediately followed by ``name_size`` utf8 bytes of schedule name and
|
1339
|
+
``metadata_size`` utf8 bytes of the JSON serialized metadata dictionary
|
1340
|
+
attached to the schedule.
|
1341
|
+
|
1342
|
+
.. _qpy_schedule_alignments:
|
1343
|
+
|
1344
|
+
SCHEDULE_BLOCK_ALIGNMENTS
|
1345
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
1346
|
+
|
1347
|
+
Then, alignment context of the schedule block starts with ``char``
|
1348
|
+
representing the supported context type followed by the :ref:`qpy_sequence` block representing
|
1349
|
+
the parameters associated with the alignment context :attr:`AlignmentKind._context_params`.
|
1350
|
+
The context type char is mapped to each alignment subclass as follows:
|
1351
|
+
|
1352
|
+
- ``l``: :class:`~.AlignLeft`
|
1353
|
+
- ``r``: :class:`~.AlignRight`
|
1354
|
+
- ``s``: :class:`~.AlignSequential`
|
1355
|
+
- ``e``: :class:`~.AlignEquispaced`
|
1356
|
+
|
1357
|
+
Note that :class:`~.AlignFunc` context is not supported because of the callback function
|
1358
|
+
stored in the context parameters.
|
1359
|
+
|
1360
|
+
.. _qpy_schedule_instructions:
|
1361
|
+
|
1362
|
+
SCHEDULE_BLOCK_INSTRUCTIONS
|
1363
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1364
|
+
|
1365
|
+
This alignment block is further followed by ``num_element`` length of block elements which may
|
1366
|
+
consist of nested schedule blocks and schedule instructions.
|
1367
|
+
Each schedule instruction starts with ``char`` representing the instruction type
|
1368
|
+
followed by the :ref:`qpy_sequence` block representing the instruction
|
1369
|
+
:attr:`~qiskit.pulse.instructions.Instruction.operands`.
|
1370
|
+
Note that the data structure of pulse :class:`~qiskit.pulse.instructions.Instruction`
|
1371
|
+
is unified so that instance can be uniquely determined by the class and a tuple of operands.
|
1372
|
+
The mapping of type char to the instruction subclass is defined as follows:
|
1373
|
+
|
1374
|
+
- ``a``: :class:`~qiskit.pulse.instructions.Acquire` instruction
|
1375
|
+
- ``p``: :class:`~qiskit.pulse.instructions.Play` instruction
|
1376
|
+
- ``d``: :class:`~qiskit.pulse.instructions.Delay` instruction
|
1377
|
+
- ``f``: :class:`~qiskit.pulse.instructions.SetFrequency` instruction
|
1378
|
+
- ``g``: :class:`~qiskit.pulse.instructions.ShiftFrequency` instruction
|
1379
|
+
- ``q``: :class:`~qiskit.pulse.instructions.SetPhase` instruction
|
1380
|
+
- ``r``: :class:`~qiskit.pulse.instructions.ShiftPhase` instruction
|
1381
|
+
- ``b``: :class:`~qiskit.pulse.instructions.RelativeBarrier` instruction
|
1382
|
+
- ``t``: :class:`~qiskit.pulse.instructions.TimeBlockade` instruction
|
1383
|
+
- ``y``: :class:`~qiskit.pulse.instructions.Reference` instruction (new in version 0.7)
|
1384
|
+
|
1385
|
+
.. _qpy_schedule_operands:
|
1386
|
+
|
1387
|
+
SCHEDULE_BLOCK_OPERANDS
|
1388
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
1389
|
+
|
1390
|
+
The operands of these instances can be serialized through the standard QPY value serialization
|
1391
|
+
mechanism, however there are special object types that only appear in the schedule operands.
|
1392
|
+
Since the operands are serialized as :ref:`qpy_sequence`, each element must be packed with the
|
1393
|
+
INSTRUCTION_PARAM pack struct, where each payload starts with a header block consists of
|
1394
|
+
the char ``type`` and uint64_t ``size``.
|
1395
|
+
Special objects start with the following type key:
|
1396
|
+
|
1397
|
+
- ``c``: :class:`~qiskit.pulse.channels.Channel`
|
1398
|
+
- ``w``: :class:`~qiskit.pulse.library.Waveform`
|
1399
|
+
- ``s``: :class:`~qiskit.pulse.library.SymbolicPulse`
|
1400
|
+
- ``o``: string (operand string, new in version 0.7)
|
1401
|
+
|
1402
|
+
.. _qpy_schedule_channel:
|
1403
|
+
|
1404
|
+
CHANNEL
|
1405
|
+
~~~~~~~
|
1406
|
+
|
1407
|
+
Channel block starts with channel subtype ``char`` that maps an object data to
|
1408
|
+
:class:`~qiskit.pulse.channels.Channel` subclass. Mapping is defined as follows:
|
1409
|
+
|
1410
|
+
- ``d``: :class:`~qiskit.pulse.channels.DriveChannel`
|
1411
|
+
- ``c``: :class:`~qiskit.pulse.channels.ControlChannel`
|
1412
|
+
- ``m``: :class:`~qiskit.pulse.channels.MeasureChannel`
|
1413
|
+
- ``a``: :class:`~qiskit.pulse.channels.AcquireChannel`
|
1414
|
+
- ``e``: :class:`~qiskit.pulse.channels.MemorySlot`
|
1415
|
+
- ``r``: :class:`~qiskit.pulse.channels.RegisterSlot`
|
1416
|
+
|
1417
|
+
The key is immediately followed by the channel index serialized as the INSTRUCTION_PARAM.
|
1418
|
+
|
1419
|
+
.. _qpy_schedule_waveform:
|
1420
|
+
|
1421
|
+
Waveform
|
1422
|
+
~~~~~~~~
|
1423
|
+
|
1424
|
+
Waveform block starts with WAVEFORM header:
|
1425
|
+
|
1426
|
+
.. code-block:: c
|
1427
|
+
|
1428
|
+
struct {
|
1429
|
+
double epsilon;
|
1430
|
+
uint32_t data_size;
|
1431
|
+
_bool amp_limited;
|
1432
|
+
}
|
1433
|
+
|
1434
|
+
which is followed by ``data_size`` bytes of complex ``ndarray`` binary generated by numpy.save_.
|
1435
|
+
This represents the complex IQ data points played on a quantum device.
|
1436
|
+
:attr:`~qiskit.pulse.library.Waveform.name` is saved after the samples in the
|
1437
|
+
INSTRUCTION_PARAM pack struct, which can be string or ``None``.
|
1438
|
+
|
1439
|
+
.. _numpy.save: https://numpy.org/doc/stable/reference/generated/numpy.save.html
|
1440
|
+
|
1441
|
+
.. _qpy_schedule_symbolic_pulse:
|
1442
|
+
|
1443
|
+
SymbolicPulse
|
1444
|
+
~~~~~~~~~~~~~
|
1445
|
+
|
1446
|
+
SymbolicPulse block starts with SYMBOLIC_PULSE header:
|
1447
|
+
|
1448
|
+
.. code-block:: c
|
1449
|
+
|
1450
|
+
struct {
|
1451
|
+
uint16_t type_size;
|
1452
|
+
uint16_t envelope_size;
|
1453
|
+
uint16_t constraints_size;
|
1454
|
+
uint16_t valid_amp_conditions_size;
|
1455
|
+
_bool amp_limited;
|
1456
|
+
}
|
1457
|
+
|
1458
|
+
which is followed by ``type_size`` utf8 bytes of :attr:`.SymbolicPulse.pulse_type` string
|
1459
|
+
that represents a class of waveform, such as "Gaussian" or "GaussianSquare".
|
1460
|
+
Then, ``envelope_size``, ``constraints_size``, ``valid_amp_conditions_size`` utf8 bytes of
|
1461
|
+
serialized symbolic expressions are generated for :attr:`.SymbolicPulse.envelope`,
|
1462
|
+
:attr:`.SymbolicPulse.constraints`, and :attr:`.SymbolicPulse.valid_amp_conditions`, respectively.
|
1463
|
+
Since string representation of these expressions are usually lengthy,
|
1464
|
+
the expression binary is generated by the python zlib_ module with data compression.
|
1465
|
+
|
1466
|
+
To uniquely specify a pulse instance, we also need to store the associated parameters,
|
1467
|
+
which consist of ``duration`` and the rest of parameters as a dictionary.
|
1468
|
+
Dictionary parameters are first dumped in the :ref:`qpy_mapping` form, and then ``duration``
|
1469
|
+
is dumped with the INSTRUCTION_PARAM pack struct.
|
1470
|
+
Lastly, :attr:`~qiskit.pulse.library.SymbolicPulse.name` is saved also with the
|
1471
|
+
INSTRUCTION_PARAM pack struct, which can be string or ``None``.
|
1472
|
+
|
1473
|
+
.. _zlib: https://docs.python.org/3/library/zlib.html
|
1474
|
+
|
1475
|
+
.. _qpy_mapping:
|
1476
|
+
|
1477
|
+
MAPPING
|
1478
|
+
~~~~~~~
|
1479
|
+
|
1480
|
+
The MAPPING is a representation for arbitrary mapping object. This is a fixed length
|
1481
|
+
:ref:`qpy_sequence` of key-value pair represented by the MAP_ITEM payload.
|
1482
|
+
|
1483
|
+
A MAP_ITEM starts with a header defined as:
|
1484
|
+
|
1485
|
+
.. code-block:: c
|
1486
|
+
|
1487
|
+
struct {
|
1488
|
+
uint16_t key_size;
|
1489
|
+
char type;
|
1490
|
+
uint16_t size;
|
1491
|
+
}
|
1492
|
+
|
1493
|
+
which is immediately followed by the ``key_size`` utf8 bytes representing
|
1494
|
+
the dictionary key in string and ``size`` utf8 bytes of arbitrary object data of
|
1495
|
+
QPY serializable ``type``.
|
1496
|
+
|
1497
|
+
.. _qpy_circuit_calibrations:
|
1498
|
+
|
1499
|
+
CIRCUIT_CALIBRATIONS
|
1500
|
+
~~~~~~~~~~~~~~~~~~~~
|
1501
|
+
|
1502
|
+
The CIRCUIT_CALIBRATIONS block is a dictionary to define pulse calibrations of the custom
|
1503
|
+
instruction set. This block starts with the following CALIBRATION header:
|
1504
|
+
|
1505
|
+
.. code-block:: c
|
1506
|
+
|
1507
|
+
struct {
|
1508
|
+
uint16_t num_cals;
|
1509
|
+
}
|
1510
|
+
|
1511
|
+
which is followed by the ``num_cals`` length of calibration entries, each starts with
|
1512
|
+
the CALIBRATION_DEF header:
|
1513
|
+
|
1514
|
+
.. code-block:: c
|
1515
|
+
|
1516
|
+
struct {
|
1517
|
+
uint16_t name_size;
|
1518
|
+
uint16_t num_qubits;
|
1519
|
+
uint16_t num_params;
|
1520
|
+
char type;
|
1521
|
+
}
|
1522
|
+
|
1523
|
+
The calibration definition header is then followed by ``name_size`` utf8 bytes of
|
1524
|
+
the gate name, ``num_qubits`` length of integers representing a sequence of qubits,
|
1525
|
+
and ``num_params`` length of INSTRUCTION_PARAM payload for parameters
|
1526
|
+
associated to the custom instruction.
|
1527
|
+
The ``type`` indicates the class of pulse program which is either, in principle,
|
1528
|
+
``ScheduleBlock`` or :class:`~.Schedule`. As of QPY Version 5,
|
1529
|
+
only ``ScheduleBlock`` payload is supported.
|
1530
|
+
Finally, :ref:`qpy_schedule_block` payload is packed for each CALIBRATION_DEF entry.
|
1531
|
+
|
1532
|
+
.. _qpy_instruction_v5:
|
1533
|
+
|
1534
|
+
INSTRUCTION
|
1535
|
+
~~~~~~~~~~~
|
1536
|
+
|
1537
|
+
The INSTRUCTION block was modified to add two new fields ``num_ctrl_qubits`` and ``ctrl_state``
|
1538
|
+
which are used to model the :attr:`.ControlledGate.num_ctrl_qubits` and
|
1539
|
+
:attr:`.ControlledGate.ctrl_state` attributes. The new payload packed struct
|
1540
|
+
format is:
|
1541
|
+
|
1542
|
+
.. code-block:: c
|
1543
|
+
|
1544
|
+
struct {
|
1545
|
+
uint16_t name_size;
|
1546
|
+
uint16_t label_size;
|
1547
|
+
uint16_t num_parameters;
|
1548
|
+
uint32_t num_qargs;
|
1549
|
+
uint32_t num_cargs;
|
1550
|
+
_Bool has_conditional;
|
1551
|
+
uint16_t conditional_reg_name_size;
|
1552
|
+
int64_t conditional_value;
|
1553
|
+
uint32_t num_ctrl_qubits;
|
1554
|
+
uint32_t ctrl_state;
|
1555
|
+
}
|
1556
|
+
|
1557
|
+
The rest of the instruction payload is the same. You can refer to
|
1558
|
+
:ref:`qpy_instructions` for the details of the full payload.
|
1559
|
+
|
1560
|
+
CUSTOM_INSTRUCTION
|
1561
|
+
~~~~~~~~~~~~~~~~~~
|
1562
|
+
|
1563
|
+
The CUSTOM_INSTRUCTION block in QPY version 5 adds a new field
|
1564
|
+
``base_gate_size`` which is used to define the size of the
|
1565
|
+
:class:`qiskit.circuit.Instruction` object stored in the
|
1566
|
+
:attr:`.ControlledGate.base_gate` attribute for a custom
|
1567
|
+
:class:`~.ControlledGate` object. With this change the CUSTOM_INSTRUCTION
|
1568
|
+
metadata block becomes:
|
1569
|
+
|
1570
|
+
.. code-block:: c
|
1571
|
+
|
1572
|
+
struct {
|
1573
|
+
uint16_t name_size;
|
1574
|
+
char type;
|
1575
|
+
uint32_t num_qubits;
|
1576
|
+
uint32_t num_clbits;
|
1577
|
+
_Bool custom_definition;
|
1578
|
+
uint64_t size;
|
1579
|
+
uint32_t num_ctrl_qubits;
|
1580
|
+
uint32_t ctrl_state;
|
1581
|
+
uint64_t base_gate_size
|
1582
|
+
}
|
1583
|
+
|
1584
|
+
Immediately following the CUSTOM_INSTRUCTION struct is the utf8 encoded name
|
1585
|
+
of size ``name_size``.
|
1586
|
+
|
1587
|
+
If ``custom_definition`` is ``True`` that means that the immediately following
|
1588
|
+
``size`` bytes contains a QPY circuit data which can be used for the custom
|
1589
|
+
definition of that gate. If ``custom_definition`` is ``False`` then the
|
1590
|
+
instruction can be considered opaque (ie no definition). The ``type`` field
|
1591
|
+
determines what type of object will get created with the custom definition.
|
1592
|
+
If it's ``'g'`` it will be a :class:`~qiskit.circuit.Gate` object, ``'i'``
|
1593
|
+
it will be a :class:`~qiskit.circuit.Instruction` object.
|
1594
|
+
|
1595
|
+
Following this the next ``base_gate_size`` bytes contain the ``INSTRUCTION``
|
1596
|
+
payload for the :attr:`.ControlledGate.base_gate`.
|
1597
|
+
|
1598
|
+
Additionally an addition value for ``type`` is added ``'c'`` which is used to
|
1599
|
+
indicate the custom instruction is a custom :class:`~.ControlledGate`.
|
1600
|
+
|
1601
|
+
.. _qpy_version_4:
|
1602
|
+
|
1603
|
+
Version 4
|
1604
|
+
---------
|
1605
|
+
|
1606
|
+
Version 4 is identical to :ref:`qpy_version_3` except that it adds 2 new type strings
|
1607
|
+
to the INSTRUCTION_PARAM struct, ``z`` to represent ``None`` (which is encoded as
|
1608
|
+
no data), ``q`` to represent a :class:`.QuantumCircuit` (which is encoded as
|
1609
|
+
a QPY circuit), ``r`` to represent a ``range`` of integers (which is encoded as
|
1610
|
+
a :ref:`qpy_range_pack`), and ``t`` to represent a ``sequence`` (which is encoded as
|
1611
|
+
defined by :ref:`qpy_sequence`). Additionally, version 4 changes the type of register
|
1612
|
+
index mapping array from ``uint32_t`` to ``int64_t``. If the values of any of the
|
1613
|
+
array elements are negative they represent a register bit that is not present in the
|
1614
|
+
circuit.
|
1615
|
+
|
1616
|
+
The :ref:`qpy_registers` header format has also been updated to
|
1617
|
+
|
1618
|
+
.. code-block:: c
|
1619
|
+
|
1620
|
+
struct {
|
1621
|
+
char type;
|
1622
|
+
_Bool standalone;
|
1623
|
+
uint32_t size;
|
1624
|
+
uint16_t name_size;
|
1625
|
+
_bool in_circuit;
|
1626
|
+
}
|
1627
|
+
|
1628
|
+
which just adds the ``in_circuit`` field which represents whether the register is
|
1629
|
+
part of the circuit or not.
|
1630
|
+
|
1631
|
+
.. _qpy_range_pack:
|
1632
|
+
|
1633
|
+
RANGE
|
1634
|
+
~~~~~
|
1635
|
+
|
1636
|
+
A RANGE is a representation of a ``range`` object. It is defined as:
|
1637
|
+
|
1638
|
+
.. code-block:: c
|
1639
|
+
|
1640
|
+
struct {
|
1641
|
+
int64_t start;
|
1642
|
+
int64_t stop;
|
1643
|
+
int64_t step;
|
1644
|
+
}
|
1645
|
+
|
1646
|
+
.. _qpy_sequence:
|
1647
|
+
|
1648
|
+
SEQUENCE
|
1649
|
+
~~~~~~~~
|
1650
|
+
|
1651
|
+
A SEQUENCE is a representation of an arbitrary sequence object. As sequence are just fixed length
|
1652
|
+
containers of arbitrary python objects their QPY can't fully represent any sequence,
|
1653
|
+
but as long as the contents in a sequence are other QPY serializable types for
|
1654
|
+
the INSTRUCTION_PARAM payload the ``sequence`` object can be serialized.
|
1655
|
+
|
1656
|
+
A sequence instruction parameter starts with a header defined as:
|
1657
|
+
|
1658
|
+
.. code-block:: c
|
1659
|
+
|
1660
|
+
struct {
|
1661
|
+
uint64_t size;
|
1662
|
+
}
|
1663
|
+
|
1664
|
+
followed by ``size`` elements that are INSTRUCTION_PARAM payloads, where each of
|
1665
|
+
these define an element in the sequence. The sequence object will be typecasted
|
1666
|
+
into proper type, e.g. ``tuple``, afterwards.
|
1667
|
+
|
1668
|
+
.. _qpy_version_3:
|
1669
|
+
|
1670
|
+
Version 3
|
1671
|
+
---------
|
1672
|
+
|
1673
|
+
Version 3 of the QPY format is identical to :ref:`qpy_version_2` except that it defines
|
1674
|
+
a struct format to represent a :class:`~qiskit.circuit.library.PauliEvolutionGate`
|
1675
|
+
natively in QPY. To accomplish this the :ref:`qpy_custom_definition` struct now supports
|
1676
|
+
a new type value ``'p'`` to represent a :class:`~qiskit.circuit.library.PauliEvolutionGate`.
|
1677
|
+
Enties in the custom instructions tables have unique name generated that start with the
|
1678
|
+
string ``"###PauliEvolutionGate_"`` followed by a uuid string. This gate name is reservered
|
1679
|
+
in QPY and if you have a custom :class:`~qiskit.circuit.Instruction` object with a definition
|
1680
|
+
set and that name prefix it will error. If it's of type ``'p'`` the data payload is defined
|
1681
|
+
as follows:
|
1682
|
+
|
1683
|
+
.. _pauli_evo_qpy:
|
1684
|
+
|
1685
|
+
PAULI_EVOLUTION
|
1686
|
+
~~~~~~~~~~~~~~~
|
1687
|
+
|
1688
|
+
This represents the high level :class:`~qiskit.circuit.library.PauliEvolutionGate`
|
1689
|
+
|
1690
|
+
.. code-block:: c
|
1691
|
+
|
1692
|
+
struct {
|
1693
|
+
uint64_t operator_count;
|
1694
|
+
_Bool standalone_op;
|
1695
|
+
char time_type;
|
1696
|
+
uint64_t time_size;
|
1697
|
+
uint64_t synthesis_size;
|
1698
|
+
}
|
1699
|
+
|
1700
|
+
This is immediately followed by ``operator_count`` elements defined by the :ref:`qpy_pauli_sum_op`
|
1701
|
+
payload. Following that we have ``time_size`` bytes representing the ``time`` attribute. If
|
1702
|
+
``standalone_op`` is ``True`` then there must only be a single operator. The
|
1703
|
+
encoding of these bytes is determined by the value of ``time_type``. Possible values of
|
1704
|
+
``time_type`` are ``'f'``, ``'p'``, and ``'e'``. If ``time_type`` is ``'f'`` it's a double,
|
1705
|
+
``'p'`` defines a :class:`~qiskit.circuit.Parameter` object which is represented by a
|
1706
|
+
:ref:`qpy_param_struct`, ``e`` defines a :class:`~qiskit.circuit.ParameterExpression` object
|
1707
|
+
(that's not a :class:`~qiskit.circuit.Parameter`) which is represented by a :ref:`qpy_param_expr`.
|
1708
|
+
Following that is ``synthesis_size`` bytes which is a utf8 encoded json payload representing
|
1709
|
+
the :class:`.EvolutionSynthesis` class used by the gate.
|
1710
|
+
|
1711
|
+
.. _qpy_pauli_sum_op:
|
1712
|
+
|
1713
|
+
SPARSE_PAULI_OP_LIST_ELEM
|
1714
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
1715
|
+
|
1716
|
+
This represents an instance of :class:`.SparsePauliOp`.
|
1717
|
+
|
1718
|
+
|
1719
|
+
.. code-block:: c
|
1720
|
+
|
1721
|
+
struct {
|
1722
|
+
uint32_t pauli_op_size;
|
1723
|
+
}
|
1724
|
+
|
1725
|
+
which is immediately followed by ``pauli_op_size`` bytes which are .npy format [#f2]_
|
1726
|
+
data which represents the :class:`~qiskit.quantum_info.SparsePauliOp`.
|
1727
|
+
|
1728
|
+
Version 3 of the QPY format also defines a struct format to represent a
|
1729
|
+
:class:`~qiskit.circuit.ParameterVectorElement` as a distinct subclass from
|
1730
|
+
a :class:`~qiskit.circuit.Parameter`. This adds a new parameter type char ``'v'``
|
1731
|
+
to represent a :class:`~qiskit.circuit.ParameterVectorElement` which is now
|
1732
|
+
supported as a type string value for an INSTRUCTION_PARAM. The payload for these
|
1733
|
+
parameters are defined below as :ref:`qpy_param_vector`.
|
1734
|
+
|
1735
|
+
.. _qpy_param_vector:
|
1736
|
+
|
1737
|
+
PARAMETER_VECTOR_ELEMENT
|
1738
|
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
1739
|
+
|
1740
|
+
A PARAMETER_VECTOR_ELEMENT represents a :class:`~qiskit.circuit.ParameterVectorElement`
|
1741
|
+
object the data for a INSTRUCTION_PARAM. The contents of the PARAMETER_VECTOR_ELEMENT are
|
1742
|
+
defined as:
|
1743
|
+
|
1744
|
+
.. code-block:: c
|
1745
|
+
|
1746
|
+
struct {
|
1747
|
+
uint16_t vector_name_size;
|
1748
|
+
uint64_t vector_size;
|
1749
|
+
char uuid[16];
|
1750
|
+
uint64_t index;
|
1751
|
+
}
|
1752
|
+
|
1753
|
+
which is immediately followed by ``vector_name_size`` utf8 bytes representing
|
1754
|
+
the parameter's vector name.
|
1755
|
+
|
1756
|
+
.. _qpy_param_expr_v3:
|
1757
|
+
|
1758
|
+
|
1759
|
+
PARAMETER_EXPR
|
1760
|
+
~~~~~~~~~~~~~~
|
1761
|
+
|
1762
|
+
Additionally, since QPY format version v3 distinguishes between a
|
1763
|
+
:class:`~qiskit.circuit.Parameter` and :class:`~qiskit.circuit.ParameterVectorElement`
|
1764
|
+
the payload for a :class:`~qiskit.circuit.ParameterExpression` needs to be updated
|
1765
|
+
to distinguish between the types. The following is the modified payload format
|
1766
|
+
which is mostly identical to the format in Version 1 and :ref:`qpy_version_2` but just
|
1767
|
+
modifies the ``map_elements`` struct to include a symbol type field.
|
1768
|
+
|
1769
|
+
A PARAMETER_EXPR represents a :class:`~qiskit.circuit.ParameterExpression`
|
1770
|
+
object that the data for an INSTRUCTION_PARAM. The contents of a PARAMETER_EXPR
|
1771
|
+
are defined as:
|
1772
|
+
|
1773
|
+
.. code-block:: c
|
1774
|
+
|
1775
|
+
struct {
|
1776
|
+
uint64_t map_elements;
|
1777
|
+
uint64_t expr_size;
|
1778
|
+
}
|
1779
|
+
|
1780
|
+
Immediately following the header is ``expr_size`` bytes of utf8 data containing
|
1781
|
+
the expression string, which is the sympy srepr of the expression for the
|
1782
|
+
parameter expression. Following that is a symbol map which contains
|
1783
|
+
``map_elements`` elements with the format
|
1784
|
+
|
1785
|
+
.. code-block:: c
|
1786
|
+
|
1787
|
+
struct {
|
1788
|
+
char symbol_type;
|
1789
|
+
char type;
|
1790
|
+
uint64_t size;
|
1791
|
+
}
|
1792
|
+
|
1793
|
+
The ``symbol_type`` key determines the payload type of the symbol representation
|
1794
|
+
for the element. If it's ``p`` it represents a :class:`~qiskit.circuit.Parameter`
|
1795
|
+
and if it's ``v`` it represents a :class:`~qiskit.circuit.ParameterVectorElement`.
|
1796
|
+
The map element struct is immediately followed by the symbol map key payload, if
|
1797
|
+
``symbol_type`` is ``p`` then it is followed immediately by a :ref:`qpy_param_struct`
|
1798
|
+
object (both the struct and utf8 name bytes) and if ``symbol_type`` is ``v``
|
1799
|
+
then the struct is imediately followed by :ref:`qpy_param_vector` (both the struct
|
1800
|
+
and utf8 name bytes). That is followed by ``size`` bytes for the
|
1801
|
+
data of the symbol. The data format is dependent on the value of ``type``. If
|
1802
|
+
``type`` is ``p`` then it represents a :class:`~qiskit.circuit.Parameter` and
|
1803
|
+
size will be 0, the value will just be the same as the key. Similarly if the
|
1804
|
+
``type`` is ``v`` then it represents a :class:`~qiskit.circuit.ParameterVectorElement`
|
1805
|
+
and size will be 0 as the value will just be the same as the key. If
|
1806
|
+
``type`` is ``f`` then it represents a double precision float. If ``type`` is
|
1807
|
+
``c`` it represents a double precision complex, which is represented by the
|
1808
|
+
:ref:`qpy_complex`. Finally, if type is ``i`` it represents an integer which is an
|
1809
|
+
``int64_t``.
|
1810
|
+
|
1811
|
+
.. _qpy_version_2:
|
1812
|
+
|
1813
|
+
Version 2
|
1814
|
+
---------
|
1815
|
+
|
1816
|
+
Version 2 of the QPY format is identical to version 1 except for the HEADER
|
1817
|
+
section is slightly different. You can refer to the :ref:`qpy_version_1` section
|
1818
|
+
for the details on the rest of the payload format.
|
1819
|
+
|
1820
|
+
HEADER
|
1821
|
+
~~~~~~
|
1822
|
+
|
1823
|
+
The contents of HEADER are defined as a C struct are:
|
1824
|
+
|
1825
|
+
.. code-block:: c
|
1826
|
+
|
1827
|
+
struct {
|
1828
|
+
uint16_t name_size;
|
1829
|
+
char global_phase_type;
|
1830
|
+
uint16_t global_phase_size;
|
1831
|
+
uint32_t num_qubits;
|
1832
|
+
uint32_t num_clbits;
|
1833
|
+
uint64_t metadata_size;
|
1834
|
+
uint32_t num_registers;
|
1835
|
+
uint64_t num_instructions;
|
1836
|
+
}
|
1837
|
+
|
1838
|
+
This is immediately followed by ``name_size`` bytes of utf8 data for the name
|
1839
|
+
of the circuit. Following this is immediately ``global_phase_size`` bytes
|
1840
|
+
representing the global phase. The content of that data is dictated by the
|
1841
|
+
value of ``global_phase_type``. If it's ``'f'`` the data is a float and is the
|
1842
|
+
size of a ``double``. If it's ``'p'`` defines a :class:`~qiskit.circuit.Parameter`
|
1843
|
+
object which is represented by a PARAM struct (see below), ``e`` defines a
|
1844
|
+
:class:`~qiskit.circuit.ParameterExpression` object (that's not a
|
1845
|
+
:class:`~qiskit.circuit.Parameter`) which is represented by a PARAM_EXPR struct
|
1846
|
+
(see below).
|
1847
|
+
|
1848
|
+
.. _qpy_version_1:
|
1849
|
+
|
1850
|
+
Version 1
|
1851
|
+
---------
|
1852
|
+
|
1853
|
+
HEADER
|
1854
|
+
~~~~~~
|
1855
|
+
|
1856
|
+
The contents of HEADER as defined as a C struct are:
|
1857
|
+
|
1858
|
+
.. code-block:: c
|
1859
|
+
|
1860
|
+
struct {
|
1861
|
+
uint16_t name_size;
|
1862
|
+
double global_phase;
|
1863
|
+
uint32_t num_qubits;
|
1864
|
+
uint32_t num_clbits;
|
1865
|
+
uint64_t metadata_size;
|
1866
|
+
uint32_t num_registers;
|
1867
|
+
uint64_t num_instructions;
|
1868
|
+
}
|
1869
|
+
|
1870
|
+
This is immediately followed by ``name_size`` bytes of utf8 data for the name
|
1871
|
+
of the circuit.
|
1872
|
+
|
1873
|
+
METADATA
|
1874
|
+
~~~~~~~~
|
1875
|
+
|
1876
|
+
The METADATA field is a UTF8 encoded JSON string. After reading the HEADER
|
1877
|
+
(which is a fixed size at the start of the QPY file) and the ``name`` string
|
1878
|
+
you then read the ``metadata_size`` number of bytes and parse the JSON to get
|
1879
|
+
the metadata for the circuit.
|
1880
|
+
|
1881
|
+
.. _qpy_registers:
|
1882
|
+
|
1883
|
+
REGISTERS
|
1884
|
+
~~~~~~~~~
|
1885
|
+
|
1886
|
+
The contents of REGISTERS is a number of REGISTER object. If num_registers is
|
1887
|
+
> 0 then after reading METADATA you read that number of REGISTER structs defined
|
1888
|
+
as:
|
1889
|
+
|
1890
|
+
.. code-block:: c
|
1891
|
+
|
1892
|
+
struct {
|
1893
|
+
char type;
|
1894
|
+
_Bool standalone;
|
1895
|
+
uint32_t size;
|
1896
|
+
uint16_t name_size;
|
1897
|
+
}
|
1898
|
+
|
1899
|
+
``type`` can be ``'q'`` or ``'c'``.
|
1900
|
+
|
1901
|
+
Immediately following the REGISTER struct is the utf8 encoded register name of
|
1902
|
+
size ``name_size``. After the ``name`` utf8 bytes there is then an array of
|
1903
|
+
int64_t values of size ``size`` that contains a map of the register's index to
|
1904
|
+
the circuit's qubit index. For example, array element 0's value is the index
|
1905
|
+
of the ``register[0]``'s position in the containing circuit's qubits list.
|
1906
|
+
|
1907
|
+
.. note::
|
1908
|
+
|
1909
|
+
Prior to QPY :ref:`qpy_version_4` the type of array elements was uint32_t. This was changed
|
1910
|
+
to enable negative values which represent bits in the array not present in the
|
1911
|
+
circuit
|
1912
|
+
|
1913
|
+
|
1914
|
+
The standalone boolean determines whether the register is constructed as a
|
1915
|
+
standalone register that was added to the circuit or was created from existing
|
1916
|
+
bits. A register is considered standalone if it has bits constructed solely
|
1917
|
+
as part of it, for example::
|
1918
|
+
|
1919
|
+
qr = QuantumRegister(2)
|
1920
|
+
qc = QuantumCircuit(qr)
|
1921
|
+
|
1922
|
+
the register ``qr`` would be a standalone register. While something like::
|
1923
|
+
|
1924
|
+
bits = [Qubit(), Qubit()]
|
1925
|
+
qr2 = QuantumRegister(bits=bits)
|
1926
|
+
qc = QuantumCircuit(qr2)
|
1927
|
+
|
1928
|
+
``qr2`` would have ``standalone`` set to ``False``.
|
1929
|
+
|
1930
|
+
|
1931
|
+
.. _qpy_custom_definition:
|
1932
|
+
|
1933
|
+
CUSTOM_DEFINITIONS
|
1934
|
+
~~~~~~~~~~~~~~~~~~
|
1935
|
+
|
1936
|
+
This section specifies custom definitions for any of the instructions in the circuit.
|
1937
|
+
|
1938
|
+
CUSTOM_DEFINITION_HEADER contents are defined as:
|
1939
|
+
|
1940
|
+
.. code-block:: c
|
1941
|
+
|
1942
|
+
struct {
|
1943
|
+
uint64_t size;
|
1944
|
+
}
|
1945
|
+
|
1946
|
+
If size is greater than 0 that means the circuit contains custom instruction(s).
|
1947
|
+
Each custom instruction is defined with a CUSTOM_INSTRUCTION block defined as:
|
1948
|
+
|
1949
|
+
.. code-block:: c
|
1950
|
+
|
1951
|
+
struct {
|
1952
|
+
uint16_t name_size;
|
1953
|
+
char type;
|
1954
|
+
uint32_t num_qubits;
|
1955
|
+
uint32_t num_clbits;
|
1956
|
+
_Bool custom_definition;
|
1957
|
+
uint64_t size;
|
1958
|
+
}
|
1959
|
+
|
1960
|
+
Immediately following the CUSTOM_INSTRUCTION struct is the utf8 encoded name
|
1961
|
+
of size ``name_size``.
|
1962
|
+
|
1963
|
+
If ``custom_definition`` is ``True`` that means that the immediately following
|
1964
|
+
``size`` bytes contains a QPY circuit data which can be used for the custom
|
1965
|
+
definition of that gate. If ``custom_definition`` is ``False`` then the
|
1966
|
+
instruction can be considered opaque (ie no definition). The ``type`` field
|
1967
|
+
determines what type of object will get created with the custom definition.
|
1968
|
+
If it's ``'g'`` it will be a :class:`~qiskit.circuit.Gate` object, ``'i'``
|
1969
|
+
it will be a :class:`~qiskit.circuit.Instruction` object.
|
1970
|
+
|
1971
|
+
.. _qpy_instructions:
|
1972
|
+
|
1973
|
+
INSTRUCTIONS
|
1974
|
+
~~~~~~~~~~~~
|
1975
|
+
|
1976
|
+
The contents of INSTRUCTIONS is a list of INSTRUCTION metadata objects
|
1977
|
+
|
1978
|
+
.. code-block:: c
|
1979
|
+
|
1980
|
+
struct {
|
1981
|
+
uint16_t name_size;
|
1982
|
+
uint16_t label_size;
|
1983
|
+
uint16_t num_parameters;
|
1984
|
+
uint32_t num_qargs;
|
1985
|
+
uint32_t num_cargs;
|
1986
|
+
_Bool has_conditional;
|
1987
|
+
uint16_t conditional_reg_name_size;
|
1988
|
+
int64_t conditional_value;
|
1989
|
+
}
|
1990
|
+
|
1991
|
+
This metadata object is immediately followed by ``name_size`` bytes of utf8 bytes
|
1992
|
+
for the ``name``. ``name`` here is the Qiskit class name for the Instruction
|
1993
|
+
class if it's defined in Qiskit. Otherwise it falls back to the custom
|
1994
|
+
instruction name. Following the ``name`` bytes there are ``label_size`` bytes of
|
1995
|
+
utf8 data for the label if one was set on the instruction. Following the label
|
1996
|
+
bytes if ``has_conditional`` is ``True`` then there are
|
1997
|
+
``conditional_reg_name_size`` bytes of utf8 data for the name of the conditional
|
1998
|
+
register name. In case of single classical bit conditions the register name
|
1999
|
+
utf8 data will be prefixed with a null character "\\x00" and then a utf8 string
|
2000
|
+
integer representing the classical bit index in the circuit that the condition
|
2001
|
+
is on.
|
2002
|
+
|
2003
|
+
This is immediately followed by the INSTRUCTION_ARG structs for the list of
|
2004
|
+
arguments of that instruction. These are in the order of all quantum arguments
|
2005
|
+
(there are num_qargs of these) followed by all classical arguments (num_cargs
|
2006
|
+
of these).
|
2007
|
+
|
2008
|
+
The contents of each INSTRUCTION_ARG is:
|
2009
|
+
|
2010
|
+
.. code-block:: c
|
2011
|
+
|
2012
|
+
struct {
|
2013
|
+
char type;
|
2014
|
+
uint32_t index;
|
2015
|
+
}
|
2016
|
+
|
2017
|
+
``type`` can be ``'q'`` or ``'c'``.
|
2018
|
+
|
2019
|
+
After all arguments for an instruction the parameters are specified with
|
2020
|
+
``num_parameters`` INSTRUCTION_PARAM structs.
|
2021
|
+
|
2022
|
+
The contents of each INSTRUCTION_PARAM is:
|
2023
|
+
|
2024
|
+
.. code-block:: c
|
2025
|
+
|
2026
|
+
struct {
|
2027
|
+
char type;
|
2028
|
+
uint64_t size;
|
2029
|
+
}
|
2030
|
+
|
2031
|
+
After each INSTRUCTION_PARAM the next ``size`` bytes are the parameter's data.
|
2032
|
+
The ``type`` field can be ``'i'``, ``'f'``, ``'p'``, ``'e'``, ``'s'``, ``'c'``
|
2033
|
+
or ``'n'`` which dictate the format. For ``'i'`` it's an integer, ``'f'`` it's
|
2034
|
+
a double, ``'s'`` if it's a string (encoded as utf8), ``'c'`` is a complex and
|
2035
|
+
the data is represented by the struct format in the :ref:`qpy_param_expr` section.
|
2036
|
+
``'p'`` defines a :class:`~qiskit.circuit.Parameter` object which is
|
2037
|
+
represented by a :ref:`qpy_param_struct` struct, ``e`` defines a
|
2038
|
+
:class:`~qiskit.circuit.ParameterExpression` object (that's not a
|
2039
|
+
:class:`~qiskit.circuit.Parameter`) which is represented by a :ref:`qpy_param_expr`
|
2040
|
+
struct (on QPY format :ref:`qpy_version_3` the format is tweak slightly see:
|
2041
|
+
:ref:`qpy_param_expr_v3`), ``'n'`` represents an object from numpy (either an
|
2042
|
+
``ndarray`` or a numpy type) which means the data is .npy format [#f2]_ data,
|
2043
|
+
and in QPY :ref:`qpy_version_3` ``'v'`` represents a
|
2044
|
+
:class:`~qiskit.circuit.ParameterVectorElement` which is represented by a
|
2045
|
+
:ref:`qpy_param_vector` struct.
|
2046
|
+
|
2047
|
+
.. _qpy_param_struct:
|
2048
|
+
|
2049
|
+
PARAMETER
|
2050
|
+
~~~~~~~~~
|
2051
|
+
|
2052
|
+
A PARAMETER represents a :class:`~qiskit.circuit.Parameter` object the data for
|
2053
|
+
a INSTRUCTION_PARAM. The contents of the PARAMETER are defined as:
|
2054
|
+
|
2055
|
+
.. code-block:: c
|
2056
|
+
|
2057
|
+
struct {
|
2058
|
+
uint16_t name_size;
|
2059
|
+
char uuid[16];
|
2060
|
+
}
|
2061
|
+
|
2062
|
+
which is immediately followed by ``name_size`` utf8 bytes representing the
|
2063
|
+
parameter name.
|
2064
|
+
|
2065
|
+
.. _qpy_param_expr:
|
2066
|
+
|
2067
|
+
PARAMETER_EXPR
|
2068
|
+
~~~~~~~~~~~~~~
|
2069
|
+
|
2070
|
+
A PARAMETER_EXPR represents a :class:`~qiskit.circuit.ParameterExpression`
|
2071
|
+
object that the data for an INSTRUCTION_PARAM. The contents of a PARAMETER_EXPR
|
2072
|
+
are defined as:
|
2073
|
+
|
2074
|
+
The PARAMETER_EXPR data starts with a header:
|
2075
|
+
|
2076
|
+
.. code-block:: c
|
2077
|
+
|
2078
|
+
struct {
|
2079
|
+
uint64_t map_elements;
|
2080
|
+
uint64_t expr_size;
|
2081
|
+
}
|
2082
|
+
|
2083
|
+
Immediately following the header is ``expr_size`` bytes of utf8 data containing
|
2084
|
+
the expression string, which is the sympy srepr of the expression for the
|
2085
|
+
parameter expression. Follwing that is a symbol map which contains
|
2086
|
+
``map_elements`` elements with the format
|
2087
|
+
|
2088
|
+
.. code-block:: c
|
2089
|
+
|
2090
|
+
struct {
|
2091
|
+
char type;
|
2092
|
+
uint64_t size;
|
2093
|
+
}
|
2094
|
+
|
2095
|
+
Which is followed immediately by ``PARAMETER`` object (both the struct and utf8
|
2096
|
+
name bytes) for the symbol map key. That is followed by ``size`` bytes for the
|
2097
|
+
data of the symbol. The data format is dependent on the value of ``type``. If
|
2098
|
+
``type`` is ``p`` then it represents a :class:`~qiskit.circuit.Parameter` and
|
2099
|
+
size will be 0, the value will just be the same as the key. If
|
2100
|
+
``type`` is ``f`` then it represents a double precision float. If ``type`` is
|
2101
|
+
``c`` it represents a double precision complex, which is represented by :ref:`qpy_complex`.
|
2102
|
+
Finally, if type is ``i`` it represents an integer which is an ``int64_t``.
|
2103
|
+
|
2104
|
+
.. _qpy_complex:
|
2105
|
+
|
2106
|
+
COMPLEX
|
2107
|
+
~~~~~~~
|
2108
|
+
|
2109
|
+
When representing a double precision complex value in QPY the following
|
2110
|
+
struct is used:
|
2111
|
+
|
2112
|
+
|
2113
|
+
.. code-block:: c
|
2114
|
+
|
2115
|
+
struct {
|
2116
|
+
double real;
|
2117
|
+
double imag;
|
2118
|
+
}
|
2119
|
+
|
2120
|
+
this matches the internal C representation of Python's complex type. [#f3]_
|
2121
|
+
|
2122
|
+
References
|
2123
|
+
==========
|
2124
|
+
|
2125
|
+
.. [#f1] https://tools.ietf.org/html/rfc1700
|
2126
|
+
.. [#f2] https://numpy.org/doc/stable/reference/generated/numpy.lib.format.html
|
2127
|
+
.. [#f3] https://docs.python.org/3/c-api/complex.html#c.Py_complex
|
2128
|
+
"""
|
2129
|
+
|
2130
|
+
from .exceptions import QpyError, UnsupportedFeatureForVersion, QPYLoadingDeprecatedFeatureWarning
|
2131
|
+
from .interface import dump, load, get_qpy_version
|
2132
|
+
|
2133
|
+
# For backward compatibility. Provide, Runtime, Experiment call these private functions.
|
2134
|
+
from .binary_io import (
|
2135
|
+
_write_instruction,
|
2136
|
+
_read_instruction,
|
2137
|
+
_write_parameter_expression,
|
2138
|
+
_read_parameter_expression,
|
2139
|
+
_read_parameter_expression_v3,
|
2140
|
+
)
|
2141
|
+
from .common import QPY_VERSION, QPY_COMPATIBILITY_VERSION
|