mirror of https://github.com/Qiskit/qiskit.git
Fix all Sphinx warnings and treat warnings as failures (#3902)
* Start fixing sphinx warnings Sphinx warnings almost always indicate a docs bug or formatting issue. Having a docs build without any warnings is important to ensure the compiled output from sphinx is as expected. This commit starts the process of fixing the ~430 warnings emitted by the terra docs. Once all the warnings are fixed this will add '-W' to the sphinx build command so that any future warnings introduced into the docs will cause a failure. * More warning fixes * Fix name 'Command' is not defined warnings * Fix 'SchedStyle' and 'Pulse' warnings * More warning fixes * More warnings fixes * Fix some warnings * Fix More pulse module warnings * Fix Pulse Lint errors * Last warning fixes outside release notes This commit fixes the last warnings emitted by the build except for release notes warnings. * Attempt to fix release note warning * Fix lints * Fix warning in quantum info * Fix reno warnings * Fix lint * Set -W on sphinx build in docs job * Fix missing indent * Ignore cyclic import in scheduler * Revert "Ignore cyclic import in scheduler" This reverts commite3cb2f40e0
. * Ignore cyclic-import in scheduler tests * Trying to fix cyclic errors * Fix import errors * Revert "Trying to fix cyclic errors" This reverts commit22709cf75c
. * Revert "Revert "Trying to fix cyclic errors"" This reverts commit3132258e37
. * Trying to fix cyclic errors of qiskit/pulse/commands/instruction.py * Try to disable cyclic import lint failures * Fix stray \ket{} usage * Update qiskit/circuit/quantumcircuit.py Co-Authored-By: Kevin Krsulich <kevin@krsulich.net> * Update Statevector.from_label to use list-table Co-authored-by: SooluThomas <soolu.elto@gmail.com> Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
This commit is contained in:
parent
1ec9f43eea
commit
fc9c8f7fa5
|
@ -215,7 +215,7 @@ stages:
|
|||
sudo apt install -y graphviz
|
||||
displayName: 'Install dependencies'
|
||||
- bash: |
|
||||
tox -edocs -- -j auto
|
||||
tox -edocs
|
||||
displayName: 'Run Docs build'
|
||||
- task: PublishBuildArtifacts@1
|
||||
displayName: 'Publish docs'
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
.. module:: qiskit
|
||||
|
||||
==========================
|
||||
Qiskit Terra API Reference
|
||||
==========================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
circuit
|
||||
compiler
|
||||
execute
|
||||
visualization
|
||||
converters
|
||||
assembler
|
||||
dagcircuit
|
||||
extensions
|
||||
providers_basicaer
|
||||
providers
|
||||
providers_models
|
||||
pulse
|
||||
scheduler
|
||||
qasm
|
||||
qobj
|
||||
quantum_info
|
||||
result
|
||||
tools
|
||||
tools_jupyter
|
||||
transpiler
|
||||
transpiler_passes
|
||||
transpiler_preset
|
||||
validation
|
||||
visualization
|
|
@ -29,7 +29,6 @@ class ControlledGate(Gate):
|
|||
|
||||
Attributes:
|
||||
num_ctrl_qubits (int): The number of control qubits.
|
||||
ctrl_state (int): The control state in decimal notation.
|
||||
|
||||
Args:
|
||||
name (str): The Qobj name of the gate.
|
||||
|
|
|
@ -247,7 +247,7 @@ class Instruction:
|
|||
It does not invert any gate.
|
||||
|
||||
Returns:
|
||||
Instruction: a fresh gate with sub-gates reversed
|
||||
qiskit.circuit.Instruction: a fresh gate with sub-gates reversed
|
||||
"""
|
||||
if not self._definition:
|
||||
return self.copy()
|
||||
|
@ -268,7 +268,7 @@ class Instruction:
|
|||
implement their own inverse (e.g. T and Tdg, Barrier, etc.)
|
||||
|
||||
Returns:
|
||||
Instruction: a fresh instruction for the inverse
|
||||
qiskit.circuit.Instruction: a fresh instruction for the inverse
|
||||
|
||||
Raises:
|
||||
CircuitError: if the instruction is not composite
|
||||
|
@ -300,7 +300,7 @@ class Instruction:
|
|||
if None then the name stays the same.
|
||||
|
||||
Returns:
|
||||
Instruction: a shallow copy of the current instruction, with the name
|
||||
qiskit.circuit.Instruction: a shallow copy of the current instruction, with the name
|
||||
updated if it was provided
|
||||
"""
|
||||
cpy = copy.copy(self)
|
||||
|
@ -366,7 +366,7 @@ class Instruction:
|
|||
n (int): Number of times to repeat the instruction
|
||||
|
||||
Returns:
|
||||
Instruction: Containing the definition.
|
||||
qiskit.circuit.Instruction: Containing the definition.
|
||||
|
||||
Raises:
|
||||
CircuitError: If n < 1.
|
||||
|
|
|
@ -444,12 +444,12 @@ class QuantumCircuit:
|
|||
the circuit in place. Expands qargs and cargs.
|
||||
|
||||
Args:
|
||||
instruction (Instruction or Operation): Instruction instance to append
|
||||
instruction (qiskit.circuit.Instruction): Instruction instance to append
|
||||
qargs (list(argument)): qubits to attach instruction to
|
||||
cargs (list(argument)): clbits to attach instruction to
|
||||
|
||||
Returns:
|
||||
Instruction: a handle to the instruction that was just added
|
||||
qiskit.circuit.Instruction: a handle to the instruction that was just added
|
||||
"""
|
||||
# Convert input to instruction
|
||||
if not isinstance(instruction, Instruction) and hasattr(instruction, 'to_instruction'):
|
||||
|
@ -578,7 +578,7 @@ class QuantumCircuit:
|
|||
parameterize the instruction.
|
||||
|
||||
Returns:
|
||||
Instruction: a composite instruction encapsulating this circuit
|
||||
qiskit.circuit.Instruction: a composite instruction encapsulating this circuit
|
||||
(can be decomposed back)
|
||||
"""
|
||||
from qiskit.converters.circuit_to_instruction import circuit_to_instruction
|
||||
|
|
|
@ -62,61 +62,60 @@ def transpile(circuits: Union[QuantumCircuit, List[QuantumCircuit]],
|
|||
will override the backend's.
|
||||
|
||||
.. note::
|
||||
|
||||
The backend arg is purely for convenience. The resulting
|
||||
circuit may be run on any backend as long as it is compatible.
|
||||
basis_gates: List of basis gate names to unroll to.
|
||||
e.g::
|
||||
['u1', 'u2', 'u3', 'cx']
|
||||
If ``None``, do not unroll.
|
||||
basis_gates: List of basis gate names to unroll to
|
||||
(e.g: ``['u1', 'u2', 'u3', 'cx']``). If ``None``, do not unroll.
|
||||
coupling_map: Coupling map (perhaps custom) to target in mapping.
|
||||
Multiple formats are supported:
|
||||
1. ``CouplingMap`` instance
|
||||
2. List
|
||||
Must be given as an adjacency matrix, where each entry
|
||||
specifies all two-qubit interactions supported by backend,
|
||||
e.g::
|
||||
[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]]
|
||||
|
||||
#. ``CouplingMap`` instance
|
||||
#. List, must be given as an adjacency matrix, where each entry
|
||||
specifies all two-qubit interactions supported by backend,
|
||||
e.g: ``[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]]``
|
||||
|
||||
backend_properties: properties returned by a backend, including information on gate
|
||||
errors, readout errors, qubit coherence times, etc. Find a backend
|
||||
that provides this information with: ``backend.properties()``
|
||||
initial_layout: Initial position of virtual qubits on physical qubits.
|
||||
If this layout makes the circuit compatible with the coupling_map
|
||||
constraints, it will be used.
|
||||
The final layout is not guaranteed to be the same, as the transpiler
|
||||
may permute qubits through swaps or other means.
|
||||
constraints, it will be used. The final layout is not guaranteed to be the same,
|
||||
as the transpiler may permute qubits through swaps or other means.
|
||||
Multiple formats are supported:
|
||||
|
||||
1. ``Layout`` instance
|
||||
|
||||
2. Dict
|
||||
|
||||
* virtual to physical::
|
||||
#. ``Layout`` instance
|
||||
#. Dict
|
||||
* virtual to physical::
|
||||
|
||||
{qr[0]: 0,
|
||||
qr[1]: 3,
|
||||
qr[2]: 5}
|
||||
|
||||
* physical to virtual::
|
||||
* physical to virtual::
|
||||
|
||||
{0: qr[0],
|
||||
3: qr[1],
|
||||
5: qr[2]}
|
||||
3. List
|
||||
|
||||
* virtual to physical::
|
||||
#. List
|
||||
|
||||
* virtual to physical::
|
||||
|
||||
[0, 3, 5] # virtual qubits are ordered (in addition to named)
|
||||
* physical to virtual::
|
||||
|
||||
* physical to virtual::
|
||||
|
||||
[qr[0], None, None, qr[1], None, qr[2]]
|
||||
|
||||
seed_transpiler: Sets random seed for the stochastic parts of the transpiler
|
||||
optimization_level: How much optimization to perform on the circuits.
|
||||
Higher levels generate more optimized circuits,
|
||||
at the expense of longer transpilation time.
|
||||
* 0: no optimization
|
||||
* 1: light optimization
|
||||
* 2: heavy optimization
|
||||
* 3: even heavier optimization
|
||||
* 0: no optimization
|
||||
* 1: light optimization
|
||||
* 2: heavy optimization
|
||||
* 3: even heavier optimization
|
||||
If ``None``, level 1 will be chosen as default.
|
||||
pass_manager: The pass manager to use for a custom pipeline of transpiler passes.
|
||||
If this arg is present, all other args will be ignored and the
|
||||
|
@ -125,17 +124,18 @@ def transpile(circuits: Union[QuantumCircuit, List[QuantumCircuit]],
|
|||
callback: A callback function that will be called after each
|
||||
pass execution. The function will be called with 5 keyword
|
||||
arguments,
|
||||
| ``pass_``: the pass being run.
|
||||
| ``dag``: the dag output of the pass.
|
||||
| ``time``: the time to execute the pass.
|
||||
| ``property_set``: the property set.
|
||||
| ``count``: the index for the pass execution.
|
||||
| ``pass_``: the pass being run.
|
||||
| ``dag``: the dag output of the pass.
|
||||
| ``time``: the time to execute the pass.
|
||||
| ``property_set``: the property set.
|
||||
| ``count``: the index for the pass execution.
|
||||
The exact arguments passed expose the internals of the pass manager,
|
||||
and are subject to change as the pass manager internals change. If
|
||||
you intend to reuse a callback function over multiple releases, be
|
||||
sure to check that the arguments being passed are the same.
|
||||
To use the callback feature, define a function that will
|
||||
take in kwargs dict and access the variables. For example::
|
||||
|
||||
def callback_func(**kwargs):
|
||||
pass_ = kwargs['pass_']
|
||||
dag = kwargs['dag']
|
||||
|
@ -144,6 +144,7 @@ def transpile(circuits: Union[QuantumCircuit, List[QuantumCircuit]],
|
|||
count = kwargs['count']
|
||||
...
|
||||
transpile(circ, callback=callback_func)
|
||||
|
||||
output_name: A list with strings to identify the output circuits. The length of
|
||||
the list should be exactly the length of the ``circuits`` parameter.
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ def circuit_to_instruction(circuit, parameter_map=None):
|
|||
QiskitError: if parameter_map is not compatible with circuit
|
||||
|
||||
Return:
|
||||
Instruction: an instruction equivalent to the action of the
|
||||
qiskit.circuit.Instruction: an instruction equivalent to the action of the
|
||||
input circuit. Upon decomposition, this instruction will
|
||||
yield the components comprising the original circuit.
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ class DAGCircuit:
|
|||
"""Add a new operation node to the graph and assign properties.
|
||||
|
||||
Args:
|
||||
op (Instruction): the operation associated with the DAG node
|
||||
op (qiskit.circuit.Instruction): the operation associated with the DAG node
|
||||
qargs (list[Qubit]): list of quantum wires to attach to.
|
||||
cargs (list[Clbit]): list of classical wires to attach to.
|
||||
condition (tuple or None): optional condition (ClassicalRegister, int)
|
||||
|
@ -240,7 +240,7 @@ class DAGCircuit:
|
|||
"""Apply an operation to the output of the circuit.
|
||||
|
||||
Args:
|
||||
op (Instruction): the operation associated with the DAG node
|
||||
op (qiskit.circuit.Instruction): the operation associated with the DAG node
|
||||
qargs (list[Qubit]): qubits that op will be applied to
|
||||
cargs (list[Clbit]): cbits that op will be applied to
|
||||
condition (tuple or None): optional condition (ClassicalRegister, int)
|
||||
|
@ -286,7 +286,7 @@ class DAGCircuit:
|
|||
"""Apply an operation to the input of the circuit.
|
||||
|
||||
Args:
|
||||
op (Instruction): the operation associated with the DAG node
|
||||
op (qiskit.circuit.Instruction): the operation associated with the DAG node
|
||||
qargs (list[Qubit]): qubits that op will be applied to
|
||||
cargs (list[Clbit]): cbits that op will be applied to
|
||||
condition (tuple or None): optional condition (ClassicalRegister, value)
|
||||
|
@ -860,7 +860,8 @@ class DAGCircuit:
|
|||
|
||||
Args:
|
||||
node (DAGNode): Node to be replaced
|
||||
op (Instruction): The Instruction instance to be added to the DAG
|
||||
op (qiskit.circuit.Instruction): The :class:`qiskit.circuit.Instruction`
|
||||
instance to be added to the DAG
|
||||
inplace (bool): Optional, default False. If True, existing DAG node
|
||||
will be modified to include op. Otherwise, a new DAG node will
|
||||
be used.
|
||||
|
@ -944,8 +945,8 @@ class DAGCircuit:
|
|||
"""Get the list of "op" nodes in the dag.
|
||||
|
||||
Args:
|
||||
op (Type): Instruction subclass op nodes to return. if op=None, return
|
||||
all op nodes.
|
||||
op (Type): :class:`qiskit.circuit.Instruction` subclass op nodes to return.
|
||||
if op=None, return all op nodes.
|
||||
Returns:
|
||||
list[DAGNode]: the list of node ids containing the given op.
|
||||
"""
|
||||
|
|
|
@ -57,20 +57,18 @@ def execute(experiments, backend,
|
|||
|
||||
basis_gates (list[str]):
|
||||
List of basis gate names to unroll to.
|
||||
e.g:
|
||||
['u1', 'u2', 'u3', 'cx']
|
||||
If None, do not unroll.
|
||||
e.g: ``['u1', 'u2', 'u3', 'cx']``
|
||||
If ``None``, do not unroll.
|
||||
|
||||
coupling_map (CouplingMap or list):
|
||||
Coupling map (perhaps custom) to target in mapping.
|
||||
Multiple formats are supported:
|
||||
a. CouplingMap instance
|
||||
coupling_map (CouplingMap or list): Coupling map (perhaps custom) to
|
||||
target in mapping. Multiple formats are supported:
|
||||
|
||||
b. list
|
||||
Must be given as an adjacency matrix, where each entry
|
||||
specifies all two-qubit interactions supported by backend
|
||||
e.g:
|
||||
[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]]
|
||||
#. CouplingMap instance
|
||||
#. list
|
||||
Must be given as an adjacency matrix, where each entry
|
||||
specifies all two-qubit interactions supported by backend
|
||||
e.g:
|
||||
``[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]]``
|
||||
|
||||
backend_properties (BackendProperties):
|
||||
Properties returned by a backend, including information on gate
|
||||
|
@ -86,105 +84,96 @@ def execute(experiments, backend,
|
|||
may permute qubits through swaps or other means.
|
||||
|
||||
Multiple formats are supported:
|
||||
a. Layout instance
|
||||
|
||||
b. dict
|
||||
virtual to physical:
|
||||
#. :class:`qiskit.transpiler.Layout` instance
|
||||
#. ``dict``:
|
||||
virtual to physical::
|
||||
|
||||
{qr[0]: 0,
|
||||
qr[1]: 3,
|
||||
qr[2]: 5}
|
||||
|
||||
physical to virtual:
|
||||
physical to virtual::
|
||||
{0: qr[0],
|
||||
3: qr[1],
|
||||
5: qr[2]}
|
||||
|
||||
c. list
|
||||
virtual to physical:
|
||||
#. ``list``
|
||||
virtual to physical::
|
||||
|
||||
[0, 3, 5] # virtual qubits are ordered (in addition to named)
|
||||
|
||||
physical to virtual:
|
||||
physical to virtual::
|
||||
|
||||
[qr[0], None, None, qr[1], None, qr[2]]
|
||||
|
||||
seed_transpiler (int):
|
||||
Sets random seed for the stochastic parts of the transpiler
|
||||
seed_transpiler (int): Sets random seed for the stochastic parts of the transpiler
|
||||
|
||||
optimization_level (int):
|
||||
How much optimization to perform on the circuits.
|
||||
optimization_level (int): How much optimization to perform on the circuits.
|
||||
Higher levels generate more optimized circuits,
|
||||
at the expense of longer transpilation time.
|
||||
0: No optimization
|
||||
1: Light optimization
|
||||
2: Heavy optimization
|
||||
3: Highest optimization
|
||||
#. No optimization
|
||||
#. Light optimization
|
||||
#. Heavy optimization
|
||||
#. Highest optimization
|
||||
If None, level 1 will be chosen as default.
|
||||
|
||||
pass_manager (PassManager):
|
||||
The pass manager to use during transpilation. If this arg is present,
|
||||
auto-selection of pass manager based on the transpile options will be
|
||||
turned off and this pass manager will be used directly.
|
||||
pass_manager (PassManager): The pass manager to use during transpilation. If this
|
||||
arg is present, auto-selection of pass manager based on the transpile options
|
||||
will be turned off and this pass manager will be used directly.
|
||||
|
||||
qobj_id (str):
|
||||
String identifier to annotate the Qobj
|
||||
qobj_id (str): String identifier to annotate the Qobj
|
||||
|
||||
qobj_header (QobjHeader or dict):
|
||||
User input that will be inserted in Qobj header, and will also be
|
||||
copied to the corresponding Result header. Headers do not affect the run.
|
||||
qobj_header (QobjHeader or dict): User input that will be inserted in Qobj header,
|
||||
and will also be copied to the corresponding :class:`qiskit.result.Result`
|
||||
header. Headers do not affect the run.
|
||||
|
||||
shots (int):
|
||||
Number of repetitions of each circuit, for sampling. Default: 1024
|
||||
shots (int): Number of repetitions of each circuit, for sampling. Default: 1024
|
||||
|
||||
memory (bool):
|
||||
If True, per-shot measurement bitstrings are returned as well
|
||||
memory (bool): If True, per-shot measurement bitstrings are returned as well
|
||||
(provided the backend supports it). For OpenPulse jobs, only
|
||||
measurement level 2 supports this option. Default: False
|
||||
|
||||
max_credits (int):
|
||||
Maximum credits to spend on job. Default: 10
|
||||
max_credits (int): Maximum credits to spend on job. Default: 10
|
||||
|
||||
seed_simulator (int):
|
||||
Random seed to control sampling, for when backend is a simulator
|
||||
seed_simulator (int): Random seed to control sampling, for when backend is a simulator
|
||||
|
||||
default_qubit_los (list):
|
||||
List of default qubit LO frequencies in Hz
|
||||
default_qubit_los (list): List of default qubit LO frequencies in Hz
|
||||
|
||||
default_meas_los (list):
|
||||
List of default meas LO frequencies in Hz
|
||||
default_meas_los (list): List of default meas LO frequencies in Hz
|
||||
|
||||
schedule_los (None or list[Union[Dict[PulseChannel, float], LoConfig]] or \
|
||||
Union[Dict[PulseChannel, float], LoConfig]):
|
||||
Experiment LO configurations
|
||||
schedule_los (None or list or dict or LoConfig): Experiment LO
|
||||
configurations, if specified the list is in the format::
|
||||
|
||||
meas_level (int or MeasLevel):
|
||||
Set the appropriate level of the measurement output for pulse experiments.
|
||||
list[Union[Dict[PulseChannel, float], LoConfig]] or
|
||||
Union[Dict[PulseChannel, float], LoConfig]
|
||||
|
||||
meas_return (str or MeasReturn):
|
||||
Level of measurement data for the backend to return
|
||||
For `meas_level` 0 and 1:
|
||||
"single" returns information from every shot.
|
||||
"avg" returns average measurement output (averaged over number of shots).
|
||||
meas_level (int or MeasLevel): Set the appropriate level of the
|
||||
measurement output for pulse experiments.
|
||||
|
||||
memory_slots (int):
|
||||
Number of classical memory slots used in this job.
|
||||
meas_return (str or MeasReturn): Level of measurement data for the
|
||||
backend to return For ``meas_level`` 0 and 1:
|
||||
``"single"`` returns information from every shot.
|
||||
``"avg"`` returns average measurement output (averaged over number
|
||||
of shots).
|
||||
|
||||
memory_slot_size (int):
|
||||
Size of each memory slot if the output is Level 0.
|
||||
memory_slots (int): Number of classical memory slots used in this job.
|
||||
|
||||
memory_slot_size (int): Size of each memory slot if the output is Level 0.
|
||||
|
||||
rep_time (int): repetition time of the experiment in μs.
|
||||
The delay between experiments will be rep_time.
|
||||
Must be from the list provided by the device.
|
||||
|
||||
parameter_binds (list[dict]):
|
||||
List of Parameter bindings over which the set of experiments will be
|
||||
executed. Each list element (bind) should be of the form
|
||||
{Parameter1: value1, Parameter2: value2, ...}. All binds will be
|
||||
parameter_binds (list[dict]): List of Parameter bindings over which the set of
|
||||
experiments will be executed. Each list element (bind) should be of the form
|
||||
``{Parameter1: value1, Parameter2: value2, ...}``. All binds will be
|
||||
executed across all experiments, e.g. if parameter_binds is a
|
||||
length-n list, and there are m experiments, a total of m x n
|
||||
length-n list, and there are m experiments, a total of :math:`m x n`
|
||||
experiments will be run (one for each experiment/bind pair).
|
||||
|
||||
schedule_circuit (bool):
|
||||
If ``True``, ``experiments`` will be converted to ``Schedule``s prior to
|
||||
execution.
|
||||
schedule_circuit (bool): If ``True``, ``experiments`` will be converted to
|
||||
:class:`qiskit.pulse.Schedule` objects prior to execution.
|
||||
|
||||
inst_map (InstructionScheduleMap):
|
||||
Mapping of circuit operations to pulse schedules. If None, defaults to the
|
||||
|
|
|
@ -49,7 +49,6 @@ Standard Extensions
|
|||
SdgGate
|
||||
SwapGate
|
||||
TdgGate
|
||||
U0Gate
|
||||
U1Gate
|
||||
U2Gate
|
||||
U3Gate
|
||||
|
|
|
@ -87,12 +87,10 @@ class Initialize(Instruction):
|
|||
self.definition = initialize_circuit.data
|
||||
|
||||
def gates_to_uncompute(self):
|
||||
"""
|
||||
Call to create a circuit with gates that take the
|
||||
desired vector to zero.
|
||||
"""Call to create a circuit with gates that take the desired vector to zero.
|
||||
|
||||
Returns:
|
||||
QuantumCircuit: circuit to take self.params vector to |00..0>
|
||||
QuantumCircuit: circuit to take self.params vector to :math:`|{00\\ldots0}\\rangle`
|
||||
"""
|
||||
q = QuantumRegister(self.num_qubits)
|
||||
circuit = QuantumCircuit(q, name='disentangler')
|
||||
|
|
|
@ -61,13 +61,13 @@ def ucrx(self, angle_list, q_controls, q_target):
|
|||
The decomposition is base on https://arxiv.org/pdf/quant-ph/0406176.pdf by Shende et al.
|
||||
|
||||
Args:
|
||||
angle_list (list): list of (real) rotation angles [a_0,...,a_{2^k-1}]
|
||||
angle_list (list): list of (real) rotation angles :math:`[a_0,...,a_{2^k-1}]`
|
||||
q_controls (QuantumRegister|list): list of k control qubits
|
||||
(or empty list if no controls). The control qubits are ordered according to their
|
||||
significance in increasing order: For example if q_controls=[q[1],q[2]]
|
||||
(with q = QuantumRegister(2)), the rotation Rx(a_0)is performed if q[1] and q[2]
|
||||
are in the state zero, the rotation Rx(a_1) is performed if q[1] is in the state
|
||||
one and q[2] is in the state zero, and so on
|
||||
significance in increasing order: For example if ``q_controls=[q[0],q[1]]``
|
||||
(with ``q = QuantumRegister(2)``), the rotation ``Rx(a_0)`` is performed if ``q[0]``
|
||||
and ``q[1]`` are in the state zero, the rotation ``Rx(a_1)`` is performed if ``q[0]``
|
||||
is in the state one and ``q[1]`` is in the state zero, and so on
|
||||
q_target (QuantumRegister|Qubit): target qubit, where we act on with
|
||||
the single-qubit rotation gates
|
||||
|
||||
|
|
|
@ -58,13 +58,13 @@ def ucry(self, angle_list, q_controls, q_target):
|
|||
The decomposition is base on https://arxiv.org/pdf/quant-ph/0406176.pdf by Shende et al.
|
||||
|
||||
Args:
|
||||
angle_list (list[numbers): list of (real) rotation angles [a_0,...,a_{2^k-1}]
|
||||
angle_list (list[numbers): list of (real) rotation angles :math:`[a_0,...,a_{2^k-1}]`
|
||||
q_controls (QuantumRegister|list[Qubit]): list of k control qubits
|
||||
(or empty list if no controls). The control qubits are ordered according to their
|
||||
significance in increasing order: For example if q_controls=[q[1],q[2]]
|
||||
(with q = QuantumRegister(2)), the rotation Ry(a_0)is performed if q[1] and q[2]
|
||||
are in the state zero, the rotation Ry(a_1) is performed if q[1] is in the state
|
||||
one and q[2] is in the state zero, and so on
|
||||
significance in increasing order: For example if ``q_controls=[q[0],q[1]]``
|
||||
(with ``q = QuantumRegister(2)``), the rotation ``Ry(a_0)`` is performed if ``q[0]``
|
||||
and ``q[1]`` are in the state zero, the rotation ``Ry(a_1)`` is performed if ``q[0]``
|
||||
is in the state one and ``q[1]`` is in the state zero, and so on
|
||||
q_target (QuantumRegister|Qubit): target qubit, where we act on with
|
||||
the single-qubit rotation gates
|
||||
|
||||
|
|
|
@ -78,9 +78,14 @@ class HGate(Gate):
|
|||
|
||||
@deprecate_arguments({'q': 'qubit'})
|
||||
def h(self, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument
|
||||
"""Apply Hadamard (H) gate to a specified qubit (qubit).
|
||||
An H gate implements a rotation of pi about the axis (x + z)/sqrt(2) on the Bloch sphere.
|
||||
This gate is canonically used to rotate the qubit state from |0⟩ to |+⟩ or |1⟩ to |-⟩.
|
||||
r"""Apply Hadamard (H) gate.
|
||||
|
||||
Applied to a specified qubit ``qubit``.
|
||||
|
||||
An H gate implements a rotation of :math:`\pi` about the axis
|
||||
:math:`\frac{(x + z)}{\sqrt{2}}` on the Bloch sphere. This gate is
|
||||
canonically used to rotate the qubit state from :math:`|0\rangle` to
|
||||
:math:`|+\rangle` or :math:`|1\rangle` to :math:`|-\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -100,6 +105,7 @@ def h(self, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument
|
|||
|
||||
from qiskit.extensions.standard.h import HGate
|
||||
HGate().to_matrix()
|
||||
|
||||
"""
|
||||
return self.append(HGate(), [qubit], [])
|
||||
|
||||
|
@ -159,9 +165,12 @@ class CHGate(ControlledGate):
|
|||
@deprecate_arguments({'ctl': 'control_qubit', 'tgt': 'target_qubit'})
|
||||
def ch(self, control_qubit, target_qubit, # pylint: disable=invalid-name
|
||||
*, ctl=None, tgt=None): # pylint: disable=unused-argument
|
||||
"""Apply cH gate from a specified control (control_qubit) to target (target_qubit) qubit.
|
||||
This gate is canonically used to rotate the qubit state from |0⟩ to |+⟩ and and |1⟩ to |−⟩
|
||||
when the control qubit is in state |1>.
|
||||
"""Apply cH gate
|
||||
|
||||
From a specified control ``control_qubit`` to target ``target_qubit`` qubit.
|
||||
This gate is canonically used to rotate the qubit state from :math:`|0\\rangle` to
|
||||
:math:`|+\\rangle` and :math:`|1\\rangle to :math:`|−\\rangle` when the control qubit is
|
||||
in state :math:`|1\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -66,11 +66,12 @@ class IdGate(IGate, metaclass=IMeta):
|
|||
|
||||
@deprecate_arguments({'q': 'qubit'})
|
||||
def i(self, qubit, *, q=None): # pylint: disable=unused-argument
|
||||
"""Apply Identity to to a specified qubit (qubit).
|
||||
"""Apply Identity to to a specified qubit ``qubit``.
|
||||
|
||||
The Identity gate ensures that nothing is applied to a qubit for one unit
|
||||
of gate time. It leaves the quantum states |0> and |1> unchanged.
|
||||
The Identity gate should not be optimized or unrolled (it is an opaque gate).
|
||||
of gate time. It leaves the quantum states :math:`|0\\rangle` and
|
||||
:math:`|1\\rangle` unchanged. The Identity gate should not be optimized or
|
||||
unrolled (it is an opaque gate).
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -71,9 +71,11 @@ class RZGate(Gate):
|
|||
|
||||
@deprecate_arguments({'q': 'qubit'})
|
||||
def rz(self, phi, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument
|
||||
"""Apply Rz gate with angle phi to a specified qubit (qubit).
|
||||
An Rz gate implemements a phi radian rotation of the qubit state vector about the
|
||||
z axis of the Bloch sphere.
|
||||
"""Apply Rz gate with angle :math:`\\phi`
|
||||
|
||||
The gate is applied to a specified qubit `qubit`.
|
||||
An Rz gate implemements a phi radian rotation of the qubit state vector
|
||||
about the z axis of the Bloch sphere.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -153,9 +155,12 @@ class CrzGate(CRZGate, metaclass=CRZMeta):
|
|||
@deprecate_arguments({'ctl': 'control_qubit', 'tgt': 'target_qubit'})
|
||||
def crz(self, theta, control_qubit, target_qubit,
|
||||
*, ctl=None, tgt=None): # pylint: disable=unused-argument
|
||||
"""Apply cRz gate from a specified control (control_qubit) to target (target_qubit) qubit
|
||||
with angle theta. A cRz gate implements a theta radian rotation of the qubit state vector
|
||||
about the z axis of the Bloch sphere when the control qubit is in state |1>.
|
||||
"""Apply cRz gate
|
||||
|
||||
Applied from a specified control ``control_qubit`` to target ``target_qubit`` qubit
|
||||
with angle :math:`\\theta`. A cRz gate implements a :math:`\\theta` radian rotation
|
||||
of the qubit state vector about the z axis of the Bloch sphere when the control
|
||||
qubit is in state :math:`|1\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -177,10 +177,12 @@ class FredkinGate(CSwapGate, metaclass=CSwapMeta):
|
|||
'tgt2': 'target_qubit2'})
|
||||
def cswap(self, control_qubit, target_qubit1, target_qubit2,
|
||||
*, ctl=None, tgt1=None, tgt2=None): # pylint: disable=unused-argument
|
||||
"""Apply Fredkin (CSWAP) gate from a specified control (control_qubit) to target1
|
||||
(target_qubit1) and target2 (target_qubit2) qubits. The CSWAP gate is canonically
|
||||
used to swap the qubit states of target1 and target2 when the control qubit is in
|
||||
state |1>.
|
||||
"""Apply Fredkin (CSWAP) gate
|
||||
|
||||
From a specified control ``control_qubit`` to target1 ``target_qubit1`` and
|
||||
target2 ``target_qubit2`` qubits. The CSWAP gate is canonically
|
||||
used to swap the qubit states of target1 and target2 when the control qubit
|
||||
is in state :math:`|1\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -73,8 +73,11 @@ class U1Gate(Gate):
|
|||
|
||||
@deprecate_arguments({'q': 'qubit'})
|
||||
def u1(self, theta, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument
|
||||
"""Apply U1 gate with angle theta to a specified qubit (qubit).
|
||||
u1(λ) := diag(1, eiλ) ∼ U(0, 0, λ) = Rz(λ) where ~ is equivalence up to a global phase.
|
||||
"""Apply U1 gate with angle theta
|
||||
|
||||
Applied to a specified qubit ``qubit``.
|
||||
:math:`u1(\\lambda) := diag(1, ei\\lambda) ∼ U(0, 0, \\lambda) = Rz(\\lambda)`
|
||||
where :math:`~` is equivalence up to a global phase.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -164,9 +167,12 @@ class Cu1Gate(CU1Gate, metaclass=CU1Meta):
|
|||
'tgt': 'target_qubit'})
|
||||
def cu1(self, theta, control_qubit, target_qubit,
|
||||
*, ctl=None, tgt=None): # pylint: disable=unused-argument
|
||||
"""Apply cU1 gate from a specified control (control_qubit) to target (target_qubit) qubit
|
||||
with angle theta. A cU1 gate implements a theta radian rotation of the qubit state vector
|
||||
about the z axis of the Bloch sphere when the control qubit is in state |1>.
|
||||
r"""Apply cU1 gate
|
||||
|
||||
Applied from a specified control ``control_qubit`` to target
|
||||
``target_qubit`` qubit with angle theta. A cU1 gate implements a
|
||||
:math:`\theta` radian rotation of the qubit state vector about the z axis
|
||||
of the Bloch sphere when the control qubit is in state :math:`|1\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -173,10 +173,12 @@ class Cu3Gate(CU3Gate, metaclass=CU3Meta):
|
|||
'tgt': 'target_qubit'})
|
||||
def cu3(self, theta, phi, lam, control_qubit, target_qubit,
|
||||
*, ctl=None, tgt=None): # pylint: disable=unused-argument
|
||||
"""Apply cU3 gate from a specified control (control_qubit) to target (target_qubit) qubit
|
||||
with angle theta, phi, and lam.
|
||||
A cU3 gate implements a U3(theta,phi,lam) on the target qubit when the
|
||||
control qubit is in state |1>.
|
||||
"""Apply cU3 gate
|
||||
|
||||
Applied from a specified control ``control_qubit`` to target
|
||||
``target_qubit`` qubit with angle ``theta``, ``phi``, and ``lam``.
|
||||
A cU3 gate implements a ``U3(theta,phi,lam)`` on the target qubit when the
|
||||
control qubit is in state :math:`|1\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -83,9 +83,10 @@ class XGate(Gate):
|
|||
@deprecate_arguments({'q': 'qubit'})
|
||||
def x(self, qubit, *, q=None): # pylint: disable=unused-argument
|
||||
"""Apply X gate to a specified qubit (qubit).
|
||||
An X gate implements a pi rotation of the qubit state vector about the
|
||||
x axis of the Bloch sphere.
|
||||
This gate is canonically used to implement a bit flip on the qubit state from |0⟩ to |1⟩,
|
||||
|
||||
An X gate implements a :math:`\\pi` rotation of the qubit state vector about
|
||||
the x axis of the Bloch sphere. This gate is canonically used to implement
|
||||
a bit flip on the qubit state from :math:`|0\\rangle` to :math:`|1\\rangle`,
|
||||
or vice versa.
|
||||
|
||||
Examples:
|
||||
|
@ -177,11 +178,14 @@ class CnotGate(CXGate, metaclass=CXMeta):
|
|||
'tgt': 'target_qubit'})
|
||||
def cx(self, control_qubit, target_qubit, # pylint: disable=invalid-name
|
||||
*, ctl=None, tgt=None): # pylint: disable=unused-argument
|
||||
"""Apply CX gate from a specified control (control_qubit) to target (target_qubit) qubit.
|
||||
A CX gate implements a pi rotation of the qubit state vector about the x axis
|
||||
of the Bloch sphere when the control qubit is in state |1>.
|
||||
This gate is canonically used to implement a bit flip on the qubit state from |0⟩ to |1⟩,
|
||||
or vice versa when the control qubit is in state |1>.
|
||||
"""Apply CX gate
|
||||
|
||||
From a specified control ``control_qubit`` to target ``target_qubit`` qubit.
|
||||
A CX gate implements a :math:`\\pi` rotation of the qubit state vector about
|
||||
the x axis of the Bloch sphere when the control qubit is in state :math:`|1\\rangle`
|
||||
This gate is canonically used to implement a bit flip on the qubit state from
|
||||
:math:`|0\\rangle` to :math:`|1\\rangle`, or vice versa when the control qubit is in
|
||||
:math:`|1\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -293,9 +297,11 @@ class ToffoliGate(CCXGate, metaclass=CCXMeta):
|
|||
'tgt': 'target_qubit'})
|
||||
def ccx(self, control_qubit1, control_qubit2, target_qubit,
|
||||
*, ctl1=None, ctl2=None, tgt=None): # pylint: disable=unused-argument
|
||||
"""Apply Toffoli (ccX) gate from two specified controls (control_qubit1 and control_qubit2)
|
||||
to target (target_qubit) qubit. This gate is canonically used to rotate the qubit state from
|
||||
|0⟩ to |1⟩, or vice versa when both the control qubits are in state |1>.
|
||||
"""Apply Toffoli (ccX) gate
|
||||
|
||||
From two specified controls ``(control_qubit1 and control_qubit2)`` to target ``target_qubit``
|
||||
qubit. This gate is canonically used to rotate the qubit state from :math:`|0\\rangle` to
|
||||
:math:`|1\\rangle`, or vice versa when both the control qubits are in state :math:`|1\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -73,10 +73,11 @@ class YGate(Gate):
|
|||
@deprecate_arguments({'q': 'qubit'})
|
||||
def y(self, qubit, *, q=None): # pylint: disable=unused-argument
|
||||
"""Apply Y gate to a specified qubit (qubit).
|
||||
A Y gate implements a pi rotation of the qubit state vector about the
|
||||
y axis of the Bloch sphere.
|
||||
This gate is canonically used to implement a bit flip and phase flip on the qubit state
|
||||
from |0⟩ to i|1⟩, or from |1> to -i|0>.
|
||||
|
||||
A Y gate implements a :math:`\\pi` rotation of the qubit state vector about
|
||||
the y axis of the Bloch sphere. This gate is canonically used to implement
|
||||
a bit flip and phase flip on the qubit state from :math:`|0\\rangle` to
|
||||
:math:`i|1\\rangle`, or from :math:`|1\\rangle` to :math:`-i|0\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
@ -167,11 +168,14 @@ class CyGate(CYGate, metaclass=CYMeta):
|
|||
'tgt': 'target_qubit'})
|
||||
def cy(self, control_qubit, target_qubit, # pylint: disable=invalid-name
|
||||
*, ctl=None, tgt=None): # pylint: disable=unused-argument
|
||||
"""Apply cY gate from a specified control (control_qubit) to target (target_qubit) qubit.
|
||||
"""Apply cY gate
|
||||
|
||||
Applied from a specified control ``control_qubit`` to target ``target_qubit`` qubit.
|
||||
A cY gate implements a pi rotation of the qubit state vector about the y axis
|
||||
of the Bloch sphere when the control qubit is in state |1>.
|
||||
of the Bloch sphere when the control qubit is in state :math:`|1\\rangle`.
|
||||
This gate is canonically used to implement a bit flip and phase flip on the qubit state
|
||||
from |0⟩ to i|1⟩, or from |1> to -i|0> when the control qubit is in state |1>.
|
||||
from :math:`|0\\rangle` to :math:`i|1\\rangle`, or from :math:`|1\\rangle` to
|
||||
:math:`-i|0\\rangle` when the control qubit is in state :math:`|1\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -73,9 +73,10 @@ class ZGate(Gate):
|
|||
@deprecate_arguments({'q': 'qubit'})
|
||||
def z(self, qubit, *, q=None): # pylint: disable=unused-argument
|
||||
"""Apply Z gate to a specified qubit (qubit).
|
||||
A Z gate implements a pi rotation of the qubit state vector about the
|
||||
z axis of the Bloch sphere.
|
||||
This gate is canonically used to implement a phase flip on the qubit state from |+⟩ to |-⟩,
|
||||
|
||||
A Z gate implements a :math:`\\pi` rotation of the qubit state vector about
|
||||
the z axis of the Bloch sphere. This gate is canonically used to implement
|
||||
a phase flip on the qubit state from :math:`|+\\rangle` to :math:`|-\\rangle`,
|
||||
or vice versa.
|
||||
|
||||
Examples:
|
||||
|
@ -166,11 +167,14 @@ class CzGate(CZGate, metaclass=CZMeta):
|
|||
'tgt': 'target_qubit'})
|
||||
def cz(self, control_qubit, target_qubit, # pylint: disable=invalid-name
|
||||
*, ctl=None, tgt=None): # pylint: disable=unused-argument
|
||||
"""Apply cZ gate from a specified control (control_qubit) to target (target_qubit) qubit.
|
||||
A cZ gate implements a pi rotation of the qubit state vector about the z axis
|
||||
of the Bloch sphere when the control qubit is in state |1>.
|
||||
This gate is canonically used to implement a phase flip on the qubit state from |+⟩ to |-⟩,
|
||||
or vice versa when the control qubit is in state |1>.
|
||||
"""Apply cZ gate
|
||||
|
||||
From a specified control ``control_qubit`` to target ``target_qubit`` qubit.
|
||||
A cZ gate implements a :math:`\\pi` rotation of the qubit state vector about
|
||||
the z axis of the Bloch sphere when the control qubit is in state :math:`|1\\rangle`.
|
||||
This gate is canonically used to implement a phase flip on the qubit state from
|
||||
:math:`|+\\rangle` to :math:`|-\\rangle`, or vice versa when the control qubit is in
|
||||
state :math:`|1\\rangle`.
|
||||
|
||||
Examples:
|
||||
|
||||
|
|
|
@ -439,12 +439,15 @@ class PulseBackendConfiguration(BackendConfiguration):
|
|||
"""
|
||||
Return a basic description of the channel dependency. Derived channels are given weights
|
||||
which describe how their frames are linked to other frames.
|
||||
For instance, the backend could be configured with this setting:
|
||||
For instance, the backend could be configured with this setting::
|
||||
|
||||
u_channel_lo = [
|
||||
[UchannelLO(q=0, scale=1. + 0.j)],
|
||||
[UchannelLO(q=0, scale=-1. + 0.j), UchannelLO(q=1, scale=1. + 0.j)]
|
||||
]
|
||||
Then, this method can be used as follows:
|
||||
|
||||
Then, this method can be used as follows::
|
||||
|
||||
backend.configuration().describe(ControlChannel(1))
|
||||
>>> {DriveChannel(0): -1, DriveChannel(1): 1}
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ been assigned to its :class:`~qiskit.pulse.channels.Channel` (s).
|
|||
Instruction
|
||||
|
||||
.. autosummary::
|
||||
:hidden:
|
||||
:toctree: ../stubs/
|
||||
|
||||
qiskit.pulse.commands
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
# copyright notice, and modified files need to carry a notice indicating
|
||||
# that they have been altered from the originals.
|
||||
|
||||
# pylint: disable=cyclic-import
|
||||
|
||||
"""
|
||||
Supported command types in Pulse.
|
||||
|
||||
|
@ -37,7 +39,6 @@ Abstract Classes
|
|||
Command
|
||||
|
||||
"""
|
||||
from .instruction import Instruction
|
||||
from .acquire import Acquire, AcquireInstruction
|
||||
from .frame_change import FrameChange, FrameChangeInstruction
|
||||
from .meas_opts import Discriminator, Kernel
|
||||
|
|
|
@ -18,9 +18,9 @@ Acquire.
|
|||
import warnings
|
||||
from typing import Optional, Union, List
|
||||
|
||||
from qiskit.pulse.channels import MemorySlot, RegisterSlot, AcquireChannel
|
||||
from qiskit.pulse.exceptions import PulseError
|
||||
from .instruction import Instruction
|
||||
from ..channels import MemorySlot, RegisterSlot, AcquireChannel
|
||||
from ..instructions import Instruction
|
||||
from .meas_opts import Discriminator, Kernel
|
||||
from .command import Command
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ import numpy as np
|
|||
from qiskit.pulse.exceptions import PulseError
|
||||
from qiskit.pulse.channels import Channel
|
||||
|
||||
from .instruction import Instruction
|
||||
|
||||
|
||||
class MetaCount(ABCMeta):
|
||||
"""Meta class to count class instances."""
|
||||
|
@ -91,8 +89,12 @@ class Command(metaclass=MetaCount):
|
|||
|
||||
@abstractmethod
|
||||
def to_instruction(self, command, *channels: List[Channel],
|
||||
name: Optional[str] = None) -> Instruction:
|
||||
"""Create an instruction from command."""
|
||||
name: Optional[str] = None):
|
||||
"""Create an instruction from command.
|
||||
|
||||
Returns:
|
||||
Instruction
|
||||
"""
|
||||
pass
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
|
|
|
@ -18,7 +18,7 @@ Delay instruction.
|
|||
from typing import Optional
|
||||
|
||||
from qiskit.pulse.channels import Channel
|
||||
from .instruction import Instruction
|
||||
from ..instructions import Instruction
|
||||
from .command import Command
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ Frame change pulse.
|
|||
from typing import Optional
|
||||
|
||||
from qiskit.pulse.channels import PulseChannel
|
||||
from .instruction import Instruction
|
||||
from ..instructions import Instruction
|
||||
from .command import Command
|
||||
|
||||
|
||||
|
|
|
@ -43,14 +43,13 @@ import math
|
|||
|
||||
import numpy as np
|
||||
|
||||
from qiskit.pulse.channels import PulseChannel
|
||||
from qiskit.pulse.exceptions import PulseError
|
||||
from qiskit.pulse.pulse_lib.discrete import gaussian, gaussian_square, drag, constant
|
||||
from qiskit.pulse.pulse_lib import continuous
|
||||
from qiskit.pulse.pulse_lib import gaussian, gaussian_square, drag, constant, continuous
|
||||
from .sample_pulse import SamplePulse
|
||||
from ..instructions import Instruction
|
||||
from ..channels import PulseChannel
|
||||
from ..exceptions import PulseError
|
||||
|
||||
from .pulse_command import PulseCommand
|
||||
from .sample_pulse import SamplePulse
|
||||
from .instruction import Instruction
|
||||
|
||||
# pylint: disable=missing-docstring
|
||||
|
||||
|
@ -97,7 +96,7 @@ class ParametricPulse(PulseCommand):
|
|||
return ParametricInstruction(self, channel, name=name)
|
||||
|
||||
def draw(self, dt: float = 1,
|
||||
style: Optional['PulseStyle'] = None,
|
||||
style=None,
|
||||
filename: Optional[str] = None,
|
||||
interp_method: Optional[Callable] = None,
|
||||
scale: float = 1, interactive: bool = False,
|
||||
|
@ -106,7 +105,7 @@ class ParametricPulse(PulseCommand):
|
|||
|
||||
Args:
|
||||
dt: Time interval of samples.
|
||||
style: A style sheet to configure plot appearance
|
||||
style (Optional[PulseStyle]): A style sheet to configure plot appearance
|
||||
filename: Name required to save pulse image
|
||||
interp_method: A function for interpolation
|
||||
scale: Relative visual scaling of waveform amplitudes
|
||||
|
@ -253,11 +252,10 @@ class GaussianSquare(ParametricPulse):
|
|||
|
||||
|
||||
class Drag(ParametricPulse):
|
||||
"""
|
||||
The Derivative Removal by Adiabatic Gate (DRAG) pulse is a standard Gaussian pulse
|
||||
r"""The Derivative Removal by Adiabatic Gate (DRAG) pulse is a standard Gaussian pulse
|
||||
with an additional Gaussian derivative component. It is designed to reduce the frequency
|
||||
spectrum of a normal gaussian pulse near the |1>-|2> transition, reducing the chance of
|
||||
leakage to the |2> state.
|
||||
spectrum of a normal gaussian pulse near the :math:`|1\rangle` - :math:`|2\rangle` transition,
|
||||
reducing the chance of leakage to the :math:`|2\rangle` state.
|
||||
|
||||
.. math::
|
||||
|
||||
|
@ -270,12 +268,21 @@ class Drag(ParametricPulse):
|
|||
|
||||
Gaussian(x, amp, sigma) = amp * exp( -(1/2) * (x - duration/2)^2 / sigma^2) )
|
||||
|
||||
Ref:
|
||||
[1] Gambetta, J. M., Motzoi, F., Merkel, S. T. & Wilhelm, F. K.
|
||||
Analytic control methods for high-fidelity unitary operations
|
||||
in a weakly nonlinear oscillator. Phys. Rev. A 83, 012308 (2011).
|
||||
[2] F. Motzoi, J. M. Gambetta, P. Rebentrost, and F. K. Wilhelm
|
||||
Phys. Rev. Lett. 103, 110501 – Published 8 September 2009
|
||||
References:
|
||||
1. |citation1|_
|
||||
|
||||
.. _citation1: https://link.aps.org/doi/10.1103/PhysRevA.83.012308
|
||||
|
||||
.. |citation1| replace:: *Gambetta, J. M., Motzoi, F., Merkel, S. T. & Wilhelm, F. K.
|
||||
Analytic control methods for high-fidelity unitary operations
|
||||
in a weakly nonlinear oscillator. Phys. Rev. A 83, 012308 (2011).*
|
||||
|
||||
2. |citation2|_
|
||||
|
||||
.. _citation2: https://link.aps.org/doi/10.1103/PhysRevLett.103.110501
|
||||
|
||||
.. |citation2| replace:: *F. Motzoi, J. M. Gambetta, P. Rebentrost, and F. K. Wilhelm
|
||||
Phys. Rev. Lett. 103, 110501 – Published 8 September 2009.*
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
|
|
|
@ -21,7 +21,7 @@ from typing import Optional
|
|||
|
||||
from qiskit.pulse.channels import PulseChannel
|
||||
from qiskit.pulse.exceptions import PulseError
|
||||
from .instruction import Instruction
|
||||
from ..instructions import Instruction
|
||||
from .command import Command
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ from typing import Callable, List, Optional
|
|||
from abc import abstractmethod
|
||||
|
||||
from qiskit.pulse.channels import Channel
|
||||
from .instruction import Instruction
|
||||
from ..instructions import Instruction
|
||||
from .command import Command
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ class PulseCommand(Command):
|
|||
|
||||
@abstractmethod
|
||||
def draw(self, dt: float = 1,
|
||||
style: Optional['PulseStyle'] = None,
|
||||
style=None,
|
||||
filename: Optional[str] = None,
|
||||
interp_method: Optional[Callable] = None,
|
||||
scale: float = 1, interactive: bool = False,
|
||||
|
@ -46,7 +46,7 @@ class PulseCommand(Command):
|
|||
|
||||
Args:
|
||||
dt: Time interval of samples.
|
||||
style: A style sheet to configure plot appearance
|
||||
style (Optional[PulseStyle]): A style sheet to configure plot appearance
|
||||
filename: Name required to save pulse image
|
||||
interp_method: A function for interpolation
|
||||
scale: Relative visual scaling of waveform amplitudes
|
||||
|
|
|
@ -23,7 +23,7 @@ import numpy as np
|
|||
from qiskit.pulse.channels import PulseChannel
|
||||
from qiskit.pulse.exceptions import PulseError
|
||||
|
||||
from .instruction import Instruction
|
||||
from ..instructions import Instruction
|
||||
from .pulse_command import PulseCommand
|
||||
|
||||
|
||||
|
@ -100,7 +100,7 @@ class SamplePulse(PulseCommand):
|
|||
return samples
|
||||
|
||||
def draw(self, dt: float = 1,
|
||||
style: Optional['PulseStyle'] = None,
|
||||
style=None,
|
||||
filename: Optional[str] = None,
|
||||
interp_method: Optional[Callable] = None,
|
||||
scale: float = 1, interactive: bool = False,
|
||||
|
@ -109,7 +109,7 @@ class SamplePulse(PulseCommand):
|
|||
|
||||
Args:
|
||||
dt: Time interval of samples.
|
||||
style: A style sheet to configure plot appearance
|
||||
style (Optional[PulseStyle]): A style sheet to configure plot appearance
|
||||
filename: Name required to save pulse image
|
||||
interp_method: A function for interpolation
|
||||
scale: Relative visual scaling of waveform amplitudes
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
Snapshot.
|
||||
"""
|
||||
from qiskit.pulse.channels import SnapshotChannel
|
||||
from .instruction import Instruction
|
||||
from ..instructions import Instruction
|
||||
from .command import Command
|
||||
|
||||
|
||||
|
|
|
@ -30,9 +30,10 @@ from abc import ABC
|
|||
from typing import Tuple, List, Iterable, Callable, Optional, Union
|
||||
|
||||
from qiskit.pulse.channels import Channel
|
||||
from qiskit.pulse.interfaces import ScheduleComponent
|
||||
from qiskit.pulse.schedule import Schedule
|
||||
from qiskit.pulse.timeslots import Interval, Timeslot, TimeslotCollection
|
||||
from ..interfaces import ScheduleComponent
|
||||
from ..schedule import Schedule
|
||||
from .. import commands # pylint: disable=unused-import
|
||||
|
||||
# pylint: disable=missing-return-doc
|
||||
|
||||
|
@ -44,7 +45,7 @@ class Instruction(ScheduleComponent, ABC):
|
|||
channels.
|
||||
"""
|
||||
|
||||
def __init__(self, duration: Union['Command', int],
|
||||
def __init__(self, duration: Union['commands.Command', int],
|
||||
*channels: Channel,
|
||||
name: Optional[str] = None):
|
||||
"""Instruction initializer.
|
||||
|
@ -73,7 +74,7 @@ class Instruction(ScheduleComponent, ABC):
|
|||
return self._name
|
||||
|
||||
@property
|
||||
def command(self) -> 'Command':
|
||||
def command(self) -> 'commands.Command':
|
||||
"""The associated command."""
|
||||
return self._command
|
||||
|
||||
|
@ -152,7 +153,7 @@ class Instruction(ScheduleComponent, ABC):
|
|||
"""Return itself as already single instruction."""
|
||||
return self
|
||||
|
||||
def union(self, *schedules: List[ScheduleComponent], name: Optional[str] = None) -> 'Schedule':
|
||||
def union(self, *schedules: List[ScheduleComponent], name: Optional[str] = None) -> Schedule:
|
||||
"""Return a new schedule which is the union of `self` and `schedule`.
|
||||
|
||||
Args:
|
||||
|
@ -165,7 +166,7 @@ class Instruction(ScheduleComponent, ABC):
|
|||
name = self.name
|
||||
return Schedule(self, *schedules, name=name)
|
||||
|
||||
def shift(self: ScheduleComponent, time: int, name: Optional[str] = None) -> 'Schedule':
|
||||
def shift(self: ScheduleComponent, time: int, name: Optional[str] = None) -> Schedule:
|
||||
"""Return a new schedule shifted forward by `time`.
|
||||
|
||||
Args:
|
||||
|
@ -177,7 +178,7 @@ class Instruction(ScheduleComponent, ABC):
|
|||
return Schedule((time, self), name=name)
|
||||
|
||||
def insert(self, start_time: int, schedule: ScheduleComponent,
|
||||
name: Optional[str] = None) -> 'Schedule':
|
||||
name: Optional[str] = None) -> Schedule:
|
||||
"""Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted within
|
||||
``self`` at ``start_time``.
|
||||
|
||||
|
@ -191,7 +192,7 @@ class Instruction(ScheduleComponent, ABC):
|
|||
return Schedule(self, (start_time, schedule), name=name)
|
||||
|
||||
def append(self, schedule: ScheduleComponent,
|
||||
name: Optional[str] = None) -> 'Schedule':
|
||||
name: Optional[str] = None) -> Schedule:
|
||||
"""Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted at the
|
||||
maximum time over all channels shared between ``self`` and ``schedule``.
|
||||
|
||||
|
@ -203,7 +204,7 @@ class Instruction(ScheduleComponent, ABC):
|
|||
time = self.ch_stop_time(*common_channels)
|
||||
return self.insert(time, schedule, name=name)
|
||||
|
||||
def draw(self, dt: float = 1, style: Optional['SchedStyle'] = None,
|
||||
def draw(self, dt: float = 1, style=None,
|
||||
filename: Optional[str] = None, interp_method: Optional[Callable] = None,
|
||||
scale: float = 1, channels_to_plot: Optional[List[Channel]] = None,
|
||||
plot_all: bool = False, plot_range: Optional[Tuple[float]] = None,
|
||||
|
@ -215,7 +216,7 @@ class Instruction(ScheduleComponent, ABC):
|
|||
|
||||
Args:
|
||||
dt: Time interval of samples
|
||||
style: A style sheet to configure plot appearance
|
||||
style (Optional[SchedStyle]): A style sheet to configure plot appearance
|
||||
filename: Name required to save pulse image
|
||||
interp_method: A function for interpolation
|
||||
scale: Relative visual scaling of waveform amplitudes
|
||||
|
@ -272,15 +273,15 @@ class Instruction(ScheduleComponent, ABC):
|
|||
return hash((hash(tuple(self.command)), self.channels.__hash__()))
|
||||
return hash((hash(tuple(self.duration)), self.channels.__hash__()))
|
||||
|
||||
def __add__(self, other: ScheduleComponent) -> 'Schedule':
|
||||
def __add__(self, other: ScheduleComponent) -> Schedule:
|
||||
"""Return a new schedule with `other` inserted within `self` at `start_time`."""
|
||||
return self.append(other)
|
||||
|
||||
def __or__(self, other: ScheduleComponent) -> 'Schedule':
|
||||
def __or__(self, other: ScheduleComponent) -> Schedule:
|
||||
"""Return a new schedule which is the union of `self` and `other`."""
|
||||
return self.insert(0, other)
|
||||
|
||||
def __lshift__(self, time: int) -> 'Schedule':
|
||||
def __lshift__(self, time: int) -> Schedule:
|
||||
"""Return a new schedule which is shifted forward by `time`."""
|
||||
return self.shift(time)
|
||||
|
||||
|
|
|
@ -21,8 +21,9 @@ Note the sampling strategy use for all discrete pulses is `midpoint`.
|
|||
import warnings
|
||||
from typing import Optional
|
||||
|
||||
from qiskit.pulse.pulse_lib import continuous
|
||||
from qiskit.pulse.exceptions import PulseError
|
||||
from ..commands.sample_pulse import SamplePulse
|
||||
from . import continuous
|
||||
|
||||
from . import samplers
|
||||
|
||||
|
@ -30,7 +31,7 @@ from . import samplers
|
|||
_sampled_constant_pulse = samplers.midpoint(continuous.constant)
|
||||
|
||||
|
||||
def constant(duration: int, amp: complex, name: Optional[str] = None) -> 'SamplePulse':
|
||||
def constant(duration: int, amp: complex, name: Optional[str] = None) -> SamplePulse:
|
||||
r"""Generates constant-sampled :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp``, samples from the function:
|
||||
|
@ -50,7 +51,7 @@ def constant(duration: int, amp: complex, name: Optional[str] = None) -> 'Sample
|
|||
_sampled_zero_pulse = samplers.midpoint(continuous.zero)
|
||||
|
||||
|
||||
def zero(duration: int, name: Optional[str] = None) -> 'SamplePulse':
|
||||
def zero(duration: int, name: Optional[str] = None) -> SamplePulse:
|
||||
"""Generates zero-sampled :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
Samples from the function:
|
||||
|
@ -70,7 +71,7 @@ _sampled_square_pulse = samplers.midpoint(continuous.square)
|
|||
|
||||
|
||||
def square(duration: int, amp: complex, freq: float = None, period: float = None,
|
||||
phase: float = 0, name: Optional[str] = None) -> 'SamplePulse':
|
||||
phase: float = 0, name: Optional[str] = None) -> SamplePulse:
|
||||
r"""Generates square wave :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp``, :math:`T=` ``period``, and :math:`\phi=` ``phase``,
|
||||
|
@ -107,7 +108,7 @@ _sampled_sawtooth_pulse = samplers.midpoint(continuous.sawtooth)
|
|||
|
||||
|
||||
def sawtooth(duration: int, amp: complex, freq: float = None, period: float = None,
|
||||
phase: float = 0, name: Optional[str] = None) -> 'SamplePulse':
|
||||
phase: float = 0, name: Optional[str] = None) -> SamplePulse:
|
||||
r"""Generates sawtooth wave :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp``, :math:`T=` ``period``, and :math:`\phi=` ``phase``,
|
||||
|
@ -133,11 +134,13 @@ def sawtooth(duration: int, amp: complex, freq: float = None, period: float = No
|
|||
|
||||
import matplotlib.pyplot as plt
|
||||
from qiskit.pulse.pulse_lib import sawtooth
|
||||
import numpy as np
|
||||
|
||||
duration = 100
|
||||
amp = 1
|
||||
period = duration
|
||||
plt.plot(range(duration), sawtooth(duration, amp, period).samples)
|
||||
sawtooth_wave = np.real(sawtooth(duration, amp, period).samples)
|
||||
plt.plot(range(duration), sawtooth_wave)
|
||||
"""
|
||||
if (freq is None) and (period is None):
|
||||
freq = 1./duration
|
||||
|
@ -154,7 +157,7 @@ _sampled_triangle_pulse = samplers.midpoint(continuous.triangle)
|
|||
|
||||
|
||||
def triangle(duration: int, amp: complex, freq: float = None, period: float = None,
|
||||
phase: float = 0, name: Optional[str] = None) -> 'SamplePulse':
|
||||
phase: float = 0, name: Optional[str] = None) -> SamplePulse:
|
||||
r"""Generates triangle wave :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp``, :math:`T=` ``period``, and :math:`\phi=` ``phase``,
|
||||
|
@ -180,11 +183,13 @@ def triangle(duration: int, amp: complex, freq: float = None, period: float = No
|
|||
|
||||
import matplotlib.pyplot as plt
|
||||
from qiskit.pulse.pulse_lib import triangle
|
||||
import numpy as np
|
||||
|
||||
duration = 100
|
||||
amp = 1
|
||||
period = duration
|
||||
plt.plot(range(duration), triangle(duration, amp, period).samples)
|
||||
triangle_wave = np.real(triangle(duration, amp, period).samples)
|
||||
plt.plot(range(duration), triangle_wave)
|
||||
"""
|
||||
if (freq is None) and (period is None):
|
||||
freq = 1./duration
|
||||
|
@ -201,7 +206,7 @@ _sampled_cos_pulse = samplers.midpoint(continuous.cos)
|
|||
|
||||
|
||||
def cos(duration: int, amp: complex, freq: float = None,
|
||||
phase: float = 0, name: Optional[str] = None) -> 'SamplePulse':
|
||||
phase: float = 0, name: Optional[str] = None) -> SamplePulse:
|
||||
r"""Generates cosine wave :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp``, :math:`\omega=` ``freq``, and :math:`\phi=` ``phase``,
|
||||
|
@ -229,7 +234,7 @@ _sampled_sin_pulse = samplers.midpoint(continuous.sin)
|
|||
|
||||
|
||||
def sin(duration: int, amp: complex, freq: float = None,
|
||||
phase: float = 0, name: Optional[str] = None) -> 'SamplePulse':
|
||||
phase: float = 0, name: Optional[str] = None) -> SamplePulse:
|
||||
r"""Generates sine wave :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp``, :math:`\omega=` ``freq``, and :math:`\phi=` ``phase``,
|
||||
|
@ -257,7 +262,7 @@ _sampled_gaussian_pulse = samplers.midpoint(continuous.gaussian)
|
|||
|
||||
|
||||
def gaussian(duration: int, amp: complex, sigma: float, name: Optional[str] = None,
|
||||
zero_ends: bool = True) -> 'SamplePulse':
|
||||
zero_ends: bool = True) -> SamplePulse:
|
||||
r"""Generates unnormalized gaussian :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp`` and :math:`\sigma=` ``sigma``, applies the `midpoint` sampling strategy
|
||||
|
@ -300,7 +305,7 @@ _sampled_gaussian_deriv_pulse = samplers.midpoint(continuous.gaussian_deriv)
|
|||
|
||||
|
||||
def gaussian_deriv(duration: int, amp: complex, sigma: float,
|
||||
name: Optional[str] = None) -> 'SamplePulse':
|
||||
name: Optional[str] = None) -> SamplePulse:
|
||||
r"""Generates unnormalized gaussian derivative :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp`` and :math:`\sigma=` ``sigma`` applies the `midpoint` sampling strategy
|
||||
|
@ -326,7 +331,7 @@ _sampled_sech_pulse = samplers.midpoint(continuous.sech)
|
|||
|
||||
|
||||
def sech(duration: int, amp: complex, sigma: float, name: str = None,
|
||||
zero_ends: bool = True) -> 'SamplePulse':
|
||||
zero_ends: bool = True) -> SamplePulse:
|
||||
r"""Generates unnormalized sech :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp`` and :math:`\sigma=` ``sigma``, applies the `midpoint` sampling strategy
|
||||
|
@ -366,7 +371,7 @@ def sech(duration: int, amp: complex, sigma: float, name: str = None,
|
|||
_sampled_sech_deriv_pulse = samplers.midpoint(continuous.sech_deriv)
|
||||
|
||||
|
||||
def sech_deriv(duration: int, amp: complex, sigma: float, name: str = None) -> 'SamplePulse':
|
||||
def sech_deriv(duration: int, amp: complex, sigma: float, name: str = None) -> SamplePulse:
|
||||
r"""Generates unnormalized sech derivative :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`A=` ``amp``, :math:`\sigma=` ``sigma``, and center :math:`\mu=` ``duration/2``,
|
||||
|
@ -393,7 +398,7 @@ _sampled_gaussian_square_pulse = samplers.midpoint(continuous.gaussian_square)
|
|||
|
||||
def gaussian_square(duration: int, amp: complex, sigma: float,
|
||||
risefall: Optional[float] = None, width: Optional[float] = None,
|
||||
name: Optional[str] = None, zero_ends: bool = True) -> 'SamplePulse':
|
||||
name: Optional[str] = None, zero_ends: bool = True) -> SamplePulse:
|
||||
r"""Generates gaussian square :class:`~qiskit.pulse.SamplePulse`.
|
||||
|
||||
For :math:`d=` ``duration``, :math:`A=` ``amp``, :math:`\sigma=` ``sigma``,
|
||||
|
@ -448,7 +453,7 @@ _sampled_drag_pulse = samplers.midpoint(continuous.drag)
|
|||
|
||||
|
||||
def drag(duration: int, amp: complex, sigma: float, beta: float,
|
||||
name: Optional[str] = None, zero_ends: bool = True) -> 'SamplePulse':
|
||||
name: Optional[str] = None, zero_ends: bool = True) -> SamplePulse:
|
||||
r"""Generates Y-only correction DRAG :class:`~qiskit.pulse.SamplePulse` for standard nonlinear
|
||||
oscillator (SNO) [1].
|
||||
|
||||
|
|
|
@ -22,13 +22,10 @@ from typing import List, Optional, Iterable
|
|||
|
||||
import numpy as np
|
||||
|
||||
from qiskit.pulse import (CmdDef, Acquire, AcquireInstruction, Delay,
|
||||
InstructionScheduleMap, ScheduleComponent, Schedule)
|
||||
from .channels import Channel, AcquireChannel, MeasureChannel, MemorySlot
|
||||
from .cmd_def import CmdDef
|
||||
from .commands import Acquire, AcquireInstruction, Delay
|
||||
from .exceptions import PulseError
|
||||
from .instruction_schedule_map import InstructionScheduleMap
|
||||
from .interfaces import ScheduleComponent
|
||||
from .schedule import Schedule
|
||||
|
||||
|
||||
def align_measures(schedules: Iterable[ScheduleComponent],
|
||||
|
|
|
@ -21,14 +21,13 @@ import abc
|
|||
import itertools
|
||||
import multiprocessing as mp
|
||||
import sys
|
||||
from typing import List, Tuple, Iterable, Union, Dict, Callable, Set, Optional, Type
|
||||
from typing import List, Tuple, Iterable, Union, Dict, Callable, Set, Optional
|
||||
import warnings
|
||||
|
||||
from qiskit.util import is_main_process
|
||||
from .timeslots import Interval
|
||||
from .timeslots import Interval, TimeslotCollection
|
||||
from .channels import Channel
|
||||
from .interfaces import ScheduleComponent
|
||||
from .timeslots import TimeslotCollection
|
||||
from .exceptions import PulseError
|
||||
|
||||
# pylint: disable=missing-return-doc
|
||||
|
@ -123,8 +122,12 @@ class Schedule(ScheduleComponent):
|
|||
return self.__children
|
||||
|
||||
@property
|
||||
def instructions(self) -> Tuple[Tuple[int, 'Instruction'], ...]:
|
||||
"""Get the time-ordered instructions from self."""
|
||||
def instructions(self):
|
||||
"""Get the time-ordered instructions from self.
|
||||
|
||||
ReturnType:
|
||||
Tuple[Tuple[int, Instruction], ...]
|
||||
"""
|
||||
|
||||
def key(time_inst_pair):
|
||||
inst = time_inst_pair[1]
|
||||
|
@ -157,15 +160,16 @@ class Schedule(ScheduleComponent):
|
|||
"""
|
||||
return self.timeslots.ch_stop_time(*channels)
|
||||
|
||||
def _instructions(self, time: int = 0) -> Iterable[Tuple[int, 'Instruction']]:
|
||||
def _instructions(self, time: int = 0):
|
||||
"""Iterable for flattening Schedule tree.
|
||||
|
||||
Args:
|
||||
time: Shifted time due to parent.
|
||||
|
||||
Yields:
|
||||
Tuple containing the time each :class:`~qiskit.pulse.Instruction`
|
||||
starts at and the flattened :class:`~qiskit.pulse.Instruction` s.
|
||||
Iterable[Tuple[int, Instruction]]: Tuple containing the time each
|
||||
:class:`~qiskit.pulse.Instruction`
|
||||
starts at and the flattened :class:`~qiskit.pulse.Instruction` s.
|
||||
"""
|
||||
for insert_time, child_sched in self._children:
|
||||
yield from child_sched._instructions(time + insert_time)
|
||||
|
@ -260,7 +264,7 @@ class Schedule(ScheduleComponent):
|
|||
|
||||
def filter(self, *filter_funcs: List[Callable],
|
||||
channels: Optional[Iterable[Channel]] = None,
|
||||
instruction_types: Optional[Iterable[Type['Instruction']]] = None,
|
||||
instruction_types=None,
|
||||
time_ranges: Optional[Iterable[Tuple[int, int]]] = None,
|
||||
intervals: Optional[Iterable[Interval]] = None) -> 'Schedule':
|
||||
"""Return a new ``Schedule`` with only the instructions from this ``Schedule`` which pass
|
||||
|
@ -276,7 +280,8 @@ class Schedule(ScheduleComponent):
|
|||
filter_funcs: A list of Callables which take a (int, ScheduleComponent) tuple and
|
||||
return a bool.
|
||||
channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``.
|
||||
instruction_types: For example, ``[PulseInstruction, AcquireInstruction]``.
|
||||
instruction_types (Optional[Iterable[Type[qiskit.pulse.Instruction]]]): For example,
|
||||
``[PulseInstruction, AcquireInstruction]``.
|
||||
time_ranges: For example, ``[(0, 5), (6, 10)]``.
|
||||
intervals: For example, ``[Interval(0, 5), Interval(6, 10)]``.
|
||||
"""
|
||||
|
@ -290,7 +295,7 @@ class Schedule(ScheduleComponent):
|
|||
|
||||
def exclude(self, *filter_funcs: List[Callable],
|
||||
channels: Optional[Iterable[Channel]] = None,
|
||||
instruction_types: Optional[Iterable[Type['Instruction']]] = None,
|
||||
instruction_types=None,
|
||||
time_ranges: Optional[Iterable[Tuple[int, int]]] = None,
|
||||
intervals: Optional[Iterable[Interval]] = None) -> 'Schedule':
|
||||
"""Return a Schedule with only the instructions from this Schedule *failing* at least one
|
||||
|
@ -302,7 +307,8 @@ class Schedule(ScheduleComponent):
|
|||
filter_funcs: A list of Callables which take a (int, ScheduleComponent) tuple and
|
||||
return a bool.
|
||||
channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``.
|
||||
instruction_types: For example, ``[PulseInstruction, AcquireInstruction]``.
|
||||
instruction_types (Optional[Iterable[Type[qiskit.pulse.Instruction]]]): For example,
|
||||
``[PulseInstruction, AcquireInstruction]``.
|
||||
time_ranges: For example, ``[(0, 5), (6, 10)]``.
|
||||
intervals: For example, ``[Interval(0, 5), Interval(6, 10)]``.
|
||||
"""
|
||||
|
@ -328,7 +334,7 @@ class Schedule(ScheduleComponent):
|
|||
|
||||
def _construct_filter(self, *filter_funcs: List[Callable],
|
||||
channels: Optional[Iterable[Channel]] = None,
|
||||
instruction_types: Optional[Iterable[Type['Instruction']]] = None,
|
||||
instruction_types=None,
|
||||
time_ranges: Optional[Iterable[Tuple[int, int]]] = None,
|
||||
intervals: Optional[Iterable[Interval]] = None) -> Callable:
|
||||
"""Returns a boolean-valued function with input type ``(int, ScheduleComponent)`` that
|
||||
|
@ -342,22 +348,38 @@ class Schedule(ScheduleComponent):
|
|||
filter_funcs: A list of Callables which take a (int, ScheduleComponent) tuple and
|
||||
return a bool.
|
||||
channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``.
|
||||
instruction_types: For example, ``[PulseInstruction, AcquireInstruction]``.
|
||||
instruction_types (Optional[Iterable[Type[Instruction]]]): For example,
|
||||
``[PulseInstruction, AcquireInstruction]``.
|
||||
time_ranges: For example, ``[(0, 5), (6, 10)]``.
|
||||
intervals: For example, ``[Interval(0, 5), Interval(6, 10)]``.
|
||||
"""
|
||||
def only_channels(channels: Set[Channel]) -> Callable:
|
||||
def channel_filter(time_inst: Tuple[int, 'Instruction']) -> bool:
|
||||
def channel_filter(time_inst) -> bool:
|
||||
"""Filter channel.
|
||||
|
||||
Args:
|
||||
time_inst (Tuple[int, Instruction]): Time
|
||||
"""
|
||||
return any([chan in channels for chan in time_inst[1].channels])
|
||||
return channel_filter
|
||||
|
||||
def only_instruction_types(types: Iterable[abc.ABCMeta]) -> Callable:
|
||||
def instruction_filter(time_inst: Tuple[int, 'Instruction']) -> bool:
|
||||
def instruction_filter(time_inst) -> bool:
|
||||
"""Filter instruction.
|
||||
|
||||
Args:
|
||||
time_inst (Tuple[int, Instruction]): Time
|
||||
"""
|
||||
return isinstance(time_inst[1], tuple(types))
|
||||
return instruction_filter
|
||||
|
||||
def only_intervals(ranges: Iterable[Interval]) -> Callable:
|
||||
def interval_filter(time_inst: Tuple[int, 'Instruction']) -> bool:
|
||||
def interval_filter(time_inst) -> bool:
|
||||
"""Filter interval.
|
||||
|
||||
Args:
|
||||
time_inst (Tuple[int, Instruction]): Time
|
||||
"""
|
||||
for i in ranges:
|
||||
if all([(i.start <= ts.interval.shift(time_inst[0]).start
|
||||
and ts.interval.shift(time_inst[0]).stop <= i.stop)
|
||||
|
@ -380,7 +402,7 @@ class Schedule(ScheduleComponent):
|
|||
# return function returning true iff all filters are passed
|
||||
return lambda x: all([filter_func(x) for filter_func in filter_func_list])
|
||||
|
||||
def draw(self, dt: float = 1, style: Optional['SchedStyle'] = None,
|
||||
def draw(self, dt: float = 1, style=None,
|
||||
filename: Optional[str] = None, interp_method: Optional[Callable] = None,
|
||||
scale: Optional[float] = None,
|
||||
channel_scales: Optional[Dict[Channel, float]] = None,
|
||||
|
@ -390,26 +412,26 @@ class Schedule(ScheduleComponent):
|
|||
framechange: bool = True, scaling: float = None,
|
||||
channels: Optional[List[Channel]] = None,
|
||||
show_framechange_channels: bool = True):
|
||||
"""Plot the schedule.
|
||||
r"""Plot the schedule.
|
||||
|
||||
Args:
|
||||
dt: Time interval of samples
|
||||
style: A style sheet to configure plot appearance
|
||||
filename: Name required to save pulse image
|
||||
interp_method: A function for interpolation
|
||||
dt: Time interval of samples.
|
||||
style (Optional[SchedStyle]): A style sheet to configure plot appearance.
|
||||
filename: Name required to save pulse image.
|
||||
interp_method: A function for interpolation.
|
||||
scale: Relative visual scaling of waveform amplitudes, see Additional Information.
|
||||
channel_scales: Channel independent scaling as a dictionary of ``Channel`` object.
|
||||
channels_to_plot: Deprecated, see ``channels``
|
||||
plot_all: Plot empty channels
|
||||
plot_range: A tuple of time range to plot
|
||||
channels_to_plot: Deprecated, see ``channels``.
|
||||
plot_all: Plot empty channels.
|
||||
plot_range: A tuple of time range to plot.
|
||||
interactive: When set true show the circuit in a new window
|
||||
(this depends on the matplotlib backend being used supporting this)
|
||||
table: Draw event table for supported commands
|
||||
label: Label individual instructions
|
||||
framechange: Add framechange indicators
|
||||
scaling: Deprecated, see ``scale``
|
||||
channels: A list of channel names to plot
|
||||
show_framechange_channels: Plot channels with only framechanges
|
||||
(this depends on the matplotlib backend being used supporting this).
|
||||
table: Draw event table for supported commands.
|
||||
label: Label individual instructions.
|
||||
framechange: Add framechange indicators.
|
||||
scaling: Deprecated, see ``scale``.
|
||||
channels: A list of channel names to plot.
|
||||
show_framechange_channels: Plot channels with only framechanges.
|
||||
|
||||
Additional Information:
|
||||
If you want to manually rescale the waveform amplitude of channels one by one,
|
||||
|
@ -420,12 +442,12 @@ class Schedule(ScheduleComponent):
|
|||
pulse.MeasureChannels(0): 5.0}
|
||||
|
||||
When the channel to plot is not included in the ``channel_scales`` dictionary,
|
||||
scaling factor of that channel is overwritten by the value of ``scale` argument.
|
||||
scaling factor of that channel is overwritten by the value of ``scale`` argument.
|
||||
In default, waveform amplitude is normalized by the maximum amplitude of the channel.
|
||||
The scaling factor is displayed under the channel name alias.
|
||||
|
||||
Returns:
|
||||
matplotlib.figure: A matplotlib figure object of the pulse schedule.
|
||||
matplotlib.Figure: A matplotlib figure object of the pulse schedule.
|
||||
"""
|
||||
# pylint: disable=invalid-name, cyclic-import
|
||||
if scaling is not None:
|
||||
|
|
|
@ -69,11 +69,10 @@ class Chi(QuantumChannel):
|
|||
QiskitError: if input data is not an N-qubit channel or
|
||||
cannot be initialized as a Chi-matrix.
|
||||
|
||||
Additional Information
|
||||
----------------------
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. The Chi matrix
|
||||
representation is only valid for N-qubit channels.
|
||||
Additional Information:
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. The Chi matrix
|
||||
representation is only valid for N-qubit channels.
|
||||
"""
|
||||
# If the input is a raw list or matrix we assume that it is
|
||||
# already a Chi matrix.
|
||||
|
|
|
@ -75,13 +75,12 @@ class Choi(QuantumChannel):
|
|||
QiskitError: if input data cannot be initialized as a
|
||||
Choi matrix.
|
||||
|
||||
Additional Information
|
||||
----------------------
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. If the input data is
|
||||
a Numpy array of shape (4**N, 4**N) qubit systems will be used. If
|
||||
the input operator is not an N-qubit operator, it will assign a
|
||||
single subsystem with dimension specified by the shape of the input.
|
||||
Additional Information:
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. If the input data is
|
||||
a Numpy array of shape (4**N, 4**N) qubit systems will be used. If
|
||||
the input operator is not an N-qubit operator, it will assign a
|
||||
single subsystem with dimension specified by the shape of the input.
|
||||
"""
|
||||
# If the input is a raw list or matrix we assume that it is
|
||||
# already a Choi matrix.
|
||||
|
|
|
@ -78,13 +78,13 @@ class Kraus(QuantumChannel):
|
|||
QiskitError: if input data cannot be initialized as a
|
||||
a list of Kraus matrices.
|
||||
|
||||
Additional Information
|
||||
----------------------
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. If the input data is
|
||||
a list of Numpy arrays of shape (2**N, 2**N) qubit systems will be used. If
|
||||
the input does not correspond to an N-qubit channel, it will assign a
|
||||
single subsystem with dimension specified by the shape of the input.
|
||||
Additional Information:
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. If the input data is
|
||||
a list of Numpy arrays of shape (2**N, 2**N) qubit systems will be
|
||||
used. If the input does not correspond to an N-qubit channel, it
|
||||
will assign a single subsystem with dimension specified by the
|
||||
shape of the input.
|
||||
"""
|
||||
# If the input is a list or tuple we assume it is a list of Kraus
|
||||
# matrices, if it is a numpy array we assume that it is a single Kraus
|
||||
|
|
|
@ -79,11 +79,10 @@ class PTM(QuantumChannel):
|
|||
QiskitError: if input data is not an N-qubit channel or
|
||||
cannot be initialized as a PTM.
|
||||
|
||||
Additional Information
|
||||
----------------------
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. The PTM
|
||||
representation is only valid for N-qubit channels.
|
||||
Additional Information:
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. The PTM
|
||||
representation is only valid for N-qubit channels.
|
||||
"""
|
||||
# If the input is a raw list or matrix we assume that it is
|
||||
# already a Chi matrix.
|
||||
|
|
|
@ -180,7 +180,7 @@ class QuantumChannel(BaseOperator):
|
|||
otherwise it will be added as a kraus simulator instruction.
|
||||
|
||||
Returns:
|
||||
Instruction: A kraus instruction for the channel.
|
||||
qiskit.circuit.Instruction: A kraus instruction for the channel.
|
||||
|
||||
Raises:
|
||||
QiskitError: if input data is not an N-qubit CPTP quantum channel.
|
||||
|
|
|
@ -75,12 +75,11 @@ class Stinespring(QuantumChannel):
|
|||
QiskitError: if input data cannot be initialized as a
|
||||
a list of Kraus matrices.
|
||||
|
||||
Additional Information
|
||||
----------------------
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. This can fail for the
|
||||
Stinespring operator if the output dimension cannot be automatically
|
||||
determined.
|
||||
Additional Information:
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. This can fail for the
|
||||
Stinespring operator if the output dimension cannot be automatically
|
||||
determined.
|
||||
"""
|
||||
# If the input is a list or tuple we assume it is a pair of general
|
||||
# Stinespring matrices. If it is a numpy array we assume that it is
|
||||
|
|
|
@ -68,13 +68,12 @@ class SuperOp(QuantumChannel):
|
|||
QiskitError: if input data cannot be initialized as a
|
||||
superoperator.
|
||||
|
||||
Additional Information
|
||||
----------------------
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. If the input data is
|
||||
a Numpy array of shape (4**N, 4**N) qubit systems will be used. If
|
||||
the input operator is not an N-qubit operator, it will assign a
|
||||
single subsystem with dimension specified by the shape of the input.
|
||||
Additional Information:
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. If the input data is
|
||||
a Numpy array of shape (4**N, 4**N) qubit systems will be used. If
|
||||
the input operator is not an N-qubit operator, it will assign a
|
||||
single subsystem with dimension specified by the shape of the input.
|
||||
"""
|
||||
# If the input is a raw list or matrix we assume that it is
|
||||
# already a superoperator.
|
||||
|
|
|
@ -65,13 +65,12 @@ class Operator(BaseOperator):
|
|||
Raises:
|
||||
QiskitError: if input data cannot be initialized as an operator.
|
||||
|
||||
Additional Information
|
||||
----------------------
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. If the input data is
|
||||
a Numpy array of shape (2**N, 2**N) qubit systems will be used. If
|
||||
the input operator is not an N-qubit operator, it will assign a
|
||||
single subsystem with dimension specified by the shape of the input.
|
||||
Additional Information:
|
||||
If the input or output dimensions are None, they will be
|
||||
automatically determined from the input data. If the input data is
|
||||
a Numpy array of shape (2**N, 2**N) qubit systems will be used. If
|
||||
the input operator is not an N-qubit operator, it will assign a
|
||||
single subsystem with dimension specified by the shape of the input.
|
||||
"""
|
||||
if isinstance(data, (list, np.ndarray)):
|
||||
# Default initialization from list or numpy array matrix
|
||||
|
|
|
@ -259,12 +259,12 @@ class DensityMatrix(QuantumState):
|
|||
def from_instruction(cls, instruction):
|
||||
"""Return the output density matrix of an instruction.
|
||||
|
||||
The statevector is initialized in the state |0,...,0> of the same
|
||||
number of qubits as the input instruction or circuit, evolved
|
||||
The statevector is initialized in the state :math:`|{0,\\ldots,0}\\rangle` of
|
||||
the same number of qubits as the input instruction or circuit, evolved
|
||||
by the input instruction, and the output statevector returned.
|
||||
|
||||
Args:
|
||||
instruction (Instruction or QuantumCircuit): instruction or circuit
|
||||
instruction (qiskit.circuit.Instruction or QuantumCircuit): instruction or circuit
|
||||
|
||||
Returns:
|
||||
DensityMatrix: the final density matrix.
|
||||
|
|
|
@ -267,8 +267,26 @@ class Statevector(QuantumState):
|
|||
def from_label(cls, label):
|
||||
"""Return a tensor product of Pauli X,Y,Z eigenstates.
|
||||
|
||||
.. list-table:: Single-qubit state labels
|
||||
:header-rows: 1
|
||||
|
||||
* - Label
|
||||
- Statevector
|
||||
* - ``"0"``
|
||||
- :math:`[1, 0]`
|
||||
* - ``"1"``
|
||||
- :math:`[0, 1]`
|
||||
* - ``"+"``
|
||||
- :math:`[1 / \\sqrt{2}, 1 / \\sqrt{2}]`
|
||||
* - ``"-"``
|
||||
- :math:`[1 / \\sqrt{2}, -1 / \\sqrt{2}]`
|
||||
* - ``"r"``
|
||||
- :math:`[1 / \\sqrt{2}, i / \\sqrt{2}]`
|
||||
* - ``"l"``
|
||||
- :math:`[1 / \\sqrt{2}, -i / \\sqrt{2}]`
|
||||
|
||||
Args:
|
||||
label (string): a eigenstate string ket label 0,1,+,-,r,l.
|
||||
label (string): a eigenstate string ket label ``0``,``1``,``+``,``-``,``r``,``l``.
|
||||
|
||||
Returns:
|
||||
Statevector: The N-qubit basis state density matrix.
|
||||
|
@ -277,14 +295,6 @@ class Statevector(QuantumState):
|
|||
QiskitError: if the label contains invalid characters, or the length
|
||||
of the label is larger than an explicitly specified num_qubits.
|
||||
|
||||
Additional Information:
|
||||
The labels correspond to the single-qubit states:
|
||||
'0': [1, 0]
|
||||
'1': [0, 1]
|
||||
'+': [1 / sqrt(2), 1 / sqrt(2)]
|
||||
'-': [1 / sqrt(2), -1 / sqrt(2)]
|
||||
'r': [1 / sqrt(2), 1j / sqrt(2)]
|
||||
'l': [1 / sqrt(2), -1j / sqrt(2)]
|
||||
"""
|
||||
# Check label is valid
|
||||
if re.match(r'^[01rl\-+]+$', label) is None:
|
||||
|
@ -325,12 +335,12 @@ class Statevector(QuantumState):
|
|||
def from_instruction(cls, instruction):
|
||||
"""Return the output statevector of an instruction.
|
||||
|
||||
The statevector is initialized in the state |0,...,0> of the same
|
||||
number of qubits as the input instruction or circuit, evolved
|
||||
The statevector is initialized in the state :math:`|{0,\\ldots,0}\\rangle` of the
|
||||
same number of qubits as the input instruction or circuit, evolved
|
||||
by the input instruction, and the output statevector returned.
|
||||
|
||||
Args:
|
||||
instruction (Instruction or QuantumCircuit): instruction or circuit
|
||||
instruction (qiskit.circuit.Instruction or QuantumCircuit): instruction or circuit
|
||||
|
||||
Returns:
|
||||
Statevector: The final statevector.
|
||||
|
|
|
@ -261,7 +261,7 @@ def Ud(a, b, c):
|
|||
|
||||
|
||||
def trace_to_fid(trace):
|
||||
"""Average gate fidelity is Fbar = (d + |Tr (Utarget.U^dag)|^2) / d(d+1)
|
||||
"""Average gate fidelity is :math:`Fbar = (d + |Tr (Utarget \\cdot U^dag)|^2) / d(d+1)`
|
||||
M. Horodecki, P. Horodecki and R. Horodecki, PRA 60, 1888 (1999)"""
|
||||
return (4 + np.abs(trace)**2)/20
|
||||
|
||||
|
@ -350,7 +350,8 @@ class TwoQubitBasisDecomposer():
|
|||
self.decomp3_supercontrolled]
|
||||
|
||||
def traces(self, target):
|
||||
"""Give the expected traces |Tr(U.Utarget^dag)| for different number of basis gates"""
|
||||
"""Give the expected traces :math:`|Tr(U \\cdot Utarget^dag)|` for different number of
|
||||
basis gates."""
|
||||
# Future gotcha: extending this to non-supercontrolled basis.
|
||||
# Careful: closest distance between a1,b1,c1 and a2,b2,c2 may be between reflections.
|
||||
# This doesn't come up if either c1==0 or c2==0 but otherwise be careful.
|
||||
|
@ -366,7 +367,7 @@ class TwoQubitBasisDecomposer():
|
|||
def decomp0(target):
|
||||
"""Decompose target ~Ud(x, y, z) with 0 uses of the basis gate.
|
||||
Result Ur has trace:
|
||||
|Tr(Ur.Utarget^dag)| = 4|(cos(x)cos(y)cos(z)+ j sin(x)sin(y)sin(z)|,
|
||||
:math:`|Tr(Ur.Utarget^dag)| = 4|(cos(x)cos(y)cos(z)+ j sin(x)sin(y)sin(z)|`,
|
||||
which is optimal for all targets and bases"""
|
||||
|
||||
U0l = target.K1l.dot(target.K2l)
|
||||
|
@ -377,7 +378,10 @@ class TwoQubitBasisDecomposer():
|
|||
def decomp1(self, target):
|
||||
"""Decompose target ~Ud(x, y, z) with 1 uses of the basis gate ~Ud(a, b, c).
|
||||
Result Ur has trace:
|
||||
|Tr(Ur.Utarget^dag)| = 4|cos(x-a)cos(y-b)cos(z-c) + j sin(x-a)sin(y-b)sin(z-c)|,
|
||||
.. math::
|
||||
|
||||
|Tr(Ur.Utarget^dag)| = 4|cos(x-a)cos(y-b)cos(z-c) + j sin(x-a)sin(y-b)sin(z-c)|
|
||||
|
||||
which is optimal for all targets and bases with z==0 or c==0"""
|
||||
# FIXME: fix for z!=0 and c!=0 using closest reflection (not always in the Weyl chamber)
|
||||
U0l = target.K1l.dot(self.basis.K1l.T.conj())
|
||||
|
@ -389,14 +393,19 @@ class TwoQubitBasisDecomposer():
|
|||
|
||||
def decomp2_supercontrolled(self, target):
|
||||
"""Decompose target ~Ud(x, y, z) with 2 uses of the basis gate.
|
||||
For supercontrolled basis ~Ud(pi/4, b, 0), all b, result Ur has trace:
|
||||
|Tr(Ur.Utarget^dag)| = 4cos(z)
|
||||
which is the optimal approximation for basis of CNOT-class ~Ud(pi/4, 0, 0)
|
||||
or DCNOT-class ~Ud(pi/4, pi/4, 0) and any target.
|
||||
|
||||
For supercontrolled basis ~Ud(pi/4, b, 0), all b, result Ur has trace
|
||||
.. math::
|
||||
|
||||
|Tr(Ur.Utarget^dag)| = 4cos(z)
|
||||
|
||||
which is the optimal approximation for basis of CNOT-class ``~Ud(pi/4, 0, 0)``
|
||||
or DCNOT-class ``~Ud(pi/4, pi/4, 0)`` and any target.
|
||||
May be sub-optimal for b!=0 (e.g. there exists exact decomposition for any target using B
|
||||
B~Ud(pi/4, pi/8, 0), but not this decomposition.)
|
||||
This is an exact decomposition for supercontrolled basis and target ~Ud(x, y, 0).
|
||||
No guarantees for non-supercontrolled basis."""
|
||||
``B~Ud(pi/4, pi/8, 0)``, but not this decomposition.)
|
||||
This is an exact decomposition for supercontrolled basis and target ``~Ud(x, y, 0)``.
|
||||
No guarantees for non-supercontrolled basis.
|
||||
"""
|
||||
|
||||
U0l = target.K1l.dot(self.q0l)
|
||||
U0r = target.K1r.dot(self.q0r)
|
||||
|
|
|
@ -42,7 +42,7 @@ def format_meas_map(meas_map: List[List[int]]) -> Dict[int, List[int]]:
|
|||
|
||||
|
||||
def measure(qubits: List[int],
|
||||
backend: Optional['BaseBackend'] = None,
|
||||
backend=None,
|
||||
inst_map: Optional[InstructionScheduleMap] = None,
|
||||
meas_map: Optional[Union[List[List[int]], Dict[int, List[int]]]] = None,
|
||||
qubit_mem_slots: Optional[Dict[int, int]] = None,
|
||||
|
@ -57,7 +57,8 @@ def measure(qubits: List[int],
|
|||
|
||||
Args:
|
||||
qubits: List of qubits to be measured.
|
||||
backend: A backend instance, which contains hardware-specific data required for scheduling.
|
||||
backend (BaseBackend): A backend instance, which contains hardware-specific data
|
||||
required for scheduling.
|
||||
inst_map: Mapping of circuit operations to pulse schedules. If None, defaults to the
|
||||
``instruction_schedule_map`` of ``backend``.
|
||||
meas_map: List of sets of qubits that must be measured together. If None, defaults to
|
||||
|
@ -113,12 +114,13 @@ def measure(qubits: List[int],
|
|||
return schedule
|
||||
|
||||
|
||||
def measure_all(backend: 'BaseBackend') -> Schedule:
|
||||
def measure_all(backend) -> Schedule:
|
||||
"""
|
||||
Return a Schedule which measures all qubits of the given backend.
|
||||
|
||||
Args:
|
||||
backend: A backend instance, which contains hardware-specific data required for scheduling.
|
||||
backend (BaseBackend): A backend instance, which contains hardware-specific data
|
||||
required for scheduling.
|
||||
|
||||
Returns:
|
||||
A schedule corresponding to the inputs provided.
|
||||
|
|
|
@ -48,7 +48,8 @@ Quantum Information
|
|||
vectorize
|
||||
devectorize
|
||||
choi_to_pauli
|
||||
chop, outer
|
||||
chop
|
||||
outer
|
||||
entropy
|
||||
shannon_entropy
|
||||
concurrence
|
||||
|
|
|
@ -185,11 +185,13 @@ def vectorize(density_matrix, method='col'):
|
|||
|
||||
Args:
|
||||
density_matrix (ndarray): a density matrix.
|
||||
method (str): the method of vectorization. Allowed values are
|
||||
- 'col' (default) flattens to column-major vector.
|
||||
- 'row' flattens to row-major vector.
|
||||
- 'pauli' flattens in the n-qubit Pauli basis.
|
||||
- 'pauli-weights': flattens in the n-qubit Pauli basis ordered by
|
||||
method (str): the method of vectorization.
|
||||
Allowed values are:
|
||||
|
||||
* 'col' (default) flattens to column-major vector.
|
||||
* 'row' flattens to row-major vector.
|
||||
* 'pauli' flattens in the n-qubit Pauli basis.
|
||||
* 'pauli-weights': flattens in the n-qubit Pauli basis ordered by
|
||||
weight.
|
||||
|
||||
Returns:
|
||||
|
@ -225,12 +227,14 @@ def devectorize(vectorized_mat, method='col'):
|
|||
|
||||
Args:
|
||||
vectorized_mat (ndarray): a vectorized density matrix.
|
||||
method (str): the method of devectorization. Allowed values are
|
||||
- 'col' (default): flattens to column-major vector.
|
||||
- 'row': flattens to row-major vector.
|
||||
- 'pauli': flattens in the n-qubit Pauli basis.
|
||||
- 'pauli-weights': flattens in the n-qubit Pauli basis ordered by
|
||||
weight.
|
||||
method (str): the method of devectorization.
|
||||
Allowed values are
|
||||
|
||||
* 'col' (default): flattens to column-major vector.
|
||||
* 'row': flattens to row-major vector.
|
||||
* 'pauli': flattens in the n-qubit Pauli basis.
|
||||
* 'pauli-weights': flattens in the n-qubit Pauli basis ordered by
|
||||
weight.
|
||||
|
||||
Returns:
|
||||
ndarray: the resulting matrix.
|
||||
|
@ -263,26 +267,29 @@ def devectorize(vectorized_mat, method='col'):
|
|||
|
||||
|
||||
def choi_to_pauli(choi, order=1):
|
||||
"""
|
||||
Convert a Choi-matrix to a Pauli-basis superoperator.
|
||||
"""Convert a Choi-matrix to a Pauli-basis superoperator.
|
||||
|
||||
Note that this function assumes that the Choi-matrix
|
||||
is defined in the standard column-stacking convention
|
||||
and is normalized to have trace 1. For a channel E this
|
||||
is defined as: choi = (I \\otimes E)(bell_state).
|
||||
is defined as: :math:`choi = (I \\otimes E)(bell_state)`.
|
||||
|
||||
The resulting 'rauli' R acts on input states as
|
||||
|rho_out>_p = R.|rho_in>_p
|
||||
where |rho> = vectorize(rho, method='pauli') for order=1
|
||||
and |rho> = vectorize(rho, method='pauli_weights') for order=0.
|
||||
|
||||
.. math::
|
||||
|
||||
|{\\rho_{out}}_p\\rangle = R \\cdot |{\\rho_{in}}_p\\rangle.
|
||||
|
||||
where :math:`|{\\rho}\\rangle =` ``vectorize(rho, method='pauli')`` for order=1
|
||||
and :math:`|{\\rho}\\rangle =` ``vectorize(rho, method='pauli_weights')`` for order=0.
|
||||
|
||||
Args:
|
||||
choi (matrix): the input Choi-matrix.
|
||||
order (int): ordering of the Pauli group vector.
|
||||
order=1 (default) is standard lexicographic ordering.
|
||||
Eg: [II, IX, IY, IZ, XI, XX, XY,...]
|
||||
order=0 is ordered by weights.
|
||||
Eg. [II, IX, IY, IZ, XI, XY, XZ, XX, XY,...]
|
||||
``order=1`` (default) is standard lexicographic ordering
|
||||
(e.g. ``[II, IX, IY, IZ, XI, XX, XY,...]``)
|
||||
``order=0`` is ordered by weights
|
||||
(e.g. ``[II, IX, IY, IZ, XI, XY, XZ, XX, XY,...]``)
|
||||
|
||||
Returns:
|
||||
np.array: A superoperator in the Pauli basis.
|
||||
|
@ -332,8 +339,7 @@ def chop(array, epsilon=1e-10):
|
|||
|
||||
|
||||
def outer(vector1, vector2=None):
|
||||
"""
|
||||
Construct the outer product of two vectors.
|
||||
"""Construct the outer product of two vectors.
|
||||
|
||||
The second vector argument is optional, if absent the projector
|
||||
of the first vector will be returned.
|
||||
|
@ -343,7 +349,7 @@ def outer(vector1, vector2=None):
|
|||
vector2 (ndarray): the (optional) second vector.
|
||||
|
||||
Returns:
|
||||
np.array: The matrix |v1><v2|.
|
||||
np.array: The matrix :math:`|v1\\rangle\\langle{v2}|`.
|
||||
|
||||
"""
|
||||
warnings.warn(
|
||||
|
|
|
@ -68,20 +68,20 @@ class CustomSolver(RecursiveBacktrackingSolver):
|
|||
|
||||
|
||||
class CSPLayout(AnalysisPass):
|
||||
"""
|
||||
If possible, chooses a Layout as a CSP, using backtracking.
|
||||
"""
|
||||
"""If possible, chooses a Layout as a CSP, using backtracking."""
|
||||
|
||||
def __init__(self, coupling_map, strict_direction=False, seed=None, call_limit=1000,
|
||||
time_limit=10):
|
||||
"""
|
||||
If possible, chooses a Layout as a CSP, using backtracking. If not possible,
|
||||
does not set the layout property. In all the cases, the property ``CSPLayout_stop_reason``
|
||||
will be added with one of the following values:
|
||||
- solution found: If a perfect layout was found.
|
||||
- nonexistent solution: If no perfect layout was found and every combination was checked.
|
||||
- call limit reached: If no perfect layout was found and the call limit was reached.
|
||||
- time limit reached: If no perfect layout was found and the time limit was reached.
|
||||
"""If possible, chooses a Layout as a CSP, using backtracking.
|
||||
|
||||
If not possible, does not set the layout property. In all the cases, the property
|
||||
:meth:`qiskit.transpiler.passes.CSPLayout_stop_reason` will be added with one of the
|
||||
following values:
|
||||
|
||||
* solution found: If a perfect layout was found.
|
||||
* nonexistent solution: If no perfect layout was found and every combination was checked.
|
||||
* call limit reached: If no perfect layout was found and the call limit was reached.
|
||||
* time limit reached: If no perfect layout was found and the time limit was reached.
|
||||
|
||||
Args:
|
||||
coupling_map (Coupling): Directed graph representing a coupling map.
|
||||
|
|
|
@ -51,12 +51,9 @@ ONEQ_XTALK_THRESH = 2
|
|||
|
||||
|
||||
class CrosstalkAdaptiveSchedule(TransformationPass):
|
||||
"""
|
||||
Crosstalk mitigation through adaptive instruction scheduling.
|
||||
"""
|
||||
"""Crosstalk mitigation through adaptive instruction scheduling."""
|
||||
def __init__(self, backend_prop, crosstalk_prop, weight_factor=0.5, measured_qubits=None):
|
||||
"""
|
||||
CrosstalkAdaptiveSchedule initializer.
|
||||
"""CrosstalkAdaptiveSchedule initializer.
|
||||
|
||||
Args:
|
||||
backend_prop (BackendProperties): backend properties object
|
||||
|
@ -68,18 +65,21 @@ class CrosstalkAdaptiveSchedule(TransformationPass):
|
|||
We currently ignore crosstalk between pairs of single-qubit gates.
|
||||
Gate pairs which are not specified are assumed to be crosstalk free.
|
||||
|
||||
Example: crosstalk_prop = {(0, 1) : {(2, 3) : 0.2, (2) : 0.15},
|
||||
(4, 5) : {(2, 3) : 0.1},
|
||||
(2, 3) : {(0, 1) : 0.05, (4, 5): 0.05}}
|
||||
Example::
|
||||
|
||||
crosstalk_prop = {(0, 1) : {(2, 3) : 0.2, (2) : 0.15},
|
||||
(4, 5) : {(2, 3) : 0.1},
|
||||
(2, 3) : {(0, 1) : 0.05, (4, 5): 0.05}}
|
||||
|
||||
The keys of the crosstalk_prop are tuples for ordered tuples for CX gates
|
||||
e.g., (0, 1) corresponding to CX 0, 1 in the hardware.
|
||||
Each key has an associated value dict which specifies the conditional error rates
|
||||
with nearby gates e.g., (0, 1) : {(2, 3) : 0.2, (2) : 0.15} means that
|
||||
with nearby gates e.g., ``(0, 1) : {(2, 3) : 0.2, (2) : 0.15}`` means that
|
||||
CNOT 0, 1 has an error rate of 0.2 when it is executed in parallel with CNOT 2,3
|
||||
and an error rate of 0.15 when it is executed in parallel with a single qubit
|
||||
gate on qubit 2.
|
||||
weight_factor (float): weight of gate error/crosstalk terms in the objective
|
||||
weight_factor*fidelities + (1-weight_factor)*decoherence errors.
|
||||
:math:`weight_factor*fidelities + (1-weight_factor)*decoherence errors`.
|
||||
Weight can be varied from 0 to 1, with 0 meaning that only decoherence
|
||||
errors are optimized and 1 meaning that only crosstalk errors are optimized.
|
||||
weight_factor should be tuned per application to get the best results.
|
||||
|
|
|
@ -46,9 +46,9 @@ class PassManager:
|
|||
callback: DEPRECATED - A callback function that will be called after each pass
|
||||
execution.
|
||||
|
||||
.. deprecated ::
|
||||
.. deprecated:: 0.13.0
|
||||
The ``callback`` parameter is deprecated in favor of
|
||||
``PassManager.run(..., callback=callback, ...).
|
||||
``PassManager.run(..., callback=callback, ...)``.
|
||||
"""
|
||||
self.callback = None
|
||||
|
||||
|
@ -276,28 +276,24 @@ class PassManager:
|
|||
self.property_set = running_passmanager.property_set
|
||||
return result
|
||||
|
||||
def draw(
|
||||
self,
|
||||
filename: str = None,
|
||||
style: Dict = None,
|
||||
raw: bool = False
|
||||
) -> Union['PIL.Image', None]:
|
||||
def draw(self, filename=None, style=None, raw=False):
|
||||
"""Draw the pass manager.
|
||||
|
||||
This function needs `pydot <https://github.com/erocarrera/pydot>`__, which in turn needs
|
||||
`Graphviz <https://www.graphviz.org/>`__ to be installed.
|
||||
|
||||
Args:
|
||||
filename: file path to save image to.
|
||||
style: keys are the pass classes and the values are the colors to make them. An
|
||||
filename (str): file path to save image to.
|
||||
style (dict): keys are the pass classes and the values are the colors to make them. An
|
||||
example can be seen in the DEFAULT_STYLE. An ordered dict can be used to ensure
|
||||
a priority coloring when pass falls into multiple categories. Any values not
|
||||
included in the provided dict will be filled in from the default dict.
|
||||
raw: If ``True``, save the raw Dot output instead of the image.
|
||||
raw (bool): If ``True``, save the raw Dot output instead of the image.
|
||||
|
||||
Returns:
|
||||
an in-memory representation of the pass manager, or ``None`` if no image was generated
|
||||
or PIL is not installed.
|
||||
Optional[PassManager]: an in-memory representation of the pass manager, or ``None``
|
||||
if no image was generated or `Pillow <https://pypi.org/project/Pillow/>`__
|
||||
is not installed.
|
||||
|
||||
Raises:
|
||||
ImportError: when nxpd or pydot not installed.
|
||||
|
|
|
@ -250,6 +250,7 @@ def bind_schema(schema, **kwargs):
|
|||
"""Class decorator for adding schema validation to its instances.
|
||||
|
||||
The decorator acts on the model class by adding:
|
||||
|
||||
* a class attribute ``schema`` with the schema used for validation
|
||||
* a class attribute ``shallow_schema`` used for validation during
|
||||
instantiation.
|
||||
|
|
|
@ -32,9 +32,9 @@ from qiskit.visualization.pulse import interpolation
|
|||
from qiskit.pulse.channels import (DriveChannel, ControlChannel,
|
||||
MeasureChannel, AcquireChannel,
|
||||
SnapshotChannel)
|
||||
from qiskit.pulse.commands import FrameChangeInstruction
|
||||
from qiskit.pulse import (SamplePulse, FrameChange, PersistentValue, Snapshot,
|
||||
Acquire, PulseError, ParametricPulse)
|
||||
from qiskit.pulse.commands.frame_change import FrameChangeInstruction
|
||||
|
||||
|
||||
class EventsOutputChannels:
|
||||
|
|
|
@ -17,7 +17,7 @@ features:
|
|||
the '$' pair. Also if you want to use a dollar sign in your label make sure
|
||||
you escape it in the label string (ie ``'\$'``).
|
||||
|
||||
You can mix and match this passthrough with the utf8 -> latex conversion to
|
||||
You can mix and match this passthrough with the utf8 to latex conversion to
|
||||
create the exact label you want, for example::
|
||||
|
||||
from qiskit import circuit
|
||||
|
|
|
@ -14,7 +14,7 @@ features:
|
|||
|
||||
* ``__init__`` takes no arguments
|
||||
* ``cmds`` and ``cmd_qubits`` are deprecated and replaced with
|
||||
``instructions`` and ``qubits_with_instruction``
|
||||
``instructions`` and ``qubits_with_instruction``
|
||||
|
||||
Example::
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ features:
|
|||
|
||||
For example:
|
||||
|
||||
.. jupyter-execute::
|
||||
.. code-block:: python
|
||||
|
||||
from qiskit.pulse import *
|
||||
from qiskit.pulse import pulse_lib
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
deprecations:
|
||||
- |
|
||||
The Exception ``TranspilerAccessError´´ has been deprecated. An
|
||||
alternative function ``TranspilerError´´ can be used instead to provide
|
||||
The Exception ``TranspilerAccessError`` has been deprecated. An
|
||||
alternative function ``TranspilerError`` can be used instead to provide
|
||||
the same functionality. This alternative function provides the exact same
|
||||
functionality but with greater generality.
|
||||
functionality but with greater generality.
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
deprecations:
|
||||
- Buffers in Pulse are deprecated. If a nonzero buffer is supplied, a warning
|
||||
will be issued with a reminder to use a Delay instead. Other options would
|
||||
include adding samples to a pulse instruction which are (0.+0.j) or setting
|
||||
the start time of the next pulse to `schedule.duration + buffer`.
|
||||
include adding samples to a pulse instruction which are :math:`(0.+0.j)` or
|
||||
setting the start time of the next pulse to `schedule.duration + buffer`.
|
||||
|
|
|
@ -5,11 +5,13 @@ deprecations:
|
|||
instruction parameters are deprecated and will be removed in a future
|
||||
release. You'll need to convert the input to one of the supported types
|
||||
which are:
|
||||
* ``int``
|
||||
* ``float``
|
||||
* ``complex``
|
||||
* ``str``
|
||||
* ``np.ndarray``
|
||||
|
||||
* ``int``
|
||||
* ``float``
|
||||
* ``complex``
|
||||
* ``str``
|
||||
* ``np.ndarray``
|
||||
|
||||
other:
|
||||
- |
|
||||
All sympy parameter output type support have been been removed (or
|
||||
|
|
|
@ -21,10 +21,10 @@ import numpy as np
|
|||
from qiskit.pulse.channels import (MemorySlot, RegisterSlot, DriveChannel, AcquireChannel,
|
||||
SnapshotChannel, MeasureChannel)
|
||||
from qiskit.pulse.commands import (FrameChange, Acquire, PersistentValue, Snapshot, Delay,
|
||||
functional_pulse, Instruction, AcquireInstruction,
|
||||
functional_pulse, AcquireInstruction,
|
||||
PulseInstruction, FrameChangeInstruction, Gaussian, Drag,
|
||||
GaussianSquare, ConstantPulse)
|
||||
from qiskit.pulse import pulse_lib, SamplePulse
|
||||
from qiskit.pulse import pulse_lib, SamplePulse, Instruction
|
||||
from qiskit.pulse.timeslots import TimeslotCollection, Interval
|
||||
from qiskit.pulse.exceptions import PulseError
|
||||
from qiskit.pulse.schedule import Schedule, ParameterizedSchedule
|
||||
|
|
|
@ -12,4 +12,6 @@
|
|||
# copyright notice, and modified files need to carry a notice indicating
|
||||
# that they have been altered from the originals.
|
||||
|
||||
# pylint: disable=cyclic-import
|
||||
|
||||
"""Qiskit pulse scheduling tests."""
|
||||
|
|
5
tox.ini
5
tox.ini
|
@ -35,9 +35,12 @@ commands =
|
|||
|
||||
[testenv:docs]
|
||||
basepython = python3
|
||||
setenv =
|
||||
{[testenv]setenv}
|
||||
QISKIT_DOCS=TRUE
|
||||
deps =
|
||||
-r{toxinidir}/requirements-dev.txt
|
||||
qiskit-aer
|
||||
qiskit-ibmq-provider
|
||||
commands =
|
||||
sphinx-build -b html docs/ docs/_build/html {posargs}
|
||||
sphinx-build -W -b html docs/ docs/_build/html {posargs}
|
||||
|
|
Loading…
Reference in New Issue