Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Qiskit/qiskit-terra into small_chan…
Browse files Browse the repository at this point in the history
…ge_docs/3
  • Loading branch information
1ucian0 committed Aug 3, 2023
2 parents ccf0c02 + 28113b6 commit c46ca8f
Show file tree
Hide file tree
Showing 67 changed files with 1,523 additions and 704 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/accelerate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rustworkx-core = "0.13"
# The base version of PyO3 and setting a minimum feature set (e.g. probably just 'extension-module')
# can be done in the workspace and inherited once we hit Rust 1.64.
[dependencies.pyo3]
version = "0.19.1"
version = "0.19.2"
features = ["extension-module", "hashbrown", "indexmap", "num-complex", "num-bigint", "abi3-py38"]

[dependencies.ndarray]
Expand Down
2 changes: 1 addition & 1 deletion crates/qasm2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ crate-type = ["cdylib"]

[dependencies]
hashbrown = "0.12.3"
pyo3 = { version = "0.19.1", features = ["extension-module", "abi3-py38"] }
pyo3 = { version = "0.19.2", features = ["extension-module", "abi3-py38"] }
9 changes: 9 additions & 0 deletions crates/qasm2/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,15 @@ impl State {
}
self.check_trailing_comma(comma.as_ref())?;
qubits
} else if self.strict {
return Err(QASM2ParseError::new_err(message_generic(
Some(&Position::new(
self.current_filename(),
barrier_token.line,
barrier_token.col,
)),
"[strict] barrier statements must have at least one argument",
)));
} else if let Some(num_gate_qubits) = num_gate_qubits {
(0..num_gate_qubits).map(QubitId::new).collect::<Vec<_>>()
} else {
Expand Down
9 changes: 7 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@

pygments_style = "colorful"

# Whether module names are included in crossrefs of functions, classes, etc.
add_module_names = False
# This adds the module name to e.g. function API docs. We use the default of True because our
# module pages sometimes have functions from submodules on the page, and we want to make clear
# that you must include the submodule to import it. We should strongly consider reorganizing our
# code to avoid this, i.e. re-exporting the submodule members from the top-level module. Once fixed
# and verified by only having a single `.. currentmodule::` in the file, we can turn this back to
# False.
add_module_names = True

# A list of prefixes that are ignored for sorting the Python module index
# (e.g., if this is set to ['foo.'], then foo.bar is shown under B, not F).
Expand Down
33 changes: 14 additions & 19 deletions qiskit/algorithms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
The :mod:`qiskit.algorithms` module has been migrated to an independent package:
https://github.com/qiskit-community/qiskit-algorithms.
The current import path is deprecated and will be removed no earlier
than 3 months after the release date. You can run ``pip install qiskit_algorithms``
and import ``from qiskit_algorithms`` instead.
than 3 months after the release date. If your code uses primitives, you can run
``pip install qiskit_algorithms`` and import ``from qiskit_algorithms`` instead.
If you use opflow/quantum instance-based algorithms, please update your code to
use primitives following: https://qisk.it/algo_migration before migrating to
the new package.
It contains a collection of quantum algorithms, for use with quantum computers, to
carry out research and investigate how to solve problems in different domains on
Expand Down Expand Up @@ -277,23 +280,7 @@
Exceptions
----------
.. autosummary::
:toctree: ../stubs/
AlgorithmError
Utility methods
---------------
Utility methods used by algorithms.
.. autosummary::
:toctree: ../stubs/
eval_observables
estimate_observables
.. autoexception:: AlgorithmError
Utility classes
---------------
Expand All @@ -305,6 +292,14 @@
AlgorithmJob
Utility functions
-----------------
Utility functions used by algorithms.
.. autofunction:: eval_observables
.. autofunction:: estimate_observables
"""
import warnings

Expand Down
15 changes: 3 additions & 12 deletions qiskit/assembler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,17 @@
Circuit Assembler
=================
.. autosummary::
:toctree: ../stubs/
assemble_circuits
.. autofunction:: assemble_circuits
Schedule Assembler
==================
.. autosummary::
:toctree: ../stubs/
assemble_schedules
.. autofunction:: assemble_schedules
Disassembler
============
.. autosummary::
:toctree: ../stubs/
disassemble
.. autofunction:: disassemble
RunConfig
=========
Expand Down
45 changes: 38 additions & 7 deletions qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,41 @@
The :class:`.SwitchCaseOp` also understands a special value:
.. py:data: CASE_DEFAULT
Used as a possible "label" in a :class:`.SwitchCaseOp` to represent the default case. This will
always match, if it is tried.
.. py:data:: CASE_DEFAULT
A special object that represents the "default" case of a switch statement. If you use this as a
case target, it must be the last case, and will match anything that wasn't already matched. For
example::
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit import SwitchCaseOp, CASE_DEFAULT
body0 = QuantumCircuit(2, 2)
body0.x(0)
body1 = QuantumCircuit(2, 2)
body1.z(0)
body2 = QuantumCircuit(2, 2)
body2.cx(0, 1)
qr, cr = QuantumRegister(2), ClassicalRegister(2)
qc = QuantumCircuit(qr, cr)
qc.switch(cr, [(0, body0), (1, body1), (CASE_DEFAULT, body2)], qr, cr)
When using the builder interface of :meth:`.QuantumCircuit.switch`, this can also be accessed as
the ``DEFAULT`` attribute of the bound case-builder object, such as::
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
qr, cr = QuantumRegister(2), ClassicalRegister(2)
qc = QuantumCircuit(qr, cr)
with qc.switch(cr) as case:
with case(0):
qc.x(0)
with case(1):
qc.z(0)
with case(case.DEFAULT):
qc.cx(0, 1)
Parametric Quantum Circuits
---------------------------
Expand All @@ -313,10 +345,9 @@
Random Circuits
---------------
.. autosummary::
:toctree: ../stubs/
random.random_circuit
.. currentmodule:: qiskit.circuit.random
.. autofunction:: random_circuit
.. currentmodule:: qiskit.circuit
"""
from .quantumcircuit import QuantumCircuit
from .classicalregister import ClassicalRegister, Clbit
Expand Down
24 changes: 21 additions & 3 deletions qiskit/circuit/commutation_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ def _hashable_parameters(self, params):
return ("fallback", str(params))

def commute(
self, op1: Operation, qargs1: List, cargs1: List, op2: Operation, qargs2: List, cargs2: List
):
self,
op1: Operation,
qargs1: List,
cargs1: List,
op2: Operation,
qargs2: List,
cargs2: List,
max_num_qubits: int = 3,
) -> bool:
"""
Checks if two Operations commute.
Checks if two Operations commute. The return value of `True` means that the operations
truly commute, and the return value of `False` means that either the operations do not
commute or that the commutation check was skipped (for example, when the operations
have conditions or have too many qubits).
Args:
op1: first operation.
Expand All @@ -77,10 +87,14 @@ def commute(
op2: second operation.
qargs2: second operation's qubits.
cargs2: second operation's clbits.
max_num_qubits: the maximum number of qubits to consider, the check may be skipped if
the number of qubits for either operation exceeds this amount.
Returns:
bool: whether two operations commute.
"""
# pylint: disable=too-many-return-statements

# We don't support commutation of conditional gates for now due to bugs in
# CommutativeCancellation. See gh-8553.
if (
Expand All @@ -105,6 +119,10 @@ def commute(
if not (intersection_q or intersection_c):
return True

# Skip the check if the number of qubits for either operation is too large
if len(qargs1) > max_num_qubits or len(qargs2) > max_num_qubits:
return False

# These lines are adapted from commutation_analysis, which is more restrictive than the
# check from dag_dependency when considering nodes with "_directive". It would be nice to
# think which optimizations from dag_dependency can indeed be used.
Expand Down
7 changes: 3 additions & 4 deletions qiskit/circuit/controlflow/switch_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def __repr__(self):
"""A special object that represents the "default" case of a switch statement. If you use this
as a case target, it must be the last case, and will match anything that wasn't already matched.
When using the builder interface of :meth:`.QuantumCircuit.switch`, this can also be accessed as the
``DEFAULT`` attribute of the bound case-builder object.
"""
``DEFAULT`` attribute of the bound case-builder object."""


class SwitchCaseOp(ControlFlowOp):
Expand All @@ -51,12 +50,12 @@ class SwitchCaseOp(ControlFlowOp):
be used to represent a default condition.
This is the low-level interface for creating a switch-case statement; in general, the circuit
method :meth:`.QuantumCircuit.switch_case` should be used as a context manager to access the
method :meth:`.QuantumCircuit.switch` should be used as a context manager to access the
builder interface. At the low level, you must ensure that all the circuit blocks contain equal
numbers of qubits and clbits, and that the order the virtual bits of the containing circuit
should be bound is the same for all blocks. This will likely mean that each circuit block is
wider than its natural width, as each block must span the union of all the spaces covered by
_any_ of the blocks.
*any* of the blocks.
Args:
target: the runtime value to switch on.
Expand Down
Loading

0 comments on commit c46ca8f

Please sign in to comment.