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 commit e3cb2f40e0.

* Ignore cyclic-import in scheduler tests

* Trying to fix cyclic errors

* Fix import errors

* Revert "Trying to fix cyclic errors"

This reverts commit 22709cf75c.

* Revert "Revert "Trying to fix cyclic errors""

This reverts commit 3132258e37.

* 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:
Ali Javadi-Abhari 2020-03-05 10:58:28 -05:00 committed by GitHub
parent 1ec9f43eea
commit fc9c8f7fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 566 additions and 444 deletions

View File

@ -215,7 +215,7 @@ stages:
sudo apt install -y graphviz sudo apt install -y graphviz
displayName: 'Install dependencies' displayName: 'Install dependencies'
- bash: | - bash: |
tox -edocs -- -j auto tox -edocs
displayName: 'Run Docs build' displayName: 'Run Docs build'
- task: PublishBuildArtifacts@1 - task: PublishBuildArtifacts@1
displayName: 'Publish docs' displayName: 'Publish docs'

33
docs/apidocs/terra.rst Normal file
View File

@ -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

View File

@ -29,7 +29,6 @@ class ControlledGate(Gate):
Attributes: Attributes:
num_ctrl_qubits (int): The number of control qubits. num_ctrl_qubits (int): The number of control qubits.
ctrl_state (int): The control state in decimal notation.
Args: Args:
name (str): The Qobj name of the gate. name (str): The Qobj name of the gate.

View File

@ -247,7 +247,7 @@ class Instruction:
It does not invert any gate. It does not invert any gate.
Returns: Returns:
Instruction: a fresh gate with sub-gates reversed qiskit.circuit.Instruction: a fresh gate with sub-gates reversed
""" """
if not self._definition: if not self._definition:
return self.copy() return self.copy()
@ -268,7 +268,7 @@ class Instruction:
implement their own inverse (e.g. T and Tdg, Barrier, etc.) implement their own inverse (e.g. T and Tdg, Barrier, etc.)
Returns: Returns:
Instruction: a fresh instruction for the inverse qiskit.circuit.Instruction: a fresh instruction for the inverse
Raises: Raises:
CircuitError: if the instruction is not composite CircuitError: if the instruction is not composite
@ -300,7 +300,7 @@ class Instruction:
if None then the name stays the same. if None then the name stays the same.
Returns: 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 updated if it was provided
""" """
cpy = copy.copy(self) cpy = copy.copy(self)
@ -366,7 +366,7 @@ class Instruction:
n (int): Number of times to repeat the instruction n (int): Number of times to repeat the instruction
Returns: Returns:
Instruction: Containing the definition. qiskit.circuit.Instruction: Containing the definition.
Raises: Raises:
CircuitError: If n < 1. CircuitError: If n < 1.

View File

@ -444,12 +444,12 @@ class QuantumCircuit:
the circuit in place. Expands qargs and cargs. the circuit in place. Expands qargs and cargs.
Args: 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 qargs (list(argument)): qubits to attach instruction to
cargs (list(argument)): clbits to attach instruction to cargs (list(argument)): clbits to attach instruction to
Returns: 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 # Convert input to instruction
if not isinstance(instruction, Instruction) and hasattr(instruction, 'to_instruction'): if not isinstance(instruction, Instruction) and hasattr(instruction, 'to_instruction'):
@ -578,7 +578,7 @@ class QuantumCircuit:
parameterize the instruction. parameterize the instruction.
Returns: Returns:
Instruction: a composite instruction encapsulating this circuit qiskit.circuit.Instruction: a composite instruction encapsulating this circuit
(can be decomposed back) (can be decomposed back)
""" """
from qiskit.converters.circuit_to_instruction import circuit_to_instruction from qiskit.converters.circuit_to_instruction import circuit_to_instruction

View File

@ -62,61 +62,60 @@ def transpile(circuits: Union[QuantumCircuit, List[QuantumCircuit]],
will override the backend's. will override the backend's.
.. note:: .. note::
The backend arg is purely for convenience. The resulting The backend arg is purely for convenience. The resulting
circuit may be run on any backend as long as it is compatible. circuit may be run on any backend as long as it is compatible.
basis_gates: List of basis gate names to unroll to. basis_gates: List of basis gate names to unroll to
e.g:: (e.g: ``['u1', 'u2', 'u3', 'cx']``). If ``None``, do not unroll.
['u1', 'u2', 'u3', 'cx']
If ``None``, do not unroll.
coupling_map: Coupling map (perhaps custom) to target in mapping. coupling_map: Coupling map (perhaps custom) to target in mapping.
Multiple formats are supported: Multiple formats are supported:
1. ``CouplingMap`` instance
2. List #. ``CouplingMap`` instance
Must be given as an adjacency matrix, where each entry #. List, must be given as an adjacency matrix, where each entry
specifies all two-qubit interactions supported by backend, specifies all two-qubit interactions supported by backend,
e.g:: e.g: ``[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]]``
[[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 backend_properties: properties returned by a backend, including information on gate
errors, readout errors, qubit coherence times, etc. Find a backend errors, readout errors, qubit coherence times, etc. Find a backend
that provides this information with: ``backend.properties()`` that provides this information with: ``backend.properties()``
initial_layout: Initial position of virtual qubits on physical qubits. initial_layout: Initial position of virtual qubits on physical qubits.
If this layout makes the circuit compatible with the coupling_map If this layout makes the circuit compatible with the coupling_map
constraints, it will be used. constraints, it will be used. The final layout is not guaranteed to be the same,
The final layout is not guaranteed to be the same, as the transpiler as the transpiler may permute qubits through swaps or other means.
may permute qubits through swaps or other means.
Multiple formats are supported: Multiple formats are supported:
1. ``Layout`` instance #. ``Layout`` instance
#. Dict
2. Dict * virtual to physical::
* virtual to physical::
{qr[0]: 0, {qr[0]: 0,
qr[1]: 3, qr[1]: 3,
qr[2]: 5} qr[2]: 5}
* physical to virtual:: * physical to virtual::
{0: qr[0], {0: qr[0],
3: qr[1], 3: qr[1],
5: qr[2]} 5: qr[2]}
3. List
* virtual to physical:: #. List
* virtual to physical::
[0, 3, 5] # virtual qubits are ordered (in addition to named) [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]] [qr[0], None, None, qr[1], None, qr[2]]
seed_transpiler: Sets random seed for the stochastic parts of the transpiler seed_transpiler: Sets random seed for the stochastic parts of the transpiler
optimization_level: How much optimization to perform on the circuits. optimization_level: How much optimization to perform on the circuits.
Higher levels generate more optimized circuits, Higher levels generate more optimized circuits,
at the expense of longer transpilation time. at the expense of longer transpilation time.
* 0: no optimization * 0: no optimization
* 1: light optimization * 1: light optimization
* 2: heavy optimization * 2: heavy optimization
* 3: even heavier optimization * 3: even heavier optimization
If ``None``, level 1 will be chosen as default. If ``None``, level 1 will be chosen as default.
pass_manager: The pass manager to use for a custom pipeline of transpiler passes. 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 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 callback: A callback function that will be called after each
pass execution. The function will be called with 5 keyword pass execution. The function will be called with 5 keyword
arguments, arguments,
| ``pass_``: the pass being run. | ``pass_``: the pass being run.
| ``dag``: the dag output of the pass. | ``dag``: the dag output of the pass.
| ``time``: the time to execute the pass. | ``time``: the time to execute the pass.
| ``property_set``: the property set. | ``property_set``: the property set.
| ``count``: the index for the pass execution. | ``count``: the index for the pass execution.
The exact arguments passed expose the internals of the pass manager, The exact arguments passed expose the internals of the pass manager,
and are subject to change as the pass manager internals change. If and are subject to change as the pass manager internals change. If
you intend to reuse a callback function over multiple releases, be you intend to reuse a callback function over multiple releases, be
sure to check that the arguments being passed are the same. sure to check that the arguments being passed are the same.
To use the callback feature, define a function that will To use the callback feature, define a function that will
take in kwargs dict and access the variables. For example:: take in kwargs dict and access the variables. For example::
def callback_func(**kwargs): def callback_func(**kwargs):
pass_ = kwargs['pass_'] pass_ = kwargs['pass_']
dag = kwargs['dag'] dag = kwargs['dag']
@ -144,6 +144,7 @@ def transpile(circuits: Union[QuantumCircuit, List[QuantumCircuit]],
count = kwargs['count'] count = kwargs['count']
... ...
transpile(circ, callback=callback_func) transpile(circ, callback=callback_func)
output_name: A list with strings to identify the output circuits. The length of 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. the list should be exactly the length of the ``circuits`` parameter.

View File

@ -38,7 +38,7 @@ def circuit_to_instruction(circuit, parameter_map=None):
QiskitError: if parameter_map is not compatible with circuit QiskitError: if parameter_map is not compatible with circuit
Return: 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 input circuit. Upon decomposition, this instruction will
yield the components comprising the original circuit. yield the components comprising the original circuit.

View File

@ -216,7 +216,7 @@ class DAGCircuit:
"""Add a new operation node to the graph and assign properties. """Add a new operation node to the graph and assign properties.
Args: 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. qargs (list[Qubit]): list of quantum wires to attach to.
cargs (list[Clbit]): list of classical wires to attach to. cargs (list[Clbit]): list of classical wires to attach to.
condition (tuple or None): optional condition (ClassicalRegister, int) condition (tuple or None): optional condition (ClassicalRegister, int)
@ -240,7 +240,7 @@ class DAGCircuit:
"""Apply an operation to the output of the circuit. """Apply an operation to the output of the circuit.
Args: 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 qargs (list[Qubit]): qubits that op will be applied to
cargs (list[Clbit]): cbits that op will be applied to cargs (list[Clbit]): cbits that op will be applied to
condition (tuple or None): optional condition (ClassicalRegister, int) condition (tuple or None): optional condition (ClassicalRegister, int)
@ -286,7 +286,7 @@ class DAGCircuit:
"""Apply an operation to the input of the circuit. """Apply an operation to the input of the circuit.
Args: 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 qargs (list[Qubit]): qubits that op will be applied to
cargs (list[Clbit]): cbits that op will be applied to cargs (list[Clbit]): cbits that op will be applied to
condition (tuple or None): optional condition (ClassicalRegister, value) condition (tuple or None): optional condition (ClassicalRegister, value)
@ -860,7 +860,8 @@ class DAGCircuit:
Args: Args:
node (DAGNode): Node to be replaced 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 inplace (bool): Optional, default False. If True, existing DAG node
will be modified to include op. Otherwise, a new DAG node will will be modified to include op. Otherwise, a new DAG node will
be used. be used.
@ -944,8 +945,8 @@ class DAGCircuit:
"""Get the list of "op" nodes in the dag. """Get the list of "op" nodes in the dag.
Args: Args:
op (Type): Instruction subclass op nodes to return. if op=None, return op (Type): :class:`qiskit.circuit.Instruction` subclass op nodes to return.
all op nodes. if op=None, return all op nodes.
Returns: Returns:
list[DAGNode]: the list of node ids containing the given op. list[DAGNode]: the list of node ids containing the given op.
""" """

View File

@ -57,20 +57,18 @@ def execute(experiments, backend,
basis_gates (list[str]): basis_gates (list[str]):
List of basis gate names to unroll to. List of basis gate names to unroll to.
e.g: e.g: ``['u1', 'u2', 'u3', 'cx']``
['u1', 'u2', 'u3', 'cx'] If ``None``, do not unroll.
If None, do not unroll.
coupling_map (CouplingMap or list): coupling_map (CouplingMap or list): Coupling map (perhaps custom) to
Coupling map (perhaps custom) to target in mapping. target in mapping. Multiple formats are supported:
Multiple formats are supported:
a. CouplingMap instance
b. list #. CouplingMap instance
Must be given as an adjacency matrix, where each entry #. list
specifies all two-qubit interactions supported by backend Must be given as an adjacency matrix, where each entry
e.g: specifies all two-qubit interactions supported by backend
[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]] e.g:
``[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]]``
backend_properties (BackendProperties): backend_properties (BackendProperties):
Properties returned by a backend, including information on gate 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. may permute qubits through swaps or other means.
Multiple formats are supported: Multiple formats are supported:
a. Layout instance
b. dict #. :class:`qiskit.transpiler.Layout` instance
virtual to physical: #. ``dict``:
virtual to physical::
{qr[0]: 0, {qr[0]: 0,
qr[1]: 3, qr[1]: 3,
qr[2]: 5} qr[2]: 5}
physical to virtual: physical to virtual::
{0: qr[0], {0: qr[0],
3: qr[1], 3: qr[1],
5: qr[2]} 5: qr[2]}
c. list #. ``list``
virtual to physical: virtual to physical::
[0, 3, 5] # virtual qubits are ordered (in addition to named) [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]] [qr[0], None, None, qr[1], None, qr[2]]
seed_transpiler (int): seed_transpiler (int): Sets random seed for the stochastic parts of the transpiler
Sets random seed for the stochastic parts of the transpiler
optimization_level (int): optimization_level (int): How much optimization to perform on the circuits.
How much optimization to perform on the circuits.
Higher levels generate more optimized circuits, Higher levels generate more optimized circuits,
at the expense of longer transpilation time. at the expense of longer transpilation time.
0: No optimization #. No optimization
1: Light optimization #. Light optimization
2: Heavy optimization #. Heavy optimization
3: Highest optimization #. Highest optimization
If None, level 1 will be chosen as default. If None, level 1 will be chosen as default.
pass_manager (PassManager): pass_manager (PassManager): The pass manager to use during transpilation. If this
The pass manager to use during transpilation. If this arg is present, arg is present, auto-selection of pass manager based on the transpile options
auto-selection of pass manager based on the transpile options will be will be turned off and this pass manager will be used directly.
turned off and this pass manager will be used directly.
qobj_id (str): qobj_id (str): String identifier to annotate the Qobj
String identifier to annotate the Qobj
qobj_header (QobjHeader or dict): qobj_header (QobjHeader or dict): User input that will be inserted in Qobj header,
User input that will be inserted in Qobj header, and will also be and will also be copied to the corresponding :class:`qiskit.result.Result`
copied to the corresponding Result header. Headers do not affect the run. header. Headers do not affect the run.
shots (int): shots (int): Number of repetitions of each circuit, for sampling. Default: 1024
Number of repetitions of each circuit, for sampling. Default: 1024
memory (bool): memory (bool): If True, per-shot measurement bitstrings are returned as well
If True, per-shot measurement bitstrings are returned as well
(provided the backend supports it). For OpenPulse jobs, only (provided the backend supports it). For OpenPulse jobs, only
measurement level 2 supports this option. Default: False measurement level 2 supports this option. Default: False
max_credits (int): max_credits (int): Maximum credits to spend on job. Default: 10
Maximum credits to spend on job. Default: 10
seed_simulator (int): seed_simulator (int): Random seed to control sampling, for when backend is a simulator
Random seed to control sampling, for when backend is a simulator
default_qubit_los (list): default_qubit_los (list): List of default qubit LO frequencies in Hz
List of default qubit LO frequencies in Hz
default_meas_los (list): default_meas_los (list): List of default meas LO frequencies in Hz
List of default meas LO frequencies in Hz
schedule_los (None or list[Union[Dict[PulseChannel, float], LoConfig]] or \ schedule_los (None or list or dict or LoConfig): Experiment LO
Union[Dict[PulseChannel, float], LoConfig]): configurations, if specified the list is in the format::
Experiment LO configurations
meas_level (int or MeasLevel): list[Union[Dict[PulseChannel, float], LoConfig]] or
Set the appropriate level of the measurement output for pulse experiments. Union[Dict[PulseChannel, float], LoConfig]
meas_return (str or MeasReturn): meas_level (int or MeasLevel): Set the appropriate level of the
Level of measurement data for the backend to return measurement output for pulse experiments.
For `meas_level` 0 and 1:
"single" returns information from every shot.
"avg" returns average measurement output (averaged over number of shots).
memory_slots (int): meas_return (str or MeasReturn): Level of measurement data for the
Number of classical memory slots used in this job. 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): memory_slots (int): Number of classical memory slots used in this job.
Size of each memory slot if the output is Level 0.
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. rep_time (int): repetition time of the experiment in μs.
The delay between experiments will be rep_time. The delay between experiments will be rep_time.
Must be from the list provided by the device. Must be from the list provided by the device.
parameter_binds (list[dict]): parameter_binds (list[dict]): List of Parameter bindings over which the set of
List of Parameter bindings over which the set of experiments will be experiments will be executed. Each list element (bind) should be of the form
executed. Each list element (bind) should be of the form ``{Parameter1: value1, Parameter2: value2, ...}``. All binds will be
{Parameter1: value1, Parameter2: value2, ...}. All binds will be
executed across all experiments, e.g. if parameter_binds is a 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). experiments will be run (one for each experiment/bind pair).
schedule_circuit (bool): schedule_circuit (bool): If ``True``, ``experiments`` will be converted to
If ``True``, ``experiments`` will be converted to ``Schedule``s prior to :class:`qiskit.pulse.Schedule` objects prior to execution.
execution.
inst_map (InstructionScheduleMap): inst_map (InstructionScheduleMap):
Mapping of circuit operations to pulse schedules. If None, defaults to the Mapping of circuit operations to pulse schedules. If None, defaults to the

View File

@ -49,7 +49,6 @@ Standard Extensions
SdgGate SdgGate
SwapGate SwapGate
TdgGate TdgGate
U0Gate
U1Gate U1Gate
U2Gate U2Gate
U3Gate U3Gate

View File

@ -87,12 +87,10 @@ class Initialize(Instruction):
self.definition = initialize_circuit.data self.definition = initialize_circuit.data
def gates_to_uncompute(self): 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: 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) q = QuantumRegister(self.num_qubits)
circuit = QuantumCircuit(q, name='disentangler') circuit = QuantumCircuit(q, name='disentangler')

View File

@ -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. The decomposition is base on https://arxiv.org/pdf/quant-ph/0406176.pdf by Shende et al.
Args: 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 q_controls (QuantumRegister|list): list of k control qubits
(or empty list if no controls). The control qubits are ordered according to their (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]] 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[1] and q[2] (with ``q = QuantumRegister(2)``), the rotation ``Rx(a_0)`` is performed if ``q[0]``
are in the state zero, the rotation Rx(a_1) is performed if q[1] is in the state and ``q[1]`` are in the state zero, the rotation ``Rx(a_1)`` is performed if ``q[0]``
one and q[2] is in the state zero, and so on 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 q_target (QuantumRegister|Qubit): target qubit, where we act on with
the single-qubit rotation gates the single-qubit rotation gates

View File

@ -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. The decomposition is base on https://arxiv.org/pdf/quant-ph/0406176.pdf by Shende et al.
Args: 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 q_controls (QuantumRegister|list[Qubit]): list of k control qubits
(or empty list if no controls). The control qubits are ordered according to their (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]] 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[1] and q[2] (with ``q = QuantumRegister(2)``), the rotation ``Ry(a_0)`` is performed if ``q[0]``
are in the state zero, the rotation Ry(a_1) is performed if q[1] is in the state and ``q[1]`` are in the state zero, the rotation ``Ry(a_1)`` is performed if ``q[0]``
one and q[2] is in the state zero, and so on 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 q_target (QuantumRegister|Qubit): target qubit, where we act on with
the single-qubit rotation gates the single-qubit rotation gates

View File

@ -78,9 +78,14 @@ class HGate(Gate):
@deprecate_arguments({'q': 'qubit'}) @deprecate_arguments({'q': 'qubit'})
def h(self, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument def h(self, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument
"""Apply Hadamard (H) gate to a specified qubit (qubit). r"""Apply Hadamard (H) gate.
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 |-. 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: Examples:
@ -100,6 +105,7 @@ def h(self, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument
from qiskit.extensions.standard.h import HGate from qiskit.extensions.standard.h import HGate
HGate().to_matrix() HGate().to_matrix()
""" """
return self.append(HGate(), [qubit], []) return self.append(HGate(), [qubit], [])
@ -159,9 +165,12 @@ class CHGate(ControlledGate):
@deprecate_arguments({'ctl': 'control_qubit', 'tgt': 'target_qubit'}) @deprecate_arguments({'ctl': 'control_qubit', 'tgt': 'target_qubit'})
def ch(self, control_qubit, target_qubit, # pylint: disable=invalid-name def ch(self, control_qubit, target_qubit, # pylint: disable=invalid-name
*, ctl=None, tgt=None): # pylint: disable=unused-argument *, ctl=None, tgt=None): # pylint: disable=unused-argument
"""Apply cH gate from a specified control (control_qubit) to target (target_qubit) qubit. """Apply cH gate
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>. 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: Examples:

View File

@ -66,11 +66,12 @@ class IdGate(IGate, metaclass=IMeta):
@deprecate_arguments({'q': 'qubit'}) @deprecate_arguments({'q': 'qubit'})
def i(self, qubit, *, q=None): # pylint: disable=unused-argument 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 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. of gate time. It leaves the quantum states :math:`|0\\rangle` and
The Identity gate should not be optimized or unrolled (it is an opaque gate). :math:`|1\\rangle` unchanged. The Identity gate should not be optimized or
unrolled (it is an opaque gate).
Examples: Examples:

View File

@ -71,9 +71,11 @@ class RZGate(Gate):
@deprecate_arguments({'q': 'qubit'}) @deprecate_arguments({'q': 'qubit'})
def rz(self, phi, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument def rz(self, phi, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument
"""Apply Rz gate with angle phi to a specified qubit (qubit). """Apply Rz gate with angle :math:`\\phi`
An Rz gate implemements a phi radian rotation of the qubit state vector about the
z axis of the Bloch sphere. 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: Examples:
@ -153,9 +155,12 @@ class CrzGate(CRZGate, metaclass=CRZMeta):
@deprecate_arguments({'ctl': 'control_qubit', 'tgt': 'target_qubit'}) @deprecate_arguments({'ctl': 'control_qubit', 'tgt': 'target_qubit'})
def crz(self, theta, control_qubit, target_qubit, def crz(self, theta, control_qubit, target_qubit,
*, ctl=None, tgt=None): # pylint: disable=unused-argument *, ctl=None, tgt=None): # pylint: disable=unused-argument
"""Apply cRz gate from a specified control (control_qubit) to target (target_qubit) qubit """Apply cRz gate
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>. 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: Examples:

View File

@ -177,10 +177,12 @@ class FredkinGate(CSwapGate, metaclass=CSwapMeta):
'tgt2': 'target_qubit2'}) 'tgt2': 'target_qubit2'})
def cswap(self, control_qubit, target_qubit1, target_qubit2, def cswap(self, control_qubit, target_qubit1, target_qubit2,
*, ctl=None, tgt1=None, tgt2=None): # pylint: disable=unused-argument *, ctl=None, tgt1=None, tgt2=None): # pylint: disable=unused-argument
"""Apply Fredkin (CSWAP) gate from a specified control (control_qubit) to target1 """Apply Fredkin (CSWAP) gate
(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 From a specified control ``control_qubit`` to target1 ``target_qubit1`` and
state |1>. 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: Examples:

View File

@ -73,8 +73,11 @@ class U1Gate(Gate):
@deprecate_arguments({'q': 'qubit'}) @deprecate_arguments({'q': 'qubit'})
def u1(self, theta, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument def u1(self, theta, qubit, *, q=None): # pylint: disable=invalid-name,unused-argument
"""Apply U1 gate with angle theta to a specified qubit (qubit). """Apply U1 gate with angle theta
u1(λ) := diag(1, eiλ) U(0, 0, λ) = Rz(λ) where ~ is equivalence up to a global phase.
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: Examples:
@ -164,9 +167,12 @@ class Cu1Gate(CU1Gate, metaclass=CU1Meta):
'tgt': 'target_qubit'}) 'tgt': 'target_qubit'})
def cu1(self, theta, control_qubit, target_qubit, def cu1(self, theta, control_qubit, target_qubit,
*, ctl=None, tgt=None): # pylint: disable=unused-argument *, ctl=None, tgt=None): # pylint: disable=unused-argument
"""Apply cU1 gate from a specified control (control_qubit) to target (target_qubit) qubit r"""Apply cU1 gate
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>. 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: Examples:

View File

@ -173,10 +173,12 @@ class Cu3Gate(CU3Gate, metaclass=CU3Meta):
'tgt': 'target_qubit'}) 'tgt': 'target_qubit'})
def cu3(self, theta, phi, lam, control_qubit, target_qubit, def cu3(self, theta, phi, lam, control_qubit, target_qubit,
*, ctl=None, tgt=None): # pylint: disable=unused-argument *, ctl=None, tgt=None): # pylint: disable=unused-argument
"""Apply cU3 gate from a specified control (control_qubit) to target (target_qubit) qubit """Apply cU3 gate
with angle theta, phi, and lam.
A cU3 gate implements a U3(theta,phi,lam) on the target qubit when the Applied from a specified control ``control_qubit`` to target
control qubit is in state |1>. ``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: Examples:

View File

@ -83,9 +83,10 @@ class XGate(Gate):
@deprecate_arguments({'q': 'qubit'}) @deprecate_arguments({'q': 'qubit'})
def x(self, qubit, *, q=None): # pylint: disable=unused-argument def x(self, qubit, *, q=None): # pylint: disable=unused-argument
"""Apply X gate to a specified qubit (qubit). """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. An X gate implements a :math:`\\pi` rotation of the qubit state vector about
This gate is canonically used to implement a bit flip on the qubit state from |0 to |1, 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. or vice versa.
Examples: Examples:
@ -177,11 +178,14 @@ class CnotGate(CXGate, metaclass=CXMeta):
'tgt': 'target_qubit'}) 'tgt': 'target_qubit'})
def cx(self, control_qubit, target_qubit, # pylint: disable=invalid-name def cx(self, control_qubit, target_qubit, # pylint: disable=invalid-name
*, ctl=None, tgt=None): # pylint: disable=unused-argument *, ctl=None, tgt=None): # pylint: disable=unused-argument
"""Apply CX gate from a specified control (control_qubit) to target (target_qubit) qubit. """Apply CX gate
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>. From a specified control ``control_qubit`` to target ``target_qubit`` qubit.
This gate is canonically used to implement a bit flip on the qubit state from |0 to |1, A CX gate implements a :math:`\\pi` rotation of the qubit state vector about
or vice versa when the control qubit is in state |1>. 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: Examples:
@ -293,9 +297,11 @@ class ToffoliGate(CCXGate, metaclass=CCXMeta):
'tgt': 'target_qubit'}) 'tgt': 'target_qubit'})
def ccx(self, control_qubit1, control_qubit2, target_qubit, def ccx(self, control_qubit1, control_qubit2, target_qubit,
*, ctl1=None, ctl2=None, tgt=None): # pylint: disable=unused-argument *, ctl1=None, ctl2=None, tgt=None): # pylint: disable=unused-argument
"""Apply Toffoli (ccX) gate from two specified controls (control_qubit1 and control_qubit2) """Apply Toffoli (ccX) gate
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>. 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: Examples:

View File

@ -73,10 +73,11 @@ class YGate(Gate):
@deprecate_arguments({'q': 'qubit'}) @deprecate_arguments({'q': 'qubit'})
def y(self, qubit, *, q=None): # pylint: disable=unused-argument def y(self, qubit, *, q=None): # pylint: disable=unused-argument
"""Apply Y gate to a specified qubit (qubit). """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. A Y gate implements a :math:`\\pi` rotation of the qubit state vector about
This gate is canonically used to implement a bit flip and phase flip on the qubit state the y axis of the Bloch sphere. This gate is canonically used to implement
from |0 to i|1, or from |1> to -i|0>. 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: Examples:
@ -167,11 +168,14 @@ class CyGate(CYGate, metaclass=CYMeta):
'tgt': 'target_qubit'}) 'tgt': 'target_qubit'})
def cy(self, control_qubit, target_qubit, # pylint: disable=invalid-name def cy(self, control_qubit, target_qubit, # pylint: disable=invalid-name
*, ctl=None, tgt=None): # pylint: disable=unused-argument *, 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 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 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: Examples:

View File

@ -73,9 +73,10 @@ class ZGate(Gate):
@deprecate_arguments({'q': 'qubit'}) @deprecate_arguments({'q': 'qubit'})
def z(self, qubit, *, q=None): # pylint: disable=unused-argument def z(self, qubit, *, q=None): # pylint: disable=unused-argument
"""Apply Z gate to a specified qubit (qubit). """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. A Z gate implements a :math:`\\pi` rotation of the qubit state vector about
This gate is canonically used to implement a phase flip on the qubit state from |+ to |-, 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. or vice versa.
Examples: Examples:
@ -166,11 +167,14 @@ class CzGate(CZGate, metaclass=CZMeta):
'tgt': 'target_qubit'}) 'tgt': 'target_qubit'})
def cz(self, control_qubit, target_qubit, # pylint: disable=invalid-name def cz(self, control_qubit, target_qubit, # pylint: disable=invalid-name
*, ctl=None, tgt=None): # pylint: disable=unused-argument *, ctl=None, tgt=None): # pylint: disable=unused-argument
"""Apply cZ gate from a specified control (control_qubit) to target (target_qubit) qubit. """Apply cZ gate
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>. From a specified control ``control_qubit`` to target ``target_qubit`` qubit.
This gate is canonically used to implement a phase flip on the qubit state from |+ to |-, A cZ gate implements a :math:`\\pi` rotation of the qubit state vector about
or vice versa when the control qubit is in state |1>. 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: Examples:

View File

@ -439,12 +439,15 @@ class PulseBackendConfiguration(BackendConfiguration):
""" """
Return a basic description of the channel dependency. Derived channels are given weights Return a basic description of the channel dependency. Derived channels are given weights
which describe how their frames are linked to other frames. 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 = [ u_channel_lo = [
[UchannelLO(q=0, scale=1. + 0.j)], [UchannelLO(q=0, scale=1. + 0.j)],
[UchannelLO(q=0, scale=-1. + 0.j), UchannelLO(q=1, 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)) backend.configuration().describe(ControlChannel(1))
>>> {DriveChannel(0): -1, DriveChannel(1): 1} >>> {DriveChannel(0): -1, DriveChannel(1): 1}

View File

@ -87,7 +87,6 @@ been assigned to its :class:`~qiskit.pulse.channels.Channel` (s).
Instruction Instruction
.. autosummary:: .. autosummary::
:hidden:
:toctree: ../stubs/ :toctree: ../stubs/
qiskit.pulse.commands qiskit.pulse.commands

View File

@ -12,6 +12,8 @@
# copyright notice, and modified files need to carry a notice indicating # copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals. # that they have been altered from the originals.
# pylint: disable=cyclic-import
""" """
Supported command types in Pulse. Supported command types in Pulse.
@ -37,7 +39,6 @@ Abstract Classes
Command Command
""" """
from .instruction import Instruction
from .acquire import Acquire, AcquireInstruction from .acquire import Acquire, AcquireInstruction
from .frame_change import FrameChange, FrameChangeInstruction from .frame_change import FrameChange, FrameChangeInstruction
from .meas_opts import Discriminator, Kernel from .meas_opts import Discriminator, Kernel

View File

@ -18,9 +18,9 @@ Acquire.
import warnings import warnings
from typing import Optional, Union, List from typing import Optional, Union, List
from qiskit.pulse.channels import MemorySlot, RegisterSlot, AcquireChannel
from qiskit.pulse.exceptions import PulseError 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 .meas_opts import Discriminator, Kernel
from .command import Command from .command import Command

View File

@ -24,8 +24,6 @@ import numpy as np
from qiskit.pulse.exceptions import PulseError from qiskit.pulse.exceptions import PulseError
from qiskit.pulse.channels import Channel from qiskit.pulse.channels import Channel
from .instruction import Instruction
class MetaCount(ABCMeta): class MetaCount(ABCMeta):
"""Meta class to count class instances.""" """Meta class to count class instances."""
@ -91,8 +89,12 @@ class Command(metaclass=MetaCount):
@abstractmethod @abstractmethod
def to_instruction(self, command, *channels: List[Channel], def to_instruction(self, command, *channels: List[Channel],
name: Optional[str] = None) -> Instruction: name: Optional[str] = None):
"""Create an instruction from command.""" """Create an instruction from command.
Returns:
Instruction
"""
pass pass
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):

View File

@ -18,7 +18,7 @@ Delay instruction.
from typing import Optional from typing import Optional
from qiskit.pulse.channels import Channel from qiskit.pulse.channels import Channel
from .instruction import Instruction from ..instructions import Instruction
from .command import Command from .command import Command

View File

@ -18,7 +18,7 @@ Frame change pulse.
from typing import Optional from typing import Optional
from qiskit.pulse.channels import PulseChannel from qiskit.pulse.channels import PulseChannel
from .instruction import Instruction from ..instructions import Instruction
from .command import Command from .command import Command

View File

@ -43,14 +43,13 @@ import math
import numpy as np import numpy as np
from qiskit.pulse.channels import PulseChannel from qiskit.pulse.pulse_lib import gaussian, gaussian_square, drag, constant, continuous
from qiskit.pulse.exceptions import PulseError from .sample_pulse import SamplePulse
from qiskit.pulse.pulse_lib.discrete import gaussian, gaussian_square, drag, constant from ..instructions import Instruction
from qiskit.pulse.pulse_lib import continuous from ..channels import PulseChannel
from ..exceptions import PulseError
from .pulse_command import PulseCommand from .pulse_command import PulseCommand
from .sample_pulse import SamplePulse
from .instruction import Instruction
# pylint: disable=missing-docstring # pylint: disable=missing-docstring
@ -97,7 +96,7 @@ class ParametricPulse(PulseCommand):
return ParametricInstruction(self, channel, name=name) return ParametricInstruction(self, channel, name=name)
def draw(self, dt: float = 1, def draw(self, dt: float = 1,
style: Optional['PulseStyle'] = None, style=None,
filename: Optional[str] = None, filename: Optional[str] = None,
interp_method: Optional[Callable] = None, interp_method: Optional[Callable] = None,
scale: float = 1, interactive: bool = False, scale: float = 1, interactive: bool = False,
@ -106,7 +105,7 @@ class ParametricPulse(PulseCommand):
Args: Args:
dt: Time interval of samples. 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 filename: Name required to save pulse image
interp_method: A function for interpolation interp_method: A function for interpolation
scale: Relative visual scaling of waveform amplitudes scale: Relative visual scaling of waveform amplitudes
@ -253,11 +252,10 @@ class GaussianSquare(ParametricPulse):
class Drag(ParametricPulse): class Drag(ParametricPulse):
""" r"""The Derivative Removal by Adiabatic Gate (DRAG) pulse is a standard Gaussian pulse
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 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 spectrum of a normal gaussian pulse near the :math:`|1\rangle` - :math:`|2\rangle` transition,
leakage to the |2> state. reducing the chance of leakage to the :math:`|2\rangle` state.
.. math:: .. math::
@ -270,12 +268,21 @@ class Drag(ParametricPulse):
Gaussian(x, amp, sigma) = amp * exp( -(1/2) * (x - duration/2)^2 / sigma^2) ) Gaussian(x, amp, sigma) = amp * exp( -(1/2) * (x - duration/2)^2 / sigma^2) )
Ref: References:
[1] Gambetta, J. M., Motzoi, F., Merkel, S. T. & Wilhelm, F. K. 1. |citation1|_
Analytic control methods for high-fidelity unitary operations
in a weakly nonlinear oscillator. Phys. Rev. A 83, 012308 (2011). .. _citation1: https://link.aps.org/doi/10.1103/PhysRevA.83.012308
[2] F. Motzoi, J. M. Gambetta, P. Rebentrost, and F. K. Wilhelm
Phys. Rev. Lett. 103, 110501 Published 8 September 2009 .. |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, def __init__(self,

View File

@ -21,7 +21,7 @@ from typing import Optional
from qiskit.pulse.channels import PulseChannel from qiskit.pulse.channels import PulseChannel
from qiskit.pulse.exceptions import PulseError from qiskit.pulse.exceptions import PulseError
from .instruction import Instruction from ..instructions import Instruction
from .command import Command from .command import Command

View File

@ -18,7 +18,7 @@ from typing import Callable, List, Optional
from abc import abstractmethod from abc import abstractmethod
from qiskit.pulse.channels import Channel from qiskit.pulse.channels import Channel
from .instruction import Instruction from ..instructions import Instruction
from .command import Command from .command import Command
@ -37,7 +37,7 @@ class PulseCommand(Command):
@abstractmethod @abstractmethod
def draw(self, dt: float = 1, def draw(self, dt: float = 1,
style: Optional['PulseStyle'] = None, style=None,
filename: Optional[str] = None, filename: Optional[str] = None,
interp_method: Optional[Callable] = None, interp_method: Optional[Callable] = None,
scale: float = 1, interactive: bool = False, scale: float = 1, interactive: bool = False,
@ -46,7 +46,7 @@ class PulseCommand(Command):
Args: Args:
dt: Time interval of samples. 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 filename: Name required to save pulse image
interp_method: A function for interpolation interp_method: A function for interpolation
scale: Relative visual scaling of waveform amplitudes scale: Relative visual scaling of waveform amplitudes

View File

@ -23,7 +23,7 @@ import numpy as np
from qiskit.pulse.channels import PulseChannel from qiskit.pulse.channels import PulseChannel
from qiskit.pulse.exceptions import PulseError from qiskit.pulse.exceptions import PulseError
from .instruction import Instruction from ..instructions import Instruction
from .pulse_command import PulseCommand from .pulse_command import PulseCommand
@ -100,7 +100,7 @@ class SamplePulse(PulseCommand):
return samples return samples
def draw(self, dt: float = 1, def draw(self, dt: float = 1,
style: Optional['PulseStyle'] = None, style=None,
filename: Optional[str] = None, filename: Optional[str] = None,
interp_method: Optional[Callable] = None, interp_method: Optional[Callable] = None,
scale: float = 1, interactive: bool = False, scale: float = 1, interactive: bool = False,
@ -109,7 +109,7 @@ class SamplePulse(PulseCommand):
Args: Args:
dt: Time interval of samples. 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 filename: Name required to save pulse image
interp_method: A function for interpolation interp_method: A function for interpolation
scale: Relative visual scaling of waveform amplitudes scale: Relative visual scaling of waveform amplitudes

View File

@ -16,7 +16,7 @@
Snapshot. Snapshot.
""" """
from qiskit.pulse.channels import SnapshotChannel from qiskit.pulse.channels import SnapshotChannel
from .instruction import Instruction from ..instructions import Instruction
from .command import Command from .command import Command

View File

@ -30,9 +30,10 @@ from abc import ABC
from typing import Tuple, List, Iterable, Callable, Optional, Union from typing import Tuple, List, Iterable, Callable, Optional, Union
from qiskit.pulse.channels import Channel 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 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 # pylint: disable=missing-return-doc
@ -44,7 +45,7 @@ class Instruction(ScheduleComponent, ABC):
channels. channels.
""" """
def __init__(self, duration: Union['Command', int], def __init__(self, duration: Union['commands.Command', int],
*channels: Channel, *channels: Channel,
name: Optional[str] = None): name: Optional[str] = None):
"""Instruction initializer. """Instruction initializer.
@ -73,7 +74,7 @@ class Instruction(ScheduleComponent, ABC):
return self._name return self._name
@property @property
def command(self) -> 'Command': def command(self) -> 'commands.Command':
"""The associated command.""" """The associated command."""
return self._command return self._command
@ -152,7 +153,7 @@ class Instruction(ScheduleComponent, ABC):
"""Return itself as already single instruction.""" """Return itself as already single instruction."""
return self 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`. """Return a new schedule which is the union of `self` and `schedule`.
Args: Args:
@ -165,7 +166,7 @@ class Instruction(ScheduleComponent, ABC):
name = self.name name = self.name
return Schedule(self, *schedules, name=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`. """Return a new schedule shifted forward by `time`.
Args: Args:
@ -177,7 +178,7 @@ class Instruction(ScheduleComponent, ABC):
return Schedule((time, self), name=name) return Schedule((time, self), name=name)
def insert(self, start_time: int, schedule: ScheduleComponent, 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 """Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted within
``self`` at ``start_time``. ``self`` at ``start_time``.
@ -191,7 +192,7 @@ class Instruction(ScheduleComponent, ABC):
return Schedule(self, (start_time, schedule), name=name) return Schedule(self, (start_time, schedule), name=name)
def append(self, schedule: ScheduleComponent, 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 """Return a new :class:`~qiskit.pulse.Schedule` with ``schedule`` inserted at the
maximum time over all channels shared between ``self`` and ``schedule``. 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) time = self.ch_stop_time(*common_channels)
return self.insert(time, schedule, name=name) 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, filename: Optional[str] = None, interp_method: Optional[Callable] = None,
scale: float = 1, channels_to_plot: Optional[List[Channel]] = None, scale: float = 1, channels_to_plot: Optional[List[Channel]] = None,
plot_all: bool = False, plot_range: Optional[Tuple[float]] = None, plot_all: bool = False, plot_range: Optional[Tuple[float]] = None,
@ -215,7 +216,7 @@ class Instruction(ScheduleComponent, ABC):
Args: Args:
dt: Time interval of samples 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 filename: Name required to save pulse image
interp_method: A function for interpolation interp_method: A function for interpolation
scale: Relative visual scaling of waveform amplitudes 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.command)), self.channels.__hash__()))
return hash((hash(tuple(self.duration)), 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 a new schedule with `other` inserted within `self` at `start_time`."""
return self.append(other) 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 a new schedule which is the union of `self` and `other`."""
return self.insert(0, 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 a new schedule which is shifted forward by `time`."""
return self.shift(time) return self.shift(time)

View File

@ -21,8 +21,9 @@ Note the sampling strategy use for all discrete pulses is `midpoint`.
import warnings import warnings
from typing import Optional from typing import Optional
from qiskit.pulse.pulse_lib import continuous
from qiskit.pulse.exceptions import PulseError from qiskit.pulse.exceptions import PulseError
from ..commands.sample_pulse import SamplePulse
from . import continuous
from . import samplers from . import samplers
@ -30,7 +31,7 @@ from . import samplers
_sampled_constant_pulse = samplers.midpoint(continuous.constant) _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`. r"""Generates constant-sampled :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp``, samples from the function: 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) _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`. """Generates zero-sampled :class:`~qiskit.pulse.SamplePulse`.
Samples from the function: 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, 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`. r"""Generates square wave :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp``, :math:`T=` ``period``, and :math:`\phi=` ``phase``, 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, 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`. r"""Generates sawtooth wave :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp``, :math:`T=` ``period``, and :math:`\phi=` ``phase``, 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 import matplotlib.pyplot as plt
from qiskit.pulse.pulse_lib import sawtooth from qiskit.pulse.pulse_lib import sawtooth
import numpy as np
duration = 100 duration = 100
amp = 1 amp = 1
period = duration 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): if (freq is None) and (period is None):
freq = 1./duration 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, 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`. r"""Generates triangle wave :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp``, :math:`T=` ``period``, and :math:`\phi=` ``phase``, 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 import matplotlib.pyplot as plt
from qiskit.pulse.pulse_lib import triangle from qiskit.pulse.pulse_lib import triangle
import numpy as np
duration = 100 duration = 100
amp = 1 amp = 1
period = duration 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): if (freq is None) and (period is None):
freq = 1./duration freq = 1./duration
@ -201,7 +206,7 @@ _sampled_cos_pulse = samplers.midpoint(continuous.cos)
def cos(duration: int, amp: complex, freq: float = None, 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`. r"""Generates cosine wave :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp``, :math:`\omega=` ``freq``, and :math:`\phi=` ``phase``, 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, 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`. r"""Generates sine wave :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp``, :math:`\omega=` ``freq``, and :math:`\phi=` ``phase``, 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, 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`. r"""Generates unnormalized gaussian :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp`` and :math:`\sigma=` ``sigma``, applies the `midpoint` sampling strategy 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, 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`. r"""Generates unnormalized gaussian derivative :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp`` and :math:`\sigma=` ``sigma`` applies the `midpoint` sampling strategy 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, 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`. r"""Generates unnormalized sech :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp`` and :math:`\sigma=` ``sigma``, applies the `midpoint` sampling strategy 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) _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`. r"""Generates unnormalized sech derivative :class:`~qiskit.pulse.SamplePulse`.
For :math:`A=` ``amp``, :math:`\sigma=` ``sigma``, and center :math:`\mu=` ``duration/2``, 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, def gaussian_square(duration: int, amp: complex, sigma: float,
risefall: Optional[float] = None, width: Optional[float] = None, 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`. r"""Generates gaussian square :class:`~qiskit.pulse.SamplePulse`.
For :math:`d=` ``duration``, :math:`A=` ``amp``, :math:`\sigma=` ``sigma``, 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, 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 r"""Generates Y-only correction DRAG :class:`~qiskit.pulse.SamplePulse` for standard nonlinear
oscillator (SNO) [1]. oscillator (SNO) [1].

View File

@ -22,13 +22,10 @@ from typing import List, Optional, Iterable
import numpy as np import numpy as np
from qiskit.pulse import (CmdDef, Acquire, AcquireInstruction, Delay,
InstructionScheduleMap, ScheduleComponent, Schedule)
from .channels import Channel, AcquireChannel, MeasureChannel, MemorySlot from .channels import Channel, AcquireChannel, MeasureChannel, MemorySlot
from .cmd_def import CmdDef
from .commands import Acquire, AcquireInstruction, Delay
from .exceptions import PulseError from .exceptions import PulseError
from .instruction_schedule_map import InstructionScheduleMap
from .interfaces import ScheduleComponent
from .schedule import Schedule
def align_measures(schedules: Iterable[ScheduleComponent], def align_measures(schedules: Iterable[ScheduleComponent],

View File

@ -21,14 +21,13 @@ import abc
import itertools import itertools
import multiprocessing as mp import multiprocessing as mp
import sys 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 import warnings
from qiskit.util import is_main_process from qiskit.util import is_main_process
from .timeslots import Interval from .timeslots import Interval, TimeslotCollection
from .channels import Channel from .channels import Channel
from .interfaces import ScheduleComponent from .interfaces import ScheduleComponent
from .timeslots import TimeslotCollection
from .exceptions import PulseError from .exceptions import PulseError
# pylint: disable=missing-return-doc # pylint: disable=missing-return-doc
@ -123,8 +122,12 @@ class Schedule(ScheduleComponent):
return self.__children return self.__children
@property @property
def instructions(self) -> Tuple[Tuple[int, 'Instruction'], ...]: def instructions(self):
"""Get the time-ordered instructions from self.""" """Get the time-ordered instructions from self.
ReturnType:
Tuple[Tuple[int, Instruction], ...]
"""
def key(time_inst_pair): def key(time_inst_pair):
inst = time_inst_pair[1] inst = time_inst_pair[1]
@ -157,15 +160,16 @@ class Schedule(ScheduleComponent):
""" """
return self.timeslots.ch_stop_time(*channels) 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. """Iterable for flattening Schedule tree.
Args: Args:
time: Shifted time due to parent. time: Shifted time due to parent.
Yields: Yields:
Tuple containing the time each :class:`~qiskit.pulse.Instruction` Iterable[Tuple[int, Instruction]]: Tuple containing the time each
starts at and the flattened :class:`~qiskit.pulse.Instruction` s. :class:`~qiskit.pulse.Instruction`
starts at and the flattened :class:`~qiskit.pulse.Instruction` s.
""" """
for insert_time, child_sched in self._children: for insert_time, child_sched in self._children:
yield from child_sched._instructions(time + insert_time) yield from child_sched._instructions(time + insert_time)
@ -260,7 +264,7 @@ class Schedule(ScheduleComponent):
def filter(self, *filter_funcs: List[Callable], def filter(self, *filter_funcs: List[Callable],
channels: Optional[Iterable[Channel]] = None, channels: Optional[Iterable[Channel]] = None,
instruction_types: Optional[Iterable[Type['Instruction']]] = None, instruction_types=None,
time_ranges: Optional[Iterable[Tuple[int, int]]] = None, time_ranges: Optional[Iterable[Tuple[int, int]]] = None,
intervals: Optional[Iterable[Interval]] = None) -> 'Schedule': intervals: Optional[Iterable[Interval]] = None) -> 'Schedule':
"""Return a new ``Schedule`` with only the instructions from this ``Schedule`` which pass """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 filter_funcs: A list of Callables which take a (int, ScheduleComponent) tuple and
return a bool. return a bool.
channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``. 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)]``. time_ranges: For example, ``[(0, 5), (6, 10)]``.
intervals: For example, ``[Interval(0, 5), Interval(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], def exclude(self, *filter_funcs: List[Callable],
channels: Optional[Iterable[Channel]] = None, channels: Optional[Iterable[Channel]] = None,
instruction_types: Optional[Iterable[Type['Instruction']]] = None, instruction_types=None,
time_ranges: Optional[Iterable[Tuple[int, int]]] = None, time_ranges: Optional[Iterable[Tuple[int, int]]] = None,
intervals: Optional[Iterable[Interval]] = None) -> 'Schedule': intervals: Optional[Iterable[Interval]] = None) -> 'Schedule':
"""Return a Schedule with only the instructions from this Schedule *failing* at least one """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 filter_funcs: A list of Callables which take a (int, ScheduleComponent) tuple and
return a bool. return a bool.
channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``. 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)]``. time_ranges: For example, ``[(0, 5), (6, 10)]``.
intervals: For example, ``[Interval(0, 5), Interval(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], def _construct_filter(self, *filter_funcs: List[Callable],
channels: Optional[Iterable[Channel]] = None, channels: Optional[Iterable[Channel]] = None,
instruction_types: Optional[Iterable[Type['Instruction']]] = None, instruction_types=None,
time_ranges: Optional[Iterable[Tuple[int, int]]] = None, time_ranges: Optional[Iterable[Tuple[int, int]]] = None,
intervals: Optional[Iterable[Interval]] = None) -> Callable: intervals: Optional[Iterable[Interval]] = None) -> Callable:
"""Returns a boolean-valued function with input type ``(int, ScheduleComponent)`` that """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 filter_funcs: A list of Callables which take a (int, ScheduleComponent) tuple and
return a bool. return a bool.
channels: For example, ``[DriveChannel(0), AcquireChannel(0)]``. 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)]``. time_ranges: For example, ``[(0, 5), (6, 10)]``.
intervals: For example, ``[Interval(0, 5), Interval(6, 10)]``. intervals: For example, ``[Interval(0, 5), Interval(6, 10)]``.
""" """
def only_channels(channels: Set[Channel]) -> Callable: 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 any([chan in channels for chan in time_inst[1].channels])
return channel_filter return channel_filter
def only_instruction_types(types: Iterable[abc.ABCMeta]) -> Callable: 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 isinstance(time_inst[1], tuple(types))
return instruction_filter return instruction_filter
def only_intervals(ranges: Iterable[Interval]) -> Callable: 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: for i in ranges:
if all([(i.start <= ts.interval.shift(time_inst[0]).start if all([(i.start <= ts.interval.shift(time_inst[0]).start
and ts.interval.shift(time_inst[0]).stop <= i.stop) 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 function returning true iff all filters are passed
return lambda x: all([filter_func(x) for filter_func in filter_func_list]) 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, filename: Optional[str] = None, interp_method: Optional[Callable] = None,
scale: Optional[float] = None, scale: Optional[float] = None,
channel_scales: Optional[Dict[Channel, float]] = None, channel_scales: Optional[Dict[Channel, float]] = None,
@ -390,26 +412,26 @@ class Schedule(ScheduleComponent):
framechange: bool = True, scaling: float = None, framechange: bool = True, scaling: float = None,
channels: Optional[List[Channel]] = None, channels: Optional[List[Channel]] = None,
show_framechange_channels: bool = True): show_framechange_channels: bool = True):
"""Plot the schedule. r"""Plot the schedule.
Args: Args:
dt: Time interval of samples 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 filename: Name required to save pulse image.
interp_method: A function for interpolation interp_method: A function for interpolation.
scale: Relative visual scaling of waveform amplitudes, see Additional Information. scale: Relative visual scaling of waveform amplitudes, see Additional Information.
channel_scales: Channel independent scaling as a dictionary of ``Channel`` object. channel_scales: Channel independent scaling as a dictionary of ``Channel`` object.
channels_to_plot: Deprecated, see ``channels`` channels_to_plot: Deprecated, see ``channels``.
plot_all: Plot empty channels plot_all: Plot empty channels.
plot_range: A tuple of time range to plot plot_range: A tuple of time range to plot.
interactive: When set true show the circuit in a new window interactive: When set true show the circuit in a new window
(this depends on the matplotlib backend being used supporting this) (this depends on the matplotlib backend being used supporting this).
table: Draw event table for supported commands table: Draw event table for supported commands.
label: Label individual instructions label: Label individual instructions.
framechange: Add framechange indicators framechange: Add framechange indicators.
scaling: Deprecated, see ``scale`` scaling: Deprecated, see ``scale``.
channels: A list of channel names to plot channels: A list of channel names to plot.
show_framechange_channels: Plot channels with only framechanges show_framechange_channels: Plot channels with only framechanges.
Additional Information: Additional Information:
If you want to manually rescale the waveform amplitude of channels one by one, 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} pulse.MeasureChannels(0): 5.0}
When the channel to plot is not included in the ``channel_scales`` dictionary, 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. In default, waveform amplitude is normalized by the maximum amplitude of the channel.
The scaling factor is displayed under the channel name alias. The scaling factor is displayed under the channel name alias.
Returns: 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 # pylint: disable=invalid-name, cyclic-import
if scaling is not None: if scaling is not None:

View File

@ -69,11 +69,10 @@ class Chi(QuantumChannel):
QiskitError: if input data is not an N-qubit channel or QiskitError: if input data is not an N-qubit channel or
cannot be initialized as a Chi-matrix. cannot be initialized as a Chi-matrix.
Additional Information Additional Information:
---------------------- If the input or output dimensions are None, they will be
If the input or output dimensions are None, they will be automatically determined from the input data. The Chi matrix
automatically determined from the input data. The Chi matrix representation is only valid for N-qubit channels.
representation is only valid for N-qubit channels.
""" """
# If the input is a raw list or matrix we assume that it is # If the input is a raw list or matrix we assume that it is
# already a Chi matrix. # already a Chi matrix.

View File

@ -75,13 +75,12 @@ class Choi(QuantumChannel):
QiskitError: if input data cannot be initialized as a QiskitError: if input data cannot be initialized as a
Choi matrix. Choi matrix.
Additional Information Additional Information:
---------------------- If the input or output dimensions are None, they will be
If the input or output dimensions are None, they will be automatically determined from the input data. If the input data is
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
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
the input operator is not an N-qubit operator, it will assign a single subsystem with dimension specified by the shape of the input.
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 # If the input is a raw list or matrix we assume that it is
# already a Choi matrix. # already a Choi matrix.

View File

@ -78,13 +78,13 @@ class Kraus(QuantumChannel):
QiskitError: if input data cannot be initialized as a QiskitError: if input data cannot be initialized as a
a list of Kraus matrices. a list of Kraus matrices.
Additional Information Additional Information:
---------------------- If the input or output dimensions are None, they will be
If the input or output dimensions are None, they will be automatically determined from the input data. If the input data is
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
a list of Numpy arrays of shape (2**N, 2**N) qubit systems will be used. If used. If the input does not correspond to an N-qubit channel, it
the input does not correspond to an N-qubit channel, it will assign a will assign a single subsystem with dimension specified by the
single subsystem with dimension specified by the shape of the input. shape of the input.
""" """
# If the input is a list or tuple we assume it is a list of Kraus # 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 # matrices, if it is a numpy array we assume that it is a single Kraus

View File

@ -79,11 +79,10 @@ class PTM(QuantumChannel):
QiskitError: if input data is not an N-qubit channel or QiskitError: if input data is not an N-qubit channel or
cannot be initialized as a PTM. cannot be initialized as a PTM.
Additional Information Additional Information:
---------------------- If the input or output dimensions are None, they will be
If the input or output dimensions are None, they will be automatically determined from the input data. The PTM
automatically determined from the input data. The PTM representation is only valid for N-qubit channels.
representation is only valid for N-qubit channels.
""" """
# If the input is a raw list or matrix we assume that it is # If the input is a raw list or matrix we assume that it is
# already a Chi matrix. # already a Chi matrix.

View File

@ -180,7 +180,7 @@ class QuantumChannel(BaseOperator):
otherwise it will be added as a kraus simulator instruction. otherwise it will be added as a kraus simulator instruction.
Returns: Returns:
Instruction: A kraus instruction for the channel. qiskit.circuit.Instruction: A kraus instruction for the channel.
Raises: Raises:
QiskitError: if input data is not an N-qubit CPTP quantum channel. QiskitError: if input data is not an N-qubit CPTP quantum channel.

View File

@ -75,12 +75,11 @@ class Stinespring(QuantumChannel):
QiskitError: if input data cannot be initialized as a QiskitError: if input data cannot be initialized as a
a list of Kraus matrices. a list of Kraus matrices.
Additional Information Additional Information:
---------------------- If the input or output dimensions are None, they will be
If the input or output dimensions are None, they will be automatically determined from the input data. This can fail for the
automatically determined from the input data. This can fail for the Stinespring operator if the output dimension cannot be automatically
Stinespring operator if the output dimension cannot be automatically determined.
determined.
""" """
# If the input is a list or tuple we assume it is a pair of general # 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 # Stinespring matrices. If it is a numpy array we assume that it is

View File

@ -68,13 +68,12 @@ class SuperOp(QuantumChannel):
QiskitError: if input data cannot be initialized as a QiskitError: if input data cannot be initialized as a
superoperator. superoperator.
Additional Information Additional Information:
---------------------- If the input or output dimensions are None, they will be
If the input or output dimensions are None, they will be automatically determined from the input data. If the input data is
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
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
the input operator is not an N-qubit operator, it will assign a single subsystem with dimension specified by the shape of the input.
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 # If the input is a raw list or matrix we assume that it is
# already a superoperator. # already a superoperator.

View File

@ -65,13 +65,12 @@ class Operator(BaseOperator):
Raises: Raises:
QiskitError: if input data cannot be initialized as an operator. QiskitError: if input data cannot be initialized as an operator.
Additional Information Additional Information:
---------------------- If the input or output dimensions are None, they will be
If the input or output dimensions are None, they will be automatically determined from the input data. If the input data is
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
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
the input operator is not an N-qubit operator, it will assign a single subsystem with dimension specified by the shape of the input.
single subsystem with dimension specified by the shape of the input.
""" """
if isinstance(data, (list, np.ndarray)): if isinstance(data, (list, np.ndarray)):
# Default initialization from list or numpy array matrix # Default initialization from list or numpy array matrix

View File

@ -259,12 +259,12 @@ class DensityMatrix(QuantumState):
def from_instruction(cls, instruction): def from_instruction(cls, instruction):
"""Return the output density matrix of an instruction. """Return the output density matrix of an instruction.
The statevector is initialized in the state |0,...,0> of the same The statevector is initialized in the state :math:`|{0,\\ldots,0}\\rangle` of
number of qubits as the input instruction or circuit, evolved the same number of qubits as the input instruction or circuit, evolved
by the input instruction, and the output statevector returned. by the input instruction, and the output statevector returned.
Args: Args:
instruction (Instruction or QuantumCircuit): instruction or circuit instruction (qiskit.circuit.Instruction or QuantumCircuit): instruction or circuit
Returns: Returns:
DensityMatrix: the final density matrix. DensityMatrix: the final density matrix.

View File

@ -267,8 +267,26 @@ class Statevector(QuantumState):
def from_label(cls, label): def from_label(cls, label):
"""Return a tensor product of Pauli X,Y,Z eigenstates. """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: Args:
label (string): a eigenstate string ket label 0,1,+,-,r,l. label (string): a eigenstate string ket label ``0``,``1``,``+``,``-``,``r``,``l``.
Returns: Returns:
Statevector: The N-qubit basis state density matrix. 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 QiskitError: if the label contains invalid characters, or the length
of the label is larger than an explicitly specified num_qubits. 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 # Check label is valid
if re.match(r'^[01rl\-+]+$', label) is None: if re.match(r'^[01rl\-+]+$', label) is None:
@ -325,12 +335,12 @@ class Statevector(QuantumState):
def from_instruction(cls, instruction): def from_instruction(cls, instruction):
"""Return the output statevector of an instruction. """Return the output statevector of an instruction.
The statevector is initialized in the state |0,...,0> of the same The statevector is initialized in the state :math:`|{0,\\ldots,0}\\rangle` of the
number of qubits as the input instruction or circuit, evolved same number of qubits as the input instruction or circuit, evolved
by the input instruction, and the output statevector returned. by the input instruction, and the output statevector returned.
Args: Args:
instruction (Instruction or QuantumCircuit): instruction or circuit instruction (qiskit.circuit.Instruction or QuantumCircuit): instruction or circuit
Returns: Returns:
Statevector: The final statevector. Statevector: The final statevector.

View File

@ -261,7 +261,7 @@ def Ud(a, b, c):
def trace_to_fid(trace): 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)""" M. Horodecki, P. Horodecki and R. Horodecki, PRA 60, 1888 (1999)"""
return (4 + np.abs(trace)**2)/20 return (4 + np.abs(trace)**2)/20
@ -350,7 +350,8 @@ class TwoQubitBasisDecomposer():
self.decomp3_supercontrolled] self.decomp3_supercontrolled]
def traces(self, target): 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. # Future gotcha: extending this to non-supercontrolled basis.
# Careful: closest distance between a1,b1,c1 and a2,b2,c2 may be between reflections. # 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. # 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): def decomp0(target):
"""Decompose target ~Ud(x, y, z) with 0 uses of the basis gate. """Decompose target ~Ud(x, y, z) with 0 uses of the basis gate.
Result Ur has trace: 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""" which is optimal for all targets and bases"""
U0l = target.K1l.dot(target.K2l) U0l = target.K1l.dot(target.K2l)
@ -377,7 +378,10 @@ class TwoQubitBasisDecomposer():
def decomp1(self, target): def decomp1(self, target):
"""Decompose target ~Ud(x, y, z) with 1 uses of the basis gate ~Ud(a, b, c). """Decompose target ~Ud(x, y, z) with 1 uses of the basis gate ~Ud(a, b, c).
Result Ur has trace: 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""" 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) # 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()) U0l = target.K1l.dot(self.basis.K1l.T.conj())
@ -389,14 +393,19 @@ class TwoQubitBasisDecomposer():
def decomp2_supercontrolled(self, target): def decomp2_supercontrolled(self, target):
"""Decompose target ~Ud(x, y, z) with 2 uses of the basis gate. """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) For supercontrolled basis ~Ud(pi/4, b, 0), all b, result Ur has trace
which is the optimal approximation for basis of CNOT-class ~Ud(pi/4, 0, 0) .. math::
or DCNOT-class ~Ud(pi/4, pi/4, 0) and any target.
|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 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.) ``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). This is an exact decomposition for supercontrolled basis and target ``~Ud(x, y, 0)``.
No guarantees for non-supercontrolled basis.""" No guarantees for non-supercontrolled basis.
"""
U0l = target.K1l.dot(self.q0l) U0l = target.K1l.dot(self.q0l)
U0r = target.K1r.dot(self.q0r) U0r = target.K1r.dot(self.q0r)

View File

@ -42,7 +42,7 @@ def format_meas_map(meas_map: List[List[int]]) -> Dict[int, List[int]]:
def measure(qubits: List[int], def measure(qubits: List[int],
backend: Optional['BaseBackend'] = None, backend=None,
inst_map: Optional[InstructionScheduleMap] = None, inst_map: Optional[InstructionScheduleMap] = None,
meas_map: Optional[Union[List[List[int]], Dict[int, List[int]]]] = None, meas_map: Optional[Union[List[List[int]], Dict[int, List[int]]]] = None,
qubit_mem_slots: Optional[Dict[int, int]] = None, qubit_mem_slots: Optional[Dict[int, int]] = None,
@ -57,7 +57,8 @@ def measure(qubits: List[int],
Args: Args:
qubits: List of qubits to be measured. 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 inst_map: Mapping of circuit operations to pulse schedules. If None, defaults to the
``instruction_schedule_map`` of ``backend``. ``instruction_schedule_map`` of ``backend``.
meas_map: List of sets of qubits that must be measured together. If None, defaults to 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 return schedule
def measure_all(backend: 'BaseBackend') -> Schedule: def measure_all(backend) -> Schedule:
""" """
Return a Schedule which measures all qubits of the given backend. Return a Schedule which measures all qubits of the given backend.
Args: 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: Returns:
A schedule corresponding to the inputs provided. A schedule corresponding to the inputs provided.

View File

@ -48,7 +48,8 @@ Quantum Information
vectorize vectorize
devectorize devectorize
choi_to_pauli choi_to_pauli
chop, outer chop
outer
entropy entropy
shannon_entropy shannon_entropy
concurrence concurrence

View File

@ -185,11 +185,13 @@ def vectorize(density_matrix, method='col'):
Args: Args:
density_matrix (ndarray): a density matrix. density_matrix (ndarray): a density matrix.
method (str): the method of vectorization. Allowed values are method (str): the method of vectorization.
- 'col' (default) flattens to column-major vector. Allowed values are:
- 'row' flattens to row-major vector.
- 'pauli' flattens in the n-qubit Pauli basis. * 'col' (default) flattens to column-major vector.
- 'pauli-weights': flattens in the n-qubit Pauli basis ordered by * '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. weight.
Returns: Returns:
@ -225,12 +227,14 @@ def devectorize(vectorized_mat, method='col'):
Args: Args:
vectorized_mat (ndarray): a vectorized density matrix. vectorized_mat (ndarray): a vectorized density matrix.
method (str): the method of devectorization. Allowed values are method (str): the method of devectorization.
- 'col' (default): flattens to column-major vector. Allowed values are
- 'row': flattens to row-major vector.
- 'pauli': flattens in the n-qubit Pauli basis. * 'col' (default): flattens to column-major vector.
- 'pauli-weights': flattens in the n-qubit Pauli basis ordered by * 'row': flattens to row-major vector.
weight. * 'pauli': flattens in the n-qubit Pauli basis.
* 'pauli-weights': flattens in the n-qubit Pauli basis ordered by
weight.
Returns: Returns:
ndarray: the resulting matrix. ndarray: the resulting matrix.
@ -263,26 +267,29 @@ def devectorize(vectorized_mat, method='col'):
def choi_to_pauli(choi, order=1): 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 Note that this function assumes that the Choi-matrix
is defined in the standard column-stacking convention is defined in the standard column-stacking convention
and is normalized to have trace 1. For a channel E this 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 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 .. math::
and |rho> = vectorize(rho, method='pauli_weights') for order=0.
|{\\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: Args:
choi (matrix): the input Choi-matrix. choi (matrix): the input Choi-matrix.
order (int): ordering of the Pauli group vector. order (int): ordering of the Pauli group vector.
order=1 (default) is standard lexicographic ordering. ``order=1`` (default) is standard lexicographic ordering
Eg: [II, IX, IY, IZ, XI, XX, XY,...] (e.g. ``[II, IX, IY, IZ, XI, XX, XY,...]``)
order=0 is ordered by weights. ``order=0`` is ordered by weights
Eg. [II, IX, IY, IZ, XI, XY, XZ, XX, XY,...] (e.g. ``[II, IX, IY, IZ, XI, XY, XZ, XX, XY,...]``)
Returns: Returns:
np.array: A superoperator in the Pauli basis. np.array: A superoperator in the Pauli basis.
@ -332,8 +339,7 @@ def chop(array, epsilon=1e-10):
def outer(vector1, vector2=None): 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 The second vector argument is optional, if absent the projector
of the first vector will be returned. of the first vector will be returned.
@ -343,7 +349,7 @@ def outer(vector1, vector2=None):
vector2 (ndarray): the (optional) second vector. vector2 (ndarray): the (optional) second vector.
Returns: Returns:
np.array: The matrix |v1><v2|. np.array: The matrix :math:`|v1\\rangle\\langle{v2}|`.
""" """
warnings.warn( warnings.warn(

View File

@ -68,20 +68,20 @@ class CustomSolver(RecursiveBacktrackingSolver):
class CSPLayout(AnalysisPass): 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, def __init__(self, coupling_map, strict_direction=False, seed=None, call_limit=1000,
time_limit=10): time_limit=10):
""" """If possible, chooses a Layout as a CSP, using backtracking.
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`` If not possible, does not set the layout property. In all the cases, the property
will be added with one of the following values: :meth:`qiskit.transpiler.passes.CSPLayout_stop_reason` will be added with one of the
- solution found: If a perfect layout was found. following values:
- 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. * solution found: If a perfect layout was found.
- time limit reached: If no perfect layout was found and the time limit was reached. * 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: Args:
coupling_map (Coupling): Directed graph representing a coupling map. coupling_map (Coupling): Directed graph representing a coupling map.

View File

@ -51,12 +51,9 @@ ONEQ_XTALK_THRESH = 2
class CrosstalkAdaptiveSchedule(TransformationPass): 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): def __init__(self, backend_prop, crosstalk_prop, weight_factor=0.5, measured_qubits=None):
""" """CrosstalkAdaptiveSchedule initializer.
CrosstalkAdaptiveSchedule initializer.
Args: Args:
backend_prop (BackendProperties): backend properties object backend_prop (BackendProperties): backend properties object
@ -68,18 +65,21 @@ class CrosstalkAdaptiveSchedule(TransformationPass):
We currently ignore crosstalk between pairs of single-qubit gates. We currently ignore crosstalk between pairs of single-qubit gates.
Gate pairs which are not specified are assumed to be crosstalk free. Gate pairs which are not specified are assumed to be crosstalk free.
Example: crosstalk_prop = {(0, 1) : {(2, 3) : 0.2, (2) : 0.15}, Example::
(4, 5) : {(2, 3) : 0.1},
(2, 3) : {(0, 1) : 0.05, (4, 5): 0.05}} 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 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. 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 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 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 and an error rate of 0.15 when it is executed in parallel with a single qubit
gate on qubit 2. gate on qubit 2.
weight_factor (float): weight of gate error/crosstalk terms in the objective 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 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. errors are optimized and 1 meaning that only crosstalk errors are optimized.
weight_factor should be tuned per application to get the best results. weight_factor should be tuned per application to get the best results.

View File

@ -46,9 +46,9 @@ class PassManager:
callback: DEPRECATED - A callback function that will be called after each pass callback: DEPRECATED - A callback function that will be called after each pass
execution. execution.
.. deprecated :: .. deprecated:: 0.13.0
The ``callback`` parameter is deprecated in favor of The ``callback`` parameter is deprecated in favor of
``PassManager.run(..., callback=callback, ...). ``PassManager.run(..., callback=callback, ...)``.
""" """
self.callback = None self.callback = None
@ -276,28 +276,24 @@ class PassManager:
self.property_set = running_passmanager.property_set self.property_set = running_passmanager.property_set
return result return result
def draw( def draw(self, filename=None, style=None, raw=False):
self,
filename: str = None,
style: Dict = None,
raw: bool = False
) -> Union['PIL.Image', None]:
"""Draw the pass manager. """Draw the pass manager.
This function needs `pydot <https://github.com/erocarrera/pydot>`__, which in turn needs This function needs `pydot <https://github.com/erocarrera/pydot>`__, which in turn needs
`Graphviz <https://www.graphviz.org/>`__ to be installed. `Graphviz <https://www.graphviz.org/>`__ to be installed.
Args: Args:
filename: file path to save image to. filename (str): file path to save image to.
style: keys are the pass classes and the values are the colors to make them. An 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 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 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. 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: Returns:
an in-memory representation of the pass manager, or ``None`` if no image was generated Optional[PassManager]: an in-memory representation of the pass manager, or ``None``
or PIL is not installed. if no image was generated or `Pillow <https://pypi.org/project/Pillow/>`__
is not installed.
Raises: Raises:
ImportError: when nxpd or pydot not installed. ImportError: when nxpd or pydot not installed.

View File

@ -250,6 +250,7 @@ def bind_schema(schema, **kwargs):
"""Class decorator for adding schema validation to its instances. """Class decorator for adding schema validation to its instances.
The decorator acts on the model class by adding: The decorator acts on the model class by adding:
* a class attribute ``schema`` with the schema used for validation * a class attribute ``schema`` with the schema used for validation
* a class attribute ``shallow_schema`` used for validation during * a class attribute ``shallow_schema`` used for validation during
instantiation. instantiation.

View File

@ -32,9 +32,9 @@ from qiskit.visualization.pulse import interpolation
from qiskit.pulse.channels import (DriveChannel, ControlChannel, from qiskit.pulse.channels import (DriveChannel, ControlChannel,
MeasureChannel, AcquireChannel, MeasureChannel, AcquireChannel,
SnapshotChannel) SnapshotChannel)
from qiskit.pulse.commands import FrameChangeInstruction
from qiskit.pulse import (SamplePulse, FrameChange, PersistentValue, Snapshot, from qiskit.pulse import (SamplePulse, FrameChange, PersistentValue, Snapshot,
Acquire, PulseError, ParametricPulse) Acquire, PulseError, ParametricPulse)
from qiskit.pulse.commands.frame_change import FrameChangeInstruction
class EventsOutputChannels: class EventsOutputChannels:

View File

@ -17,7 +17,7 @@ features:
the '$' pair. Also if you want to use a dollar sign in your label make sure 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 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:: create the exact label you want, for example::
from qiskit import circuit from qiskit import circuit

View File

@ -14,7 +14,7 @@ features:
* ``__init__`` takes no arguments * ``__init__`` takes no arguments
* ``cmds`` and ``cmd_qubits`` are deprecated and replaced with * ``cmds`` and ``cmd_qubits`` are deprecated and replaced with
``instructions`` and ``qubits_with_instruction`` ``instructions`` and ``qubits_with_instruction``
Example:: Example::

View File

@ -10,7 +10,7 @@ features:
For example: For example:
.. jupyter-execute:: .. code-block:: python
from qiskit.pulse import * from qiskit.pulse import *
from qiskit.pulse import pulse_lib from qiskit.pulse import pulse_lib

View File

@ -1,7 +1,7 @@
--- ---
deprecations: deprecations:
- | - |
The Exception ``TranspilerAccessError´´ has been deprecated. An The Exception ``TranspilerAccessError`` has been deprecated. An
alternative function ``TranspilerError´´ can be used instead to provide alternative function ``TranspilerError`` can be used instead to provide
the same functionality. This alternative function provides the exact same the same functionality. This alternative function provides the exact same
functionality but with greater generality. functionality but with greater generality.

View File

@ -3,5 +3,5 @@
deprecations: deprecations:
- Buffers in Pulse are deprecated. If a nonzero buffer is supplied, a warning - 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 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 include adding samples to a pulse instruction which are :math:`(0.+0.j)` or
the start time of the next pulse to `schedule.duration + buffer`. setting the start time of the next pulse to `schedule.duration + buffer`.

View File

@ -5,11 +5,13 @@ deprecations:
instruction parameters are deprecated and will be removed in a future 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 release. You'll need to convert the input to one of the supported types
which are: which are:
* ``int``
* ``float`` * ``int``
* ``complex`` * ``float``
* ``str`` * ``complex``
* ``np.ndarray`` * ``str``
* ``np.ndarray``
other: other:
- | - |
All sympy parameter output type support have been been removed (or All sympy parameter output type support have been been removed (or

View File

@ -21,10 +21,10 @@ import numpy as np
from qiskit.pulse.channels import (MemorySlot, RegisterSlot, DriveChannel, AcquireChannel, from qiskit.pulse.channels import (MemorySlot, RegisterSlot, DriveChannel, AcquireChannel,
SnapshotChannel, MeasureChannel) SnapshotChannel, MeasureChannel)
from qiskit.pulse.commands import (FrameChange, Acquire, PersistentValue, Snapshot, Delay, from qiskit.pulse.commands import (FrameChange, Acquire, PersistentValue, Snapshot, Delay,
functional_pulse, Instruction, AcquireInstruction, functional_pulse, AcquireInstruction,
PulseInstruction, FrameChangeInstruction, Gaussian, Drag, PulseInstruction, FrameChangeInstruction, Gaussian, Drag,
GaussianSquare, ConstantPulse) 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.timeslots import TimeslotCollection, Interval
from qiskit.pulse.exceptions import PulseError from qiskit.pulse.exceptions import PulseError
from qiskit.pulse.schedule import Schedule, ParameterizedSchedule from qiskit.pulse.schedule import Schedule, ParameterizedSchedule

View File

@ -12,4 +12,6 @@
# copyright notice, and modified files need to carry a notice indicating # copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals. # that they have been altered from the originals.
# pylint: disable=cyclic-import
"""Qiskit pulse scheduling tests.""" """Qiskit pulse scheduling tests."""

View File

@ -35,9 +35,12 @@ commands =
[testenv:docs] [testenv:docs]
basepython = python3 basepython = python3
setenv =
{[testenv]setenv}
QISKIT_DOCS=TRUE
deps = deps =
-r{toxinidir}/requirements-dev.txt -r{toxinidir}/requirements-dev.txt
qiskit-aer qiskit-aer
qiskit-ibmq-provider qiskit-ibmq-provider
commands = commands =
sphinx-build -b html docs/ docs/_build/html {posargs} sphinx-build -W -b html docs/ docs/_build/html {posargs}