qiskit 1.0.2__cp38-abi3-win32.whl → 1.1.0rc1__cp38-abi3-win32.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 -1
- qiskit/__init__.py +27 -16
- qiskit/_accelerate.pyd +0 -0
- qiskit/_numpy_compat.py +73 -0
- qiskit/assembler/disassemble.py +5 -6
- qiskit/circuit/__init__.py +1131 -169
- qiskit/circuit/_classical_resource_map.py +7 -6
- qiskit/circuit/_utils.py +18 -8
- qiskit/circuit/annotated_operation.py +21 -0
- qiskit/circuit/barrier.py +10 -13
- qiskit/circuit/bit.py +0 -1
- qiskit/circuit/classical/__init__.py +2 -2
- qiskit/circuit/classical/expr/__init__.py +39 -5
- qiskit/circuit/classical/expr/constructors.py +84 -1
- qiskit/circuit/classical/expr/expr.py +83 -13
- qiskit/circuit/classical/expr/visitors.py +83 -0
- qiskit/circuit/commutation_checker.py +86 -51
- qiskit/circuit/controlflow/_builder_utils.py +9 -1
- qiskit/circuit/controlflow/break_loop.py +8 -22
- qiskit/circuit/controlflow/builder.py +116 -1
- qiskit/circuit/controlflow/continue_loop.py +8 -22
- qiskit/circuit/controlflow/control_flow.py +47 -8
- qiskit/circuit/controlflow/for_loop.py +8 -23
- qiskit/circuit/controlflow/if_else.py +13 -27
- qiskit/circuit/controlflow/switch_case.py +14 -21
- qiskit/circuit/controlflow/while_loop.py +9 -23
- qiskit/circuit/controlledgate.py +2 -2
- qiskit/circuit/delay.py +7 -5
- qiskit/circuit/gate.py +20 -7
- qiskit/circuit/instruction.py +31 -30
- qiskit/circuit/instructionset.py +9 -22
- qiskit/circuit/library/__init__.py +8 -2
- qiskit/circuit/library/arithmetic/integer_comparator.py +2 -2
- qiskit/circuit/library/arithmetic/quadratic_form.py +3 -2
- qiskit/circuit/library/blueprintcircuit.py +29 -7
- qiskit/circuit/library/data_preparation/state_preparation.py +6 -5
- qiskit/circuit/library/generalized_gates/diagonal.py +5 -4
- qiskit/circuit/library/generalized_gates/isometry.py +51 -254
- qiskit/circuit/library/generalized_gates/pauli.py +2 -2
- qiskit/circuit/library/generalized_gates/permutation.py +4 -1
- qiskit/circuit/library/generalized_gates/rv.py +15 -11
- qiskit/circuit/library/generalized_gates/uc.py +2 -98
- qiskit/circuit/library/generalized_gates/unitary.py +9 -4
- qiskit/circuit/library/hamiltonian_gate.py +11 -5
- qiskit/circuit/library/n_local/efficient_su2.py +5 -5
- qiskit/circuit/library/n_local/n_local.py +100 -49
- qiskit/circuit/library/n_local/two_local.py +3 -59
- qiskit/circuit/library/overlap.py +3 -3
- qiskit/circuit/library/phase_oracle.py +1 -1
- qiskit/circuit/library/quantum_volume.py +39 -38
- qiskit/circuit/library/standard_gates/equivalence_library.py +50 -0
- qiskit/circuit/library/standard_gates/global_phase.py +4 -2
- qiskit/circuit/library/standard_gates/i.py +1 -2
- qiskit/circuit/library/standard_gates/iswap.py +1 -2
- qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py +11 -5
- qiskit/circuit/library/standard_gates/p.py +31 -15
- qiskit/circuit/library/standard_gates/r.py +4 -3
- qiskit/circuit/library/standard_gates/rx.py +7 -4
- qiskit/circuit/library/standard_gates/rxx.py +4 -3
- qiskit/circuit/library/standard_gates/ry.py +7 -4
- qiskit/circuit/library/standard_gates/ryy.py +4 -3
- qiskit/circuit/library/standard_gates/rz.py +7 -4
- qiskit/circuit/library/standard_gates/rzx.py +4 -3
- qiskit/circuit/library/standard_gates/rzz.py +4 -3
- qiskit/circuit/library/standard_gates/s.py +4 -8
- qiskit/circuit/library/standard_gates/t.py +2 -4
- qiskit/circuit/library/standard_gates/u.py +16 -11
- qiskit/circuit/library/standard_gates/u1.py +6 -2
- qiskit/circuit/library/standard_gates/u2.py +4 -2
- qiskit/circuit/library/standard_gates/u3.py +9 -5
- qiskit/circuit/library/standard_gates/x.py +22 -11
- qiskit/circuit/library/standard_gates/xx_minus_yy.py +4 -3
- qiskit/circuit/library/standard_gates/xx_plus_yy.py +7 -5
- qiskit/circuit/library/standard_gates/z.py +1 -2
- qiskit/circuit/measure.py +4 -1
- qiskit/circuit/operation.py +13 -8
- qiskit/circuit/parameter.py +11 -6
- qiskit/circuit/quantumcircuit.py +864 -128
- qiskit/circuit/quantumcircuitdata.py +2 -2
- qiskit/circuit/reset.py +5 -2
- qiskit/circuit/store.py +95 -0
- qiskit/compiler/assembler.py +22 -22
- qiskit/compiler/transpiler.py +63 -112
- qiskit/converters/circuit_to_dag.py +7 -0
- qiskit/converters/circuit_to_dagdependency_v2.py +47 -0
- qiskit/converters/circuit_to_gate.py +2 -0
- qiskit/converters/circuit_to_instruction.py +22 -0
- qiskit/converters/dag_to_circuit.py +4 -0
- qiskit/converters/dag_to_dagdependency_v2.py +44 -0
- qiskit/dagcircuit/collect_blocks.py +15 -10
- qiskit/dagcircuit/dagcircuit.py +434 -124
- qiskit/dagcircuit/dagdependency.py +19 -12
- qiskit/dagcircuit/dagdependency_v2.py +641 -0
- qiskit/dagcircuit/dagdepnode.py +19 -16
- qiskit/dagcircuit/dagnode.py +14 -4
- qiskit/primitives/__init__.py +12 -8
- qiskit/primitives/backend_estimator.py +3 -5
- qiskit/primitives/backend_estimator_v2.py +410 -0
- qiskit/primitives/backend_sampler_v2.py +287 -0
- qiskit/primitives/base/base_estimator.py +4 -9
- qiskit/primitives/base/base_sampler.py +2 -2
- qiskit/primitives/containers/__init__.py +5 -4
- qiskit/primitives/containers/bit_array.py +292 -2
- qiskit/primitives/containers/data_bin.py +123 -50
- qiskit/primitives/containers/estimator_pub.py +10 -3
- qiskit/primitives/containers/observables_array.py +2 -2
- qiskit/primitives/containers/pub_result.py +1 -1
- qiskit/primitives/containers/sampler_pub.py +19 -3
- qiskit/primitives/containers/sampler_pub_result.py +74 -0
- qiskit/primitives/containers/shape.py +1 -1
- qiskit/primitives/statevector_estimator.py +4 -4
- qiskit/primitives/statevector_sampler.py +7 -12
- qiskit/providers/__init__.py +17 -18
- qiskit/providers/backend.py +2 -2
- qiskit/providers/backend_compat.py +8 -10
- qiskit/providers/basic_provider/basic_provider_tools.py +67 -31
- qiskit/providers/basic_provider/basic_simulator.py +81 -21
- qiskit/providers/fake_provider/fake_1q.py +1 -1
- qiskit/providers/fake_provider/fake_backend.py +3 -408
- qiskit/providers/fake_provider/generic_backend_v2.py +26 -14
- qiskit/providers/provider.py +16 -0
- qiskit/pulse/builder.py +4 -1
- qiskit/pulse/parameter_manager.py +60 -4
- qiskit/pulse/schedule.py +29 -13
- qiskit/pulse/utils.py +61 -20
- qiskit/qasm2/__init__.py +1 -5
- qiskit/qasm2/parse.py +1 -4
- qiskit/qasm3/__init__.py +42 -5
- qiskit/qasm3/ast.py +19 -0
- qiskit/qasm3/exporter.py +178 -106
- qiskit/qasm3/printer.py +27 -5
- qiskit/qpy/__init__.py +247 -13
- qiskit/qpy/binary_io/circuits.py +216 -47
- qiskit/qpy/binary_io/schedules.py +42 -36
- qiskit/qpy/binary_io/value.py +201 -22
- qiskit/qpy/common.py +1 -1
- qiskit/qpy/exceptions.py +20 -0
- qiskit/qpy/formats.py +29 -0
- qiskit/qpy/type_keys.py +21 -0
- qiskit/quantum_info/analysis/distance.py +3 -3
- qiskit/quantum_info/analysis/make_observable.py +2 -1
- qiskit/quantum_info/analysis/z2_symmetries.py +2 -1
- qiskit/quantum_info/operators/channel/chi.py +9 -8
- qiskit/quantum_info/operators/channel/choi.py +10 -9
- qiskit/quantum_info/operators/channel/kraus.py +2 -1
- qiskit/quantum_info/operators/channel/ptm.py +10 -9
- qiskit/quantum_info/operators/channel/quantum_channel.py +2 -1
- qiskit/quantum_info/operators/channel/stinespring.py +2 -1
- qiskit/quantum_info/operators/channel/superop.py +12 -11
- qiskit/quantum_info/operators/channel/transformations.py +12 -11
- qiskit/quantum_info/operators/dihedral/dihedral.py +5 -4
- qiskit/quantum_info/operators/operator.py +43 -30
- qiskit/quantum_info/operators/scalar_op.py +10 -9
- qiskit/quantum_info/operators/symplectic/base_pauli.py +70 -59
- qiskit/quantum_info/operators/symplectic/clifford.py +36 -9
- qiskit/quantum_info/operators/symplectic/pauli.py +48 -4
- qiskit/quantum_info/operators/symplectic/pauli_list.py +36 -14
- qiskit/quantum_info/operators/symplectic/random.py +3 -2
- qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +54 -33
- qiskit/quantum_info/states/densitymatrix.py +13 -13
- qiskit/quantum_info/states/stabilizerstate.py +3 -3
- qiskit/quantum_info/states/statevector.py +14 -13
- qiskit/quantum_info/states/utils.py +5 -3
- qiskit/result/mitigation/correlated_readout_mitigator.py +3 -2
- qiskit/result/mitigation/local_readout_mitigator.py +2 -1
- qiskit/result/mitigation/utils.py +3 -2
- qiskit/synthesis/__init__.py +2 -0
- qiskit/synthesis/discrete_basis/commutator_decompose.py +2 -2
- qiskit/synthesis/evolution/lie_trotter.py +7 -14
- qiskit/synthesis/evolution/qdrift.py +3 -4
- qiskit/synthesis/linear/cnot_synth.py +1 -3
- qiskit/synthesis/linear/linear_circuits_utils.py +1 -1
- qiskit/synthesis/linear_phase/cz_depth_lnn.py +4 -18
- qiskit/synthesis/permutation/__init__.py +1 -0
- qiskit/synthesis/permutation/permutation_reverse_lnn.py +90 -0
- qiskit/synthesis/qft/qft_decompose_lnn.py +2 -6
- qiskit/synthesis/two_qubit/two_qubit_decompose.py +165 -954
- qiskit/synthesis/two_qubit/xx_decompose/circuits.py +13 -12
- qiskit/synthesis/two_qubit/xx_decompose/decomposer.py +7 -1
- qiskit/synthesis/unitary/aqc/__init__.py +1 -1
- qiskit/synthesis/unitary/aqc/cnot_structures.py +2 -1
- qiskit/synthesis/unitary/aqc/fast_gradient/fast_gradient.py +2 -1
- qiskit/synthesis/unitary/qsd.py +3 -2
- qiskit/transpiler/__init__.py +7 -3
- qiskit/transpiler/layout.py +140 -61
- qiskit/transpiler/passes/__init__.py +6 -0
- qiskit/transpiler/passes/basis/basis_translator.py +7 -2
- qiskit/transpiler/passes/basis/unroll_3q_or_more.py +1 -1
- qiskit/transpiler/passes/basis/unroll_custom_definitions.py +1 -1
- qiskit/transpiler/passes/calibration/rzx_builder.py +2 -1
- qiskit/transpiler/passes/layout/apply_layout.py +8 -3
- qiskit/transpiler/passes/layout/sabre_layout.py +15 -3
- qiskit/transpiler/passes/layout/set_layout.py +1 -1
- qiskit/transpiler/passes/optimization/__init__.py +2 -0
- qiskit/transpiler/passes/optimization/commutation_analysis.py +2 -2
- qiskit/transpiler/passes/optimization/commutative_cancellation.py +1 -1
- qiskit/transpiler/passes/optimization/consolidate_blocks.py +1 -1
- qiskit/transpiler/passes/optimization/cx_cancellation.py +10 -0
- qiskit/transpiler/passes/optimization/elide_permutations.py +114 -0
- qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +9 -3
- qiskit/transpiler/passes/optimization/optimize_annotated.py +248 -12
- qiskit/transpiler/passes/optimization/remove_final_reset.py +37 -0
- qiskit/transpiler/passes/optimization/template_matching/forward_match.py +1 -3
- qiskit/transpiler/passes/routing/__init__.py +1 -0
- qiskit/transpiler/passes/routing/basic_swap.py +13 -2
- qiskit/transpiler/passes/routing/lookahead_swap.py +7 -1
- qiskit/transpiler/passes/routing/sabre_swap.py +10 -6
- qiskit/transpiler/passes/routing/star_prerouting.py +417 -0
- qiskit/transpiler/passes/routing/stochastic_swap.py +24 -8
- qiskit/transpiler/passes/scheduling/__init__.py +1 -1
- qiskit/transpiler/passes/scheduling/alap.py +1 -2
- qiskit/transpiler/passes/scheduling/alignments/align_measures.py +1 -2
- qiskit/transpiler/passes/scheduling/alignments/check_durations.py +9 -6
- qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +8 -0
- qiskit/transpiler/passes/scheduling/alignments/reschedule.py +13 -4
- qiskit/transpiler/passes/scheduling/asap.py +1 -2
- qiskit/transpiler/passes/scheduling/base_scheduler.py +21 -2
- qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +26 -4
- qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +24 -2
- qiskit/transpiler/passes/scheduling/time_unit_conversion.py +28 -4
- qiskit/transpiler/passes/synthesis/aqc_plugin.py +2 -2
- qiskit/transpiler/passes/synthesis/high_level_synthesis.py +120 -13
- qiskit/transpiler/passes/synthesis/unitary_synthesis.py +162 -55
- qiskit/transpiler/passes/utils/gates_basis.py +3 -3
- qiskit/transpiler/passmanager.py +44 -1
- qiskit/transpiler/preset_passmanagers/__init__.py +3 -3
- qiskit/transpiler/preset_passmanagers/builtin_plugins.py +34 -16
- qiskit/transpiler/preset_passmanagers/common.py +4 -6
- qiskit/transpiler/preset_passmanagers/plugin.py +9 -1
- qiskit/utils/optionals.py +6 -2
- qiskit/visualization/array.py +1 -1
- qiskit/visualization/bloch.py +2 -3
- qiskit/visualization/circuit/matplotlib.py +44 -14
- qiskit/visualization/circuit/text.py +38 -18
- qiskit/visualization/counts_visualization.py +3 -6
- qiskit/visualization/dag_visualization.py +6 -7
- qiskit/visualization/pulse_v2/interface.py +8 -3
- qiskit/visualization/state_visualization.py +3 -2
- qiskit/visualization/timeline/interface.py +18 -8
- {qiskit-1.0.2.dist-info → qiskit-1.1.0rc1.dist-info}/METADATA +12 -8
- {qiskit-1.0.2.dist-info → qiskit-1.1.0rc1.dist-info}/RECORD +245 -235
- {qiskit-1.0.2.dist-info → qiskit-1.1.0rc1.dist-info}/WHEEL +1 -1
- qiskit/_qasm2.pyd +0 -0
- qiskit/_qasm3.pyd +0 -0
- {qiskit-1.0.2.dist-info → qiskit-1.1.0rc1.dist-info}/LICENSE.txt +0 -0
- {qiskit-1.0.2.dist-info → qiskit-1.1.0rc1.dist-info}/entry_points.txt +0 -0
- {qiskit-1.0.2.dist-info → qiskit-1.1.0rc1.dist-info}/top_level.txt +0 -0
@@ -14,6 +14,7 @@ Multiple-Controlled U3 gate. Not using ancillary qubits.
|
|
14
14
|
"""
|
15
15
|
|
16
16
|
from math import pi
|
17
|
+
import math
|
17
18
|
from typing import Optional, Union, Tuple, List
|
18
19
|
import numpy as np
|
19
20
|
|
@@ -123,6 +124,9 @@ def _mcsu2_real_diagonal(
|
|
123
124
|
if not is_unitary_matrix(unitary):
|
124
125
|
raise QiskitError(f"The unitary in must be an unitary matrix, but is {unitary}.")
|
125
126
|
|
127
|
+
if not np.isclose(1.0, np.linalg.det(unitary)):
|
128
|
+
raise QiskitError("Invalid Value _mcsu2_real_diagonal requires det(unitary) equal to one.")
|
129
|
+
|
126
130
|
is_main_diag_real = np.isclose(unitary[0, 0].imag, 0.0) and np.isclose(unitary[1, 1].imag, 0.0)
|
127
131
|
is_secondary_diag_real = np.isclose(unitary[0, 1].imag, 0.0) and np.isclose(
|
128
132
|
unitary[1, 0].imag, 0.0
|
@@ -141,18 +145,20 @@ def _mcsu2_real_diagonal(
|
|
141
145
|
if np.isclose(z, -1):
|
142
146
|
s_op = [[1.0, 0.0], [0.0, 1.0j]]
|
143
147
|
else:
|
144
|
-
alpha_r =
|
145
|
-
alpha_i = z.imag / (
|
148
|
+
alpha_r = math.sqrt((math.sqrt((z.real + 1.0) / 2.0) + 1.0) / 2.0)
|
149
|
+
alpha_i = z.imag / (
|
150
|
+
2.0 * math.sqrt((z.real + 1.0) * (math.sqrt((z.real + 1.0) / 2.0) + 1.0))
|
151
|
+
)
|
146
152
|
alpha = alpha_r + 1.0j * alpha_i
|
147
|
-
beta = x / (2.0 *
|
153
|
+
beta = x / (2.0 * math.sqrt((z.real + 1.0) * (math.sqrt((z.real + 1.0) / 2.0) + 1.0)))
|
148
154
|
|
149
155
|
# S gate definition
|
150
156
|
s_op = np.array([[alpha, -np.conj(beta)], [beta, np.conj(alpha)]])
|
151
157
|
|
152
158
|
s_gate = UnitaryGate(s_op)
|
153
159
|
|
154
|
-
k_1 =
|
155
|
-
k_2 =
|
160
|
+
k_1 = math.ceil(num_controls / 2.0)
|
161
|
+
k_2 = math.floor(num_controls / 2.0)
|
156
162
|
|
157
163
|
ctrl_state_k_1 = None
|
158
164
|
ctrl_state_k_2 = None
|
@@ -140,13 +140,14 @@ class PhaseGate(Gate):
|
|
140
140
|
"""
|
141
141
|
return PhaseGate(-self.params[0])
|
142
142
|
|
143
|
-
def __array__(self, dtype=None):
|
143
|
+
def __array__(self, dtype=None, copy=None):
|
144
144
|
"""Return a numpy.array for the Phase gate."""
|
145
|
+
if copy is False:
|
146
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
145
147
|
lam = float(self.params[0])
|
146
148
|
return numpy.array([[1, 0], [0, exp(1j * lam)]], dtype=dtype)
|
147
149
|
|
148
|
-
def power(self, exponent: float):
|
149
|
-
"""Raise gate to a power."""
|
150
|
+
def power(self, exponent: float, annotated: bool = False):
|
150
151
|
(theta,) = self.params
|
151
152
|
return PhaseGate(exponent * theta)
|
152
153
|
|
@@ -280,8 +281,10 @@ class CPhaseGate(ControlledGate):
|
|
280
281
|
r"""Return inverted CPhase gate (:math:`CPhase(\lambda)^{\dagger} = CPhase(-\lambda)`)"""
|
281
282
|
return CPhaseGate(-self.params[0], ctrl_state=self.ctrl_state)
|
282
283
|
|
283
|
-
def __array__(self, dtype=None):
|
284
|
+
def __array__(self, dtype=None, copy=None):
|
284
285
|
"""Return a numpy.array for the CPhase gate."""
|
286
|
+
if copy is False:
|
287
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
285
288
|
eith = exp(1j * float(self.params[0]))
|
286
289
|
if self.ctrl_state:
|
287
290
|
return numpy.array(
|
@@ -289,8 +292,7 @@ class CPhaseGate(ControlledGate):
|
|
289
292
|
)
|
290
293
|
return numpy.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, eith, 0], [0, 0, 0, 1]], dtype=dtype)
|
291
294
|
|
292
|
-
def power(self, exponent: float):
|
293
|
-
"""Raise gate to a power."""
|
295
|
+
def power(self, exponent: float, annotated: bool = False):
|
294
296
|
(theta,) = self.params
|
295
297
|
return CPhaseGate(exponent * theta)
|
296
298
|
|
@@ -333,6 +335,7 @@ class MCPhaseGate(ControlledGate):
|
|
333
335
|
lam: ParameterValueType,
|
334
336
|
num_ctrl_qubits: int,
|
335
337
|
label: str | None = None,
|
338
|
+
ctrl_state: str | int | None = None,
|
336
339
|
*,
|
337
340
|
duration=None,
|
338
341
|
unit="dt",
|
@@ -345,6 +348,7 @@ class MCPhaseGate(ControlledGate):
|
|
345
348
|
[lam],
|
346
349
|
num_ctrl_qubits=num_ctrl_qubits,
|
347
350
|
label=label,
|
351
|
+
ctrl_state=ctrl_state,
|
348
352
|
base_gate=PhaseGate(lam, label=_base_label),
|
349
353
|
duration=duration,
|
350
354
|
unit=unit,
|
@@ -354,20 +358,32 @@ class MCPhaseGate(ControlledGate):
|
|
354
358
|
# pylint: disable=cyclic-import
|
355
359
|
from qiskit.circuit.quantumcircuit import QuantumCircuit
|
356
360
|
|
357
|
-
|
358
|
-
qc = QuantumCircuit(
|
361
|
+
qr = QuantumRegister(self.num_qubits, "q")
|
362
|
+
qc = QuantumCircuit(qr, name=self.name)
|
359
363
|
|
360
364
|
if self.num_ctrl_qubits == 0:
|
361
365
|
qc.p(self.params[0], 0)
|
362
366
|
if self.num_ctrl_qubits == 1:
|
363
367
|
qc.cp(self.params[0], 0, 1)
|
364
368
|
else:
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
369
|
+
lam = self.params[0]
|
370
|
+
if type(lam) in [float, int]:
|
371
|
+
q_controls = list(range(self.num_ctrl_qubits))
|
372
|
+
q_target = self.num_ctrl_qubits
|
373
|
+
new_target = q_target
|
374
|
+
for k in range(self.num_ctrl_qubits):
|
375
|
+
qc.mcrz(lam / (2**k), q_controls, new_target, use_basis_gates=True)
|
376
|
+
new_target = q_controls.pop()
|
377
|
+
qc.p(lam / (2**self.num_ctrl_qubits), new_target)
|
378
|
+
else: # in this case type(lam) is ParameterValueType
|
379
|
+
from .u3 import _gray_code_chain
|
380
|
+
|
381
|
+
scaled_lam = self.params[0] / (2 ** (self.num_ctrl_qubits - 1))
|
382
|
+
bottom_gate = CPhaseGate(scaled_lam)
|
383
|
+
for operation, qubits, clbits in _gray_code_chain(
|
384
|
+
qr, self.num_ctrl_qubits, bottom_gate
|
385
|
+
):
|
386
|
+
qc._append(operation, qubits, clbits)
|
371
387
|
self.definition = qc
|
372
388
|
|
373
389
|
def control(
|
@@ -407,5 +423,5 @@ class MCPhaseGate(ControlledGate):
|
|
407
423
|
return gate
|
408
424
|
|
409
425
|
def inverse(self, annotated: bool = False):
|
410
|
-
r"""Return inverted
|
426
|
+
r"""Return inverted MCPhase gate (:math:`MCPhase(\lambda)^{\dagger} = MCPhase(-\lambda)`)"""
|
411
427
|
return MCPhaseGate(-self.params[0], self.num_ctrl_qubits)
|
@@ -93,8 +93,10 @@ class RGate(Gate):
|
|
93
93
|
"""
|
94
94
|
return RGate(-self.params[0], self.params[1])
|
95
95
|
|
96
|
-
def __array__(self, dtype=None):
|
96
|
+
def __array__(self, dtype=None, copy=None):
|
97
97
|
"""Return a numpy.array for the R gate."""
|
98
|
+
if copy is False:
|
99
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
98
100
|
theta, phi = float(self.params[0]), float(self.params[1])
|
99
101
|
cos = math.cos(theta / 2)
|
100
102
|
sin = math.sin(theta / 2)
|
@@ -102,8 +104,7 @@ class RGate(Gate):
|
|
102
104
|
exp_p = exp(1j * phi)
|
103
105
|
return numpy.array([[cos, -1j * exp_m * sin], [-1j * exp_p * sin, cos]], dtype=dtype)
|
104
106
|
|
105
|
-
def power(self, exponent: float):
|
106
|
-
"""Raise gate to a power."""
|
107
|
+
def power(self, exponent: float, annotated: bool = False):
|
107
108
|
theta, phi = self.params
|
108
109
|
return RGate(exponent * theta, phi)
|
109
110
|
|
@@ -120,14 +120,15 @@ class RXGate(Gate):
|
|
120
120
|
"""
|
121
121
|
return RXGate(-self.params[0])
|
122
122
|
|
123
|
-
def __array__(self, dtype=None):
|
123
|
+
def __array__(self, dtype=None, copy=None):
|
124
124
|
"""Return a numpy.array for the RX gate."""
|
125
|
+
if copy is False:
|
126
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
125
127
|
cos = math.cos(self.params[0] / 2)
|
126
128
|
sin = math.sin(self.params[0] / 2)
|
127
129
|
return numpy.array([[cos, -1j * sin], [-1j * sin, cos]], dtype=dtype)
|
128
130
|
|
129
|
-
def power(self, exponent: float):
|
130
|
-
"""Raise gate to a power."""
|
131
|
+
def power(self, exponent: float, annotated: bool = False):
|
131
132
|
(theta,) = self.params
|
132
133
|
return RXGate(exponent * theta)
|
133
134
|
|
@@ -264,8 +265,10 @@ class CRXGate(ControlledGate):
|
|
264
265
|
"""
|
265
266
|
return CRXGate(-self.params[0], ctrl_state=self.ctrl_state)
|
266
267
|
|
267
|
-
def __array__(self, dtype=None):
|
268
|
+
def __array__(self, dtype=None, copy=None):
|
268
269
|
"""Return a numpy.array for the CRX gate."""
|
270
|
+
if copy is False:
|
271
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
269
272
|
half_theta = float(self.params[0]) / 2
|
270
273
|
cos = math.cos(half_theta)
|
271
274
|
isin = 1j * math.sin(half_theta)
|
@@ -122,8 +122,10 @@ class RXXGate(Gate):
|
|
122
122
|
"""
|
123
123
|
return RXXGate(-self.params[0])
|
124
124
|
|
125
|
-
def __array__(self, dtype=None):
|
125
|
+
def __array__(self, dtype=None, copy=None):
|
126
126
|
"""Return a Numpy.array for the RXX gate."""
|
127
|
+
if copy is False:
|
128
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
127
129
|
theta2 = float(self.params[0]) / 2
|
128
130
|
cos = math.cos(theta2)
|
129
131
|
isin = 1j * math.sin(theta2)
|
@@ -132,8 +134,7 @@ class RXXGate(Gate):
|
|
132
134
|
dtype=dtype,
|
133
135
|
)
|
134
136
|
|
135
|
-
def power(self, exponent: float):
|
136
|
-
"""Raise gate to a power."""
|
137
|
+
def power(self, exponent: float, annotated: bool = False):
|
137
138
|
(theta,) = self.params
|
138
139
|
return RXXGate(exponent * theta)
|
139
140
|
|
@@ -119,14 +119,15 @@ class RYGate(Gate):
|
|
119
119
|
"""
|
120
120
|
return RYGate(-self.params[0])
|
121
121
|
|
122
|
-
def __array__(self, dtype=None):
|
122
|
+
def __array__(self, dtype=None, copy=None):
|
123
123
|
"""Return a numpy.array for the RY gate."""
|
124
|
+
if copy is False:
|
125
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
124
126
|
cos = math.cos(self.params[0] / 2)
|
125
127
|
sin = math.sin(self.params[0] / 2)
|
126
128
|
return numpy.array([[cos, -sin], [sin, cos]], dtype=dtype)
|
127
129
|
|
128
|
-
def power(self, exponent: float):
|
129
|
-
"""Raise gate to a power."""
|
130
|
+
def power(self, exponent: float, annotated: bool = False):
|
130
131
|
(theta,) = self.params
|
131
132
|
return RYGate(exponent * theta)
|
132
133
|
|
@@ -259,8 +260,10 @@ class CRYGate(ControlledGate):
|
|
259
260
|
."""
|
260
261
|
return CRYGate(-self.params[0], ctrl_state=self.ctrl_state)
|
261
262
|
|
262
|
-
def __array__(self, dtype=None):
|
263
|
+
def __array__(self, dtype=None, copy=None):
|
263
264
|
"""Return a numpy.array for the CRY gate."""
|
265
|
+
if copy is False:
|
266
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
264
267
|
half_theta = float(self.params[0]) / 2
|
265
268
|
cos = math.cos(half_theta)
|
266
269
|
sin = math.sin(half_theta)
|
@@ -122,8 +122,10 @@ class RYYGate(Gate):
|
|
122
122
|
"""
|
123
123
|
return RYYGate(-self.params[0])
|
124
124
|
|
125
|
-
def __array__(self, dtype=None):
|
125
|
+
def __array__(self, dtype=None, copy=None):
|
126
126
|
"""Return a numpy.array for the RYY gate."""
|
127
|
+
if copy is False:
|
128
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
127
129
|
theta = float(self.params[0])
|
128
130
|
cos = math.cos(theta / 2)
|
129
131
|
isin = 1j * math.sin(theta / 2)
|
@@ -132,8 +134,7 @@ class RYYGate(Gate):
|
|
132
134
|
dtype=dtype,
|
133
135
|
)
|
134
136
|
|
135
|
-
def power(self, exponent: float):
|
136
|
-
"""Raise gate to a power."""
|
137
|
+
def power(self, exponent: float, annotated: bool = False):
|
137
138
|
(theta,) = self.params
|
138
139
|
return RYYGate(exponent * theta)
|
139
140
|
|
@@ -130,15 +130,16 @@ class RZGate(Gate):
|
|
130
130
|
"""
|
131
131
|
return RZGate(-self.params[0])
|
132
132
|
|
133
|
-
def __array__(self, dtype=None):
|
133
|
+
def __array__(self, dtype=None, copy=None):
|
134
134
|
"""Return a numpy.array for the RZ gate."""
|
135
135
|
import numpy as np
|
136
136
|
|
137
|
+
if copy is False:
|
138
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
137
139
|
ilam2 = 0.5j * float(self.params[0])
|
138
140
|
return np.array([[exp(-ilam2), 0], [0, exp(ilam2)]], dtype=dtype)
|
139
141
|
|
140
|
-
def power(self, exponent: float):
|
141
|
-
"""Raise gate to a power."""
|
142
|
+
def power(self, exponent: float, annotated: bool = False):
|
142
143
|
(theta,) = self.params
|
143
144
|
return RZGate(exponent * theta)
|
144
145
|
|
@@ -277,10 +278,12 @@ class CRZGate(ControlledGate):
|
|
277
278
|
"""
|
278
279
|
return CRZGate(-self.params[0], ctrl_state=self.ctrl_state)
|
279
280
|
|
280
|
-
def __array__(self, dtype=None):
|
281
|
+
def __array__(self, dtype=None, copy=None):
|
281
282
|
"""Return a numpy.array for the CRZ gate."""
|
282
283
|
import numpy
|
283
284
|
|
285
|
+
if copy is False:
|
286
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
284
287
|
arg = 1j * float(self.params[0]) / 2
|
285
288
|
if self.ctrl_state:
|
286
289
|
return numpy.array(
|
@@ -166,10 +166,12 @@ class RZXGate(Gate):
|
|
166
166
|
"""
|
167
167
|
return RZXGate(-self.params[0])
|
168
168
|
|
169
|
-
def __array__(self, dtype=None):
|
169
|
+
def __array__(self, dtype=None, copy=None):
|
170
170
|
"""Return a numpy.array for the RZX gate."""
|
171
171
|
import numpy
|
172
172
|
|
173
|
+
if copy is False:
|
174
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
173
175
|
half_theta = float(self.params[0]) / 2
|
174
176
|
cos = math.cos(half_theta)
|
175
177
|
isin = 1j * math.sin(half_theta)
|
@@ -178,8 +180,7 @@ class RZXGate(Gate):
|
|
178
180
|
dtype=dtype,
|
179
181
|
)
|
180
182
|
|
181
|
-
def power(self, exponent: float):
|
182
|
-
"""Raise gate to a power."""
|
183
|
+
def power(self, exponent: float, annotated: bool = False):
|
183
184
|
(theta,) = self.params
|
184
185
|
return RZXGate(exponent * theta)
|
185
186
|
|
@@ -130,10 +130,12 @@ class RZZGate(Gate):
|
|
130
130
|
"""
|
131
131
|
return RZZGate(-self.params[0])
|
132
132
|
|
133
|
-
def __array__(self, dtype=None):
|
133
|
+
def __array__(self, dtype=None, copy=None):
|
134
134
|
"""Return a numpy.array for the RZZ gate."""
|
135
135
|
import numpy
|
136
136
|
|
137
|
+
if copy is False:
|
138
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
137
139
|
itheta2 = 1j * float(self.params[0]) / 2
|
138
140
|
return numpy.array(
|
139
141
|
[
|
@@ -145,8 +147,7 @@ class RZZGate(Gate):
|
|
145
147
|
dtype=dtype,
|
146
148
|
)
|
147
149
|
|
148
|
-
def power(self, exponent: float):
|
149
|
-
"""Raise gate to a power."""
|
150
|
+
def power(self, exponent: float, annotated: bool = False):
|
150
151
|
(theta,) = self.params
|
151
152
|
return RZZGate(exponent * theta)
|
152
153
|
|
@@ -94,8 +94,7 @@ class SGate(SingletonGate):
|
|
94
94
|
"""
|
95
95
|
return SdgGate()
|
96
96
|
|
97
|
-
def power(self, exponent: float):
|
98
|
-
"""Raise gate to a power."""
|
97
|
+
def power(self, exponent: float, annotated: bool = False):
|
99
98
|
from .p import PhaseGate
|
100
99
|
|
101
100
|
return PhaseGate(0.5 * numpy.pi * exponent)
|
@@ -172,8 +171,7 @@ class SdgGate(SingletonGate):
|
|
172
171
|
"""
|
173
172
|
return SGate()
|
174
173
|
|
175
|
-
def power(self, exponent: float):
|
176
|
-
"""Raise gate to a power."""
|
174
|
+
def power(self, exponent: float, annotated: bool = False):
|
177
175
|
from .p import PhaseGate
|
178
176
|
|
179
177
|
return PhaseGate(-0.5 * numpy.pi * exponent)
|
@@ -259,8 +257,7 @@ class CSGate(SingletonControlledGate):
|
|
259
257
|
"""
|
260
258
|
return CSdgGate(ctrl_state=self.ctrl_state)
|
261
259
|
|
262
|
-
def power(self, exponent: float):
|
263
|
-
"""Raise gate to a power."""
|
260
|
+
def power(self, exponent: float, annotated: bool = False):
|
264
261
|
from .p import CPhaseGate
|
265
262
|
|
266
263
|
return CPhaseGate(0.5 * numpy.pi * exponent)
|
@@ -345,8 +342,7 @@ class CSdgGate(SingletonControlledGate):
|
|
345
342
|
"""
|
346
343
|
return CSGate(ctrl_state=self.ctrl_state)
|
347
344
|
|
348
|
-
def power(self, exponent: float):
|
349
|
-
"""Raise gate to a power."""
|
345
|
+
def power(self, exponent: float, annotated: bool = False):
|
350
346
|
from .p import CPhaseGate
|
351
347
|
|
352
348
|
return CPhaseGate(-0.5 * numpy.pi * exponent)
|
@@ -92,8 +92,7 @@ class TGate(SingletonGate):
|
|
92
92
|
"""
|
93
93
|
return TdgGate()
|
94
94
|
|
95
|
-
def power(self, exponent: float):
|
96
|
-
"""Raise gate to a power."""
|
95
|
+
def power(self, exponent: float, annotated: bool = False):
|
97
96
|
return PhaseGate(0.25 * numpy.pi * exponent)
|
98
97
|
|
99
98
|
def __eq__(self, other):
|
@@ -168,8 +167,7 @@ class TdgGate(SingletonGate):
|
|
168
167
|
"""
|
169
168
|
return TGate()
|
170
169
|
|
171
|
-
def power(self, exponent: float):
|
172
|
-
"""Raise gate to a power."""
|
170
|
+
def power(self, exponent: float, annotated: bool = False):
|
173
171
|
return PhaseGate(-0.25 * numpy.pi * exponent)
|
174
172
|
|
175
173
|
def __eq__(self, other):
|
@@ -11,7 +11,8 @@
|
|
11
11
|
# that they have been altered from the originals.
|
12
12
|
|
13
13
|
"""Two-pulse single-qubit gate."""
|
14
|
-
import
|
14
|
+
import cmath
|
15
|
+
import copy as _copy
|
15
16
|
import math
|
16
17
|
from cmath import exp
|
17
18
|
from typing import Optional, Union
|
@@ -135,8 +136,10 @@ class UGate(Gate):
|
|
135
136
|
)
|
136
137
|
return gate
|
137
138
|
|
138
|
-
def __array__(self, dtype=
|
139
|
+
def __array__(self, dtype=None, copy=None):
|
139
140
|
"""Return a numpy.array for the U gate."""
|
141
|
+
if copy is False:
|
142
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
140
143
|
theta, phi, lam = (float(param) for param in self.params)
|
141
144
|
cos = math.cos(theta / 2)
|
142
145
|
sin = math.sin(theta / 2)
|
@@ -145,7 +148,7 @@ class UGate(Gate):
|
|
145
148
|
[cos, -exp(1j * lam) * sin],
|
146
149
|
[exp(1j * phi) * sin, exp(1j * (phi + lam)) * cos],
|
147
150
|
],
|
148
|
-
dtype=dtype,
|
151
|
+
dtype=dtype or complex,
|
149
152
|
)
|
150
153
|
|
151
154
|
def __eq__(self, other):
|
@@ -336,15 +339,17 @@ class CUGate(ControlledGate):
|
|
336
339
|
ctrl_state=self.ctrl_state,
|
337
340
|
)
|
338
341
|
|
339
|
-
def __array__(self, dtype=None):
|
342
|
+
def __array__(self, dtype=None, copy=None):
|
340
343
|
"""Return a numpy.array for the CU gate."""
|
344
|
+
if copy is False:
|
345
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
341
346
|
theta, phi, lam, gamma = (float(param) for param in self.params)
|
342
|
-
cos =
|
343
|
-
sin =
|
344
|
-
a =
|
345
|
-
b = -
|
346
|
-
c =
|
347
|
-
d =
|
347
|
+
cos = math.cos(theta / 2)
|
348
|
+
sin = math.sin(theta / 2)
|
349
|
+
a = cmath.exp(1j * gamma) * cos
|
350
|
+
b = -cmath.exp(1j * (gamma + lam)) * sin
|
351
|
+
c = cmath.exp(1j * (gamma + phi)) * sin
|
352
|
+
d = cmath.exp(1j * (gamma + phi + lam)) * cos
|
348
353
|
if self.ctrl_state:
|
349
354
|
return numpy.array(
|
350
355
|
[[1, 0, 0, 0], [0, a, 0, b], [0, 0, 1, 0], [0, c, 0, d]], dtype=dtype
|
@@ -371,5 +376,5 @@ class CUGate(ControlledGate):
|
|
371
376
|
# assuming that `params` will be a view onto the base gate's `_params`.
|
372
377
|
memo = memo if memo is not None else {}
|
373
378
|
out = super().__deepcopy__(memo)
|
374
|
-
out._params =
|
379
|
+
out._params = _copy.deepcopy(out._params, memo)
|
375
380
|
return out
|
@@ -160,8 +160,10 @@ class U1Gate(Gate):
|
|
160
160
|
"""
|
161
161
|
return U1Gate(-self.params[0])
|
162
162
|
|
163
|
-
def __array__(self, dtype=None):
|
163
|
+
def __array__(self, dtype=None, copy=None):
|
164
164
|
"""Return a numpy.array for the U1 gate."""
|
165
|
+
if copy is False:
|
166
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
165
167
|
lam = float(self.params[0])
|
166
168
|
return numpy.array([[1, 0], [0, numpy.exp(1j * lam)]], dtype=dtype)
|
167
169
|
|
@@ -304,8 +306,10 @@ class CU1Gate(ControlledGate):
|
|
304
306
|
"""
|
305
307
|
return CU1Gate(-self.params[0], ctrl_state=self.ctrl_state)
|
306
308
|
|
307
|
-
def __array__(self, dtype=None):
|
309
|
+
def __array__(self, dtype=None, copy=None):
|
308
310
|
"""Return a numpy.array for the CU1 gate."""
|
311
|
+
if copy is False:
|
312
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
309
313
|
eith = exp(1j * float(self.params[0]))
|
310
314
|
if self.ctrl_state:
|
311
315
|
return numpy.array(
|
@@ -127,8 +127,10 @@ class U2Gate(Gate):
|
|
127
127
|
"""
|
128
128
|
return U2Gate(-self.params[1] - pi, -self.params[0] + pi)
|
129
129
|
|
130
|
-
def __array__(self, dtype=
|
130
|
+
def __array__(self, dtype=None, copy=None):
|
131
131
|
"""Return a Numpy.array for the U2 gate."""
|
132
|
+
if copy is False:
|
133
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
132
134
|
isqrt2 = 1 / sqrt(2)
|
133
135
|
phi, lam = self.params
|
134
136
|
phi, lam = float(phi), float(lam)
|
@@ -137,5 +139,5 @@ class U2Gate(Gate):
|
|
137
139
|
[isqrt2, -exp(1j * lam) * isqrt2],
|
138
140
|
[exp(1j * phi) * isqrt2, exp(1j * (phi + lam)) * isqrt2],
|
139
141
|
],
|
140
|
-
dtype=dtype,
|
142
|
+
dtype=dtype or complex,
|
141
143
|
)
|
@@ -149,8 +149,10 @@ class U3Gate(Gate):
|
|
149
149
|
qc.u(self.params[0], self.params[1], self.params[2], 0)
|
150
150
|
self.definition = qc
|
151
151
|
|
152
|
-
def __array__(self, dtype=
|
152
|
+
def __array__(self, dtype=None, copy=None):
|
153
153
|
"""Return a Numpy.array for the U3 gate."""
|
154
|
+
if copy is False:
|
155
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
154
156
|
theta, phi, lam = self.params
|
155
157
|
theta, phi, lam = float(theta), float(phi), float(lam)
|
156
158
|
cos = math.cos(theta / 2)
|
@@ -160,7 +162,7 @@ class U3Gate(Gate):
|
|
160
162
|
[cos, -exp(1j * lam) * sin],
|
161
163
|
[exp(1j * phi) * sin, exp(1j * (phi + lam)) * cos],
|
162
164
|
],
|
163
|
-
dtype=dtype,
|
165
|
+
dtype=dtype or complex,
|
164
166
|
)
|
165
167
|
|
166
168
|
|
@@ -305,8 +307,10 @@ class CU3Gate(ControlledGate):
|
|
305
307
|
-self.params[0], -self.params[2], -self.params[1], ctrl_state=self.ctrl_state
|
306
308
|
)
|
307
309
|
|
308
|
-
def __array__(self, dtype=
|
310
|
+
def __array__(self, dtype=None, copy=None):
|
309
311
|
"""Return a numpy.array for the CU3 gate."""
|
312
|
+
if copy is False:
|
313
|
+
raise ValueError("unable to avoid copy while creating an array as requested")
|
310
314
|
theta, phi, lam = self.params
|
311
315
|
theta, phi, lam = float(theta), float(phi), float(lam)
|
312
316
|
cos = math.cos(theta / 2)
|
@@ -319,7 +323,7 @@ class CU3Gate(ControlledGate):
|
|
319
323
|
[0, 0, 1, 0],
|
320
324
|
[0, exp(1j * phi) * sin, 0, exp(1j * (phi + lam)) * cos],
|
321
325
|
],
|
322
|
-
dtype=dtype,
|
326
|
+
dtype=dtype or complex,
|
323
327
|
)
|
324
328
|
else:
|
325
329
|
return numpy.array(
|
@@ -329,7 +333,7 @@ class CU3Gate(ControlledGate):
|
|
329
333
|
[exp(1j * phi) * sin, 0, exp(1j * (phi + lam)) * cos, 0],
|
330
334
|
[0, 0, 0, 1],
|
331
335
|
],
|
332
|
-
dtype=dtype,
|
336
|
+
dtype=dtype or complex,
|
333
337
|
)
|
334
338
|
|
335
339
|
|