Commit Graph

6331 Commits

Author SHA1 Message Date
Daiki Murata 8455c9f459
Remove deprecated classes and methods in quantum_info (#8070)
* remove deprecated

* fix test

* fix test

* fix cyclic dependency

* create releasenote

* leave import path

* fix lint

* deprecate argument

* Update qiskit/quantum_info/operators/symplectic/pauli.py

* Remove already-expired deprecation

* Revert unnecessary over-specific import

* Flesh out detail in release note

* Issue deprecation warning for old Pauli path

* Reinstate buggy deprecated behaviour

* Reinstate None default for Pauli data kwarg

Co-authored-by: ikkoham <ikkoham@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-23 11:16:16 +00:00
Junye Huang 3241978340
Move `qiskit.test.mock` to `qiskit.providers.fake_provider` and deprecate (#8121)
* redirect imports from qiskit.test.mock to qiskit.providers.fake_provider

* import the rest of classes in fake_backend_v2 to fake_provider

* redirect imports to fake_provider

Anything that can be imported from fake_provider root are imported from there instead of sub files.

* change jupyter-execute to code-block

* redirect import

* Combine multiple imports into one

* Add missing )

* move all files except __init__ from qiskit.test.mock to qiskit.providers.fake_provider

* redirect imports in fake_provider.__init__.py

* redirect imports in mock.__init__.py

* Use relative imports in fake_provider.__init__.py

* redirect .utlis imports

* Don't import fake_backend_v2.py in __init__ to avoid clashes of FakeBackendV2 names

* Match imports from the old and new __init__

* Organize imports

* black linting

* Fix FakePulseBackend import order dependency

* fix cyclic import

* move relative import after absolute import

* fix cyclic import

* Update MANIFEST.ini with new path

* add deprecation warning

* add deprecation test

* add release note

* move test files from test.python.mock to test.python.providers.fake_provider

* linting

* linting

* change deprecation warning location

* update path for tools/update_fake_backends.py

* rename docstrings

* Update ibmq_mock.py

* import back FakeBackendV2 and FakeBackend5QV2 in __init__

* Modify release note

* reformat release note

* remove unnecessary tests

These two tests were introduced in PR #7437 to test the new imports which are not needed any more: https://github.com/Qiskit/qiskit-terra/pull/7437#discussion_r810843786

* Use relative imports

* redirect import in test_schedular.py

* first draft of module level doc

* Update docstring of fake provider v1 and v2

* Update wording of module level doc

* add fake V1 and V2 backends

* Correct fake v1 and v2 backends in the list

* comment on backends that do not have V2 versions

* list special fake backends

* Add descriptions for sections

* add code example using jupyter execute

* Update code example and improve descriptions of the module

* not using fake provider before fake provider get backend name is fixed

* modify comment

* formating fix

* Remove fake backend coupling map from docstrings

* linting

* remove coupling map of Pooughkeepsie

* add qiskit-aer to tox.ini as deps for docs build

* Revert "remove coupling map of Pooughkeepsie"

This reverts commit 4560748930.

* Revert "linting"

This reverts commit eddfa65bf6.

* Revert "Remove fake backend coupling map from docstrings"

This reverts commit 3aee7a8b57.

* fix coupling maps

* Fix minor typos

* Issue deprecation warnings from all levels of package

The previous commits in this PR did not maintain the old import paths
for submodules of `qisit.test.mock`.  This re-instatates them, with
suitable deprecation warnings.  Hopefully nobody is using these anyway,
but it's better to be on the safe side.

* Import from the correct location

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-23 02:28:30 +00:00
Matthew Treinish f25a7ed586
Refactor marginal_memory() hex to bin lookup table to be a true static (#8223)
* Refactor marginal_memory() hex to bin lookup table to be a true static

In the recently merged #8051 we create a lookup table in Rust to speed
up the hex->bin conversion used internally as part of the
marginal_memory() function. This was previously done using the
lazy_static crate which is used to lazily evaluate dynamic code to
create a static at runtime on the first access. The typical use case for
this is to create a static Vec or HashMap. However for the
marginal_counts() usage we didn't need to do this because we were
creating a fixed size array so the static can be evaulated at compile
time assuming the array is constructed with a const function. This
commit removes the lazy_static usage and switches to a true static to
further improve the performance of the lookup table by avoiding the
construction overhead.

* Reduce number of empty entries in LUT

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-23 01:18:53 +00:00
Naoki Kanazawa c650341a52
QPY schedule serialization (#7300)
* Schedule serialization wip

* pulse serialization

* move mapping io to separate file

* move dump numbers to parameter_values

* add alignment context serialization

* block serialization

* add interface

* bug fix

* black / lint

* documentation

* add serialization for kernel and discriminator

* migrate circuit qpy to qpy module

* keep import path

* reno

* lint

* fix import path

* update schedule qpy with cleanup. alignment classes and acquire instruction class are also updated, i.e. remove individual instance members.

* move type key enum to type_keys module

* add mapping writer (for qpy values) and cleanup sequence serializer to make sure element data is INSTRUCTION_PARAM struct.

* compress symbolic pulse expressions with zlib

* remove change to existing circuit qpy tests

* cleanup for type key

* add unittest and fix some bug
- small bug fix for wrong class usage
- exeption for None symbolic expression
- add explicit expand for symengine expression

* update documentation

* add seek(0) to data_from_binary helper function

* remove subclasses and hard coded is_sequential in every subclass

* documentation update and type fix

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* move test to own module

* update typehint

* add backward compatibility test

* fix merge and cleanup

* add circuit calibrations serialization

* fix qpy_compat test

* remove compatibility test for parameterized program

* update reno for calibrations

* fix data size

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-23 00:25:30 +00:00
Yuma-Nakamura 206ecd0e20
Add grouping by full-operator commutation relations to PauliList (#7874)
* add group_inter_qubit_commuting

* fix style lint of pauli_list.py

* fix style lint

* fix black format

* update format

* add test, docstring

* reformat

* adjust line length

* adjust docstring format

* adjust docstring format

* adjust docstring format

* update docstring and comment

* add release note

* Update documentation

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-22 23:30:03 +00:00
ewinston 2b52def6d6
simplify documentation of UGate and U3Gate. (#8220)
* simplify documentation of UGate and U3Gate.

* Update qiskit/circuit/library/standard_gates/u.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Update qiskit/circuit/library/standard_gates/u.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Update qiskit/circuit/library/standard_gates/u3.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Update qiskit/circuit/library/standard_gates/u.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* fix trailing whitespace

* Fix trailing whitespace in qiskit/circuit/library/standard_gates/u3.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-22 22:14:24 +00:00
Matthew Treinish 5d93d8a34c
Expand instruction_supported() to optionally check parameters (#7807)
* Expand instruction_supported() to optionally check parameters

This commit expands the recently added instruction_supported() method of
the Target class to also enable optionally checking if a parameter on an
instruction is supported. This is anticipating future changes around how
instruction parameters are represented in terra more generally as part
of #7624 and specifically in the Target for #7797. Before we do any
refactoring around this having a standard API for checking if a
parameter is supported is useful. This commit expands the interface for
the insturction_supported() method to check any combination of
operation name, qargs, operation class, or parameters (either operation
name or class is required) and the method will return True if that
instruction can be run on the Target device.

* Fix docs build

* Expand test coverage

* Apply suggestions from code review

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>

* Update fake backend name in tests

* Fix handling of multiple parameters in gate name case

* Fix parameter checking in class gate input case

* Add missing test path

* Add release note

* Fix release-note typo

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-22 20:59:55 +00:00
Matthew Treinish 8ee4ac80ec
Add dedicated functions for memory marginalization (#8051)
* Add dedicated functions for memory marginalization

This commit adds dedicated functions for memory marginalization.
Previously, the marginal_counts() function had support for marginalizing
memory in a Results object, but this  can be inefficient especially if
your memory list is outside a Results object. The new functions added in
this commit are implemented in Rust and multithreaded. Additionally the
marginal_counts() function is updated to use the same inner Rust
functions.

* Fix rustfmt

* Add missing test file

* Fix typos

Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>

* Remove unused import

* Increate default parallel_threshold to 1000

* Add support for different measurement levels

* Update docstring

* Add release note

* Expand unit tests

* Fix rustfmt

* Apply suggestions from code review

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Use a lookup table instead of a match statement

Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>
Co-authored-by: Kevin Hartman <kevin@hart.mn>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-22 19:07:06 +00:00
Matthew Treinish 5a6ec94699
Set version number to 0.21.0rc1 for first release candidate (#8200)
* Set version number to 0.21.0rc1 for first release candidate

For the 0.21.0 release we're going to start pushing release candidates
prior to the release to enable testing before we cut the final release.
In preparation for tagging the first release candidate this commit
updates the version string to indicate it's a release candidate.

* Update cargo version to reflect 0.21.0

* Fix qpy handling of prerelease tags

* Fix pre-release handling in qpy compat tests

* Inline version parsing in qpy compat test

* Fix qpy version handling
2022-06-22 16:52:11 +00:00
dependabot[bot] b7142c9102
Bump indexmap from 1.9.0 to 1.9.1 (#8221)
Bumps [indexmap](https://github.com/bluss/indexmap) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/bluss/indexmap/releases)
- [Changelog](https://github.com/bluss/indexmap/blob/master/RELEASES.md)
- [Commits](https://github.com/bluss/indexmap/compare/1.9.0...1.9.1)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-22 13:50:26 +00:00
Matthew Treinish dbc81a8dcd
Leverage Python SharedMemory for common transpile args (#7789)
* Leverage Python SharedMemory for common transpile args

This commit uses the Python shared memory library to reduce the overhead
of launching parallel processes as part of transpile. As the size of the
backends grow the payload size we're serializing and copying between
worker processes is also increasing. When we're running a lot of small
circuits at once on a big backend we can easily spend far more time
dealing with IO overhead than running the transpilation. By using shared
memory this reduces the overhead to only serializing and copying it once
and then each worker process just needs to serializing it. While this
doesn't remove all the overhead it should reduce the impact somewhat.

Fixes #7741

* Fix python 3.7 compat

* Fix approximation degree parsing

* Fix broken test

* Fix more test failures

* Simplify arg parsing logic

* Only use shared memory when running in parallel

The serialization overhead of using shared memory is only necessary when
we're running in parallel. If we're running serially there is no need to
serialize the transpiler arguments and write them to shared memory since
serially we are running the same memory space. This commit splits the
code path between serial and parallel and only uses shared memory when
we are running in parallel.

* Fix handling of ideal gates in UnitarySynthesis

The move to only having one copy of shared arguments fixed an issue in
the handling of basis gates in some cases where a list input was not
properly wrapped in a list. This was then causing UnitarySynthesis pass
to be skipped in some cases because the target basis was incomplete (and
was only a single gate) which wouldn't match any of the basis the
synthesis pass could work in. By fixing this issue with shared memory
a bug in UnitarySynthesis was exposed when trying to run the pass with
no coupling map but a Target (i.e. an ideal simulator) the pass would
fail because it assumed if there was a Target there was a coupling map
and would try to use the coupling map to find the natural direction to
synthesize the 2q gates into. This commit fixes the unitary synthesis
pass to ignore the natural direction if no coupling map is preset even
if there is a target. The test triggering this condition is then updated
to update the result to include the output of the unitary synthesis
pass.

* Fix lint failure on python 3.7

This commit fixes a lint failure on Python 3.7 by disabling a module
name check for the shared memory attributes in the multiprocessing
module. These were added in Python 3.8 and don't exist in older python
versions. For python 3.7 we use a backport library to make up for this,
but pylint doesn't know to conditionally check the stdlib import
statement as it is only used on Python >= 3.8. To avoid the failure we
just disable checking the imports from stdlib.

* Add release notes

* Relax equality check on test_target_ideal_gates opt_level 3

This commit relaxes the output circuit equality check on the optimization
level 3 variant of the test_target_ideal_gates() test. Since this branch
fixes the basis gate handling so that the UnitarySynthesis pass is
actually running now the exact output is dependent on the 2q synthesis
routine which on different platforms has subtlely different but equally
correct results based on differences in the the floating point
implementation. To avoid spurious CI failures this commit changes the
test just check the output unitary of the circuit is equivalent to the
input for optimization level 3.

* Only try to write pickle buffer length to shared memory

In CI we were seeing failures on the macOS Python 3.7 environment around
writing the pickle bytes data to the memory view of the shared memory
object that we allocated. This failure was being caused by the macOS
shared memory backport library over allocating the shared memory object
and the size of the memory view buffer being larger than the pickle
data. This caused the assignment of the pickle data to the memory view
to fail because the lengths didn't match. This commit fixes this by
explicitly only writing the bytes equal to the pickle length into
memory. This ensures no matter how big the allocated memory view is we
are always writing the correct size.

Co-Authored-By: Jake Lishman <jake.lishman@ibm.com>

* Actually commit black changes

* Remove manual manipulation of QISKIT_IN_PARALLEL

This commit removes a leftover from earlier iterations of the PR that
were manually manipulation of QISKIT_IN_PARALLEL. This was done earlier
in the PR branch because parallel_map was manually replaced with
multiprocessing directly. However, after refining the use of shared
memory this wasn't needed and parallel_map was used instead.

* Remove unecessary optimization_level storage

* Update docs and type hints

* Remove unnecessary list cast for basis gates

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-22 12:03:35 +00:00
Paul Nation 6a22ed81e2
Optimize standard gate.__array__ (#8218)
* optimize matrix construction

* black

* lint

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-22 05:00:58 +00:00
Julien Gacon cbb64ed266
Remove deprecated `optimize` from `Optimizer` (and small other fixes) (#8123)
* Remove deprecated methods from Optimizers

* `optimize` method is superseded by `minimize`
* SPSA didn't trigger the deprecation warning, so it's included now
* The `factr` attribute in `P_BFGS` was deprecated 13 months ago

* add reno

* Apply suggestions from code review

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Fix lint and reno

* change meth to attr in reno

* remove logic for Optimizer.optimize in VQE

* lint

* address comments from review

* Fix lint

This commit fixes the pylint failures. Two for unused imports and the
third was a to disable a broken check in pylint where it was complaining
about a multiline string being a docstring without """ quotes.

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-22 02:13:28 +00:00
Matthew Treinish 8dc0cfc593
Add namespace redirect hook for qiskit-aer (#5089)
* Remove namespace packaging and hardcode elements (attempt 2)

Namespace packages are constant source of problems for users. The python
packaging ecosystem around splitting packages across namespaces is
fragile at the best of times and can often leave a you with an
environment that isn't recoverable (especially when mixing install
methods). There is also a performance hit whenever there is a piece of
the namespace we allow external packages to extend since it requires
doing a full python path search which can be slow depending on the
backing I/O and the number of paths in sys.path for an environment. This
commit starts the process of addressing this by removing the arbitrary
namespace hook points and hard coding the element namespace maps via a
custom import loader at the root of the namespace. This has 2 advantages
it removes the use of namespace packages so the fragility and
performance impact are fixed since every element will be renamed to use
'qiskit_' instead of 'qiskit.', but it also makes it explicit where we
extend the namespace. The previous method allowed any package to extend
qiskit.* and qiskit.providers.* with whatever they wanted.

We'll need to coordinate updating the elements with this merging,
because it is a breaking change for each element (although not for end
users).

A potential follow on is to add a plugin interface for 3rd party
providers like what was proposed in #1465 so that we can make external
providers externally discoverable without needing to add manual hook
points moving forward (this was done for backwards compat with the aqt
and honeywell provider).

This is a second attempt at removing namespace packaging. The first
attempt in PR #4767 was merged and had to be reverted because there were
some circular import error issues that needed to be resolved. Since
having this in terra blocks CI for all the qiskit elements a revert was
necessary to unblock developement for the entire project while those
were resolved.

* Try using new aer path for qiskit.Aer alias

* Try moving Aer and IBMQ alias to the end

* Fix typo

* Fix circular import issue

* Fix typos

* Run black

* Remove file encoding

* Adjust init with import re-direct

* Make qiskit_aer a opportunistic load

To ensure that someone with an old version of Aer installed can still
access it via the old namespace this changes the meta finder logic to
first try qiskit_aer, if it's importable then we build the redirect path
first and use that for the legacy qiskit.providers.aer path. If it's not
then we just return None and fall back to the other finders in
sys.meta_path.

To support this the pkgutil hook is added back to qiskit.providers to
add the namespace hook for old version of aer using namespace packagingm
although not strictly necessary because the implicit support for
namespace packages will still likely work we can remove it at a later
date.

* Deprecate qiskit.Aer entrypoint

* Fix lint

* Remove unnecessary noqa comments

* Revert version.py change and use old aer import for now

* Fix typo

* Add back pkgutil extension to root init

* Make redirect hook more generic

* Add comments explaining the various hooks

* Make qiskit.Aer a pending deprecation instead of a deprecation

* Restrict namespace redirect error to ModuleNotFoundError

* Apply suggestions from code review

Co-authored-by: Jake Lishman <jake@binhbar.com>

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-22 00:50:06 +00:00
Jake Lishman ea02667698
Change data type of `QuantumCircuit.data` elements (#8093)
* Convert QuantumCircuit.data items to CircuitInstruction

This introduces a new, lightweight class `CircuitInstruction` the
encapsulates the previous 3-tuple that made up the items of
`QuantumCircuit.data`.  It includes a legacy API that makes the object
appear to be the old 3-tuple when used as if it were that tuple, and the
relatively small changeset for this commit is an approximate indication
that these should mostly be suitable.  There will be significant
performance penalties for accessing the legacy interface, however, due
to some internal type conversions, so it is a matter of priority to
convert internal usage to the new dotted-attribute access form.

The only places necessary to change across Terra were those where the
data elements were compared by referential equality to expected values
(such as in the control-flow builders), and places that were invalidly
accessing the private attribute `QuantumCircuit._data`.  All these are
updated.

`ParameterTable` should in the future be changed to operate over this
entire context, but that was beyond the scope of the initial commit.

* Convert all usage of data tuple to CircuitInstruction

This previous commit is the minimal set of changes needed for the entire
test suite to pass, but large parts of Terra and the test suite were
still using the backwards-compatibility shims when dealing with
`QuantumCircuit.data`.  This changes over every single usage within
Terra to use the new dotted-access form, rather than the tuple indexing
or iteration that previously existed.

The internal types of the `qargs` and `cargs` in `DAGDepNode` and
`DAGOpNode` are also changed to be `tuple` now; previously they were
semi-undefined, and in some cases were not consistent, but not caught in
the test suite.  Since changing the type of the `qubits` parameter in
`CircuitInstruction` to be tuple (unless using the
backwards-compatibility shims), this caused a lot of failures where the
value was being assigned directly.  Normalising to `tuple` has the same
benefit as it does in the circuit instruction - less copying overhead,
and no worrying about multiple writable references to the same object.

By far the largest set of changes are in the test suite; we do a lot of
comparing things for exact equality, and since the type is now changed
from `list` to `tuple`, all the tests had to be updated.  This isn't
expected to have much impact on user code, but changing the type to an
immutable one has large benefits for us when copying these data
structures.

* Correct bad version in comment

* Simplify unnecessary if/else

* Update remnant legacy interface uses

Some uses of the legacy interface related to directly setting
`QuantumCircuit.data` had slipped through the cracks.  A bug in
`astroid` caused its inference to fail, and think that these settings
made the scalar type of `QuantumCircuit.data` the old 3-tuple after it
saw these settings.  Since there's a property setter for `data`, that's
a bug in `astroid`, but it still turned up some useful additional cases
that were useful to correct.

* Remove accidental blank line

* Use QuantumCircuit.copy_empty_like in Instruction constructors

* Correct global phase in Instruction.inverse

* Shut pylint up about consider-using-generator

pylint isn't actually correct in this case.  `tuple(<list comp>)` is
more efficient than `tuple(<generator>)` (certainly as of Python 3.10),
because Python still needs to use a temporary vector-like expanding
collection while consuming the iterable so despite appearances there's
no memory benefit to the generator, and list comprehensions are
translated into faster bytecode than general generators.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-21 23:51:21 +00:00
Matthew Treinish 42c72be193
Fix BackendV2 support for PassManagerConfig.from_backend() (#8109)
This commit fixes the PassManagerConfig.from_backend() constructor
method when running with a BackendV2 object. Previously this was not
correctly handled and it always assumed the input backend was a
BackendV1 object. This would cause an error if you ran the constructor
with a BackendV2.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-21 22:31:06 +00:00
Kevin J. Sung 992c2619d6
Edit Result to always contain date, status, header (#8216)
* date attribute

Date attribute is needed for some specific applications such as mitigation in mthree. It is not created by default when running a job in the basicAer backend.

* Update test_result.py

* Adding default attributes header and status

I have no clue why in the test_results the attribute status is repeated.

* fix Result repr

* add release note

* Qualify method name in release note

* Remove final conditional attribute lookup on Result

Co-authored-by: Alejandro Montanez <alejomonbar@gmail.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-21 20:53:29 +00:00
Matthew Treinish 71495591d7
Add StagedPassManager class for pass manager with defined stages (#6403)
* Add FullPassManager class for pass manager with defined stages

This commit adds a new PassManager subclass, FullPassManager. This class
is used to have a PassManager with a defined structure and stages for
the normal transpile workflow. The preset pass managers are then updated
to be FullPassManager objects they conform to the fixed structure. Having
a class with defined phases gives us flexibility in the future for making
the transpiler pluggable with external plugins (similar to what's done in
PR #6124) and also have backend hook points before or after different
phases of the transpile.

Fixes #5978

* Add docs

* Deduplicate preset passmanager construction

* Update docs

* Add dedicated scheduling stage to FullPassManager

* Add missing new UnitarySynthesis kwargs after rebase

* Use basis_translator as default method instead of basis

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>

* Rename FullPassManager StructuredPassManager

* Rename generate_scheduling_post_opt() generate_scheduling()

* Fix missing and incorrect arguments

* Fix more rebase issues

* Fix even more rebase issues

* Only run unroll3q on level 0-2 if coupling map is set

To preserve the behavior prior to this reorganization this commit makes
the Unroll3qorMore pass run if we have a coupling map set. This is
because this pass is only needed to be run for these optimization levels
so that the layout and routing passes can function (as they only work
with 2q gates). If we're not running these passes we shouldn't be
unrolling gates. This will fix the last 4 QAOA test failures post the
recent rebase as that was failing because we were trying to unroll an
unbound 4q hamiltonian gate when weren't before.

* Rework StructuredPassManager as a more dynamic StagedPassManager

This commit redefines the previous StructuredPassManager class into a
more dynamic StagedPassmanager. The StagedPassManager doesn't have fixed
hard coded stages anymore but instead lets users define their own
stages. It also adds implicit 'pre_' and 'post_' hook points for each
listed stage. This lets users dynamically define the stages based on a
particular use case.

* Fix docs

* Update internal pass set on each access

This commit updates the api for the StagedPassManager to refresh the
internal pass list on each access. This adds a little overhead but with
the tradeoff of making in place modifications to a stage's pass manager
reflected without needing to manually call an update method.

* Rename phases attribute to stages

* Fix lint

* Explicitly set name in qpy compat tests

The rework of the preset passmanager construction changes the import
order slightly and the number of circuits constructed in a session prior
to the qpy compat deserialization side generating equivalent circuits
for comparision has changed. This is causing all the deserialization
side numbers to change and the tests are now failing because the circuit
names are not equivalent. Since the exact name is a side effect of the
import order (based on the number of unnamed circuits created in the
session priort) it's not part of what the qpy tests are validating.
We're trying to assert that the naem is preserved loading a qpy file
across a version boundary. To fix this issues this commit adds an
explicit name to the generation for all the circuits to ensure that we
have a deterministic name for each circuit.

* Apply suggestions from code review

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Run black

* Update type hint

* Remove out of date docstring note

* Update copyright header date in qiskit/transpiler/preset_passmanagers/common.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Add check for invalid stage names

* Add backwards compatibility note

* Add docs on using StagedPassManager features with preset passmanagers

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-21 18:57:04 +00:00
ewinston f28f3835fb
support control flow in BasisTranslator pass (#7808)
* create two tests and 1st modification of unroller

* if_else test, parameter test

* black

* linting

* change shallow copy of control flow ops to not copy body

* add special copy

* debug

* add `replace_blocks` method

* minor update

* clean debug code

* linting fix bugs

* minor commit

* linting

* don't recurse on run

* linting

* don't mutate basis in "_update_basis".

* Update qiskit/transpiler/passes/basis/basis_translator.py

Co-authored-by: Jake Lishman <jake@binhbar.com>

* apply_translation returns bool

* factor out "replace_node" function

* linting

* singledispatchmethod -> singledispatch for python 3.7

* black

* fix indentation bug

* linting

* black

* changed _get_example_gates following @jakelishman suggestion.

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-21 17:40:00 +00:00
Frank Harkins 4414c4eca6
Pass `max_size` to Statevector LaTeX drawer (#8197)
* Fix #7516

* Remove unused import

* Improve splitting of string literals

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-21 16:17:04 +00:00
Jake Lishman 0e3e68d162
Speedup constant factors in `LookaheadSwap` (#8068)
* Speedup constant factors in `LookaheadSwap`

This picks some of the low-hanging fruit in `LookaheadSwap`, avoiding
recalculating various properties and entities that are already known,
and making some access patterns more efficient.  It does not change the
complexity properties of the algorithm, which will still cause its
runtime to be excessive for large circuits.

* Put comment in correct location

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-21 15:02:21 +00:00
Luciano Bello 4d251d1c2d
enable multiplexer tests from text circuit drawer (#8207)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-21 12:42:27 +00:00
dependabot[bot] ed4e1a397d
Bump num-complex from 0.4.1 to 0.4.2 (#8203)
Bumps [num-complex](https://github.com/rust-num/num-complex) from 0.4.1 to 0.4.2.
- [Release notes](https://github.com/rust-num/num-complex/releases)
- [Changelog](https://github.com/rust-num/num-complex/blob/master/RELEASES.md)
- [Commits](https://github.com/rust-num/num-complex/compare/num-complex-0.4.1...num-complex-0.4.2)

---
updated-dependencies:
- dependency-name: num-complex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-20 12:56:46 +00:00
dependabot[bot] d0125a955c
Bump indexmap from 1.8.2 to 1.9.0 (#8195)
Bumps [indexmap](https://github.com/bluss/indexmap) from 1.8.2 to 1.9.0.
- [Release notes](https://github.com/bluss/indexmap/releases)
- [Changelog](https://github.com/bluss/indexmap/blob/master/RELEASES.md)
- [Commits](https://github.com/bluss/indexmap/compare/1.8.2...1.9.0)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-18 10:05:07 +00:00
Matthew Treinish a34f0ce1ec
Fix handling of ControlledGates in QPY (#8055)
* Fix handling of ControlledGates in QPY

This commit fixes the handling of ControlledGates in QPY. Previously the
extra parameters needed to reconstruct a custom controlled gate were not
encoded into the QPY payload. Fixing this required a version bump to the
QPY format to modify the payload for a custom instruction entry. Once we
added to the format the extra data required for a controlled gate, the
number of control qubits, the control state, and the base gate object,
the deserializer has enough information to recreate the custom
ControlledGate objects. However, fixing this exposed another bug with
standard library multicontrolled gates where they often didn't contain
sufficient data in the payload to reconstruct either.

Fixes #7999

* Fix test failure caused by missing condition

This commit fixes the qpy test failure. This was caused by the omission
of the classical condition on a controlled gate when reconstructing the
circuit in deserialization. Fixing this oversight fixes the test
failures.

* Add QPY version 5 payload format description

* Add release note

* Expand test coverage

* Only check controlled gate type key on version 5 or newer

* Fix mcu1 deserialization

* Add copy to avoid mutating list while iterating over it

* Fix compat test minimum version

This commit fixes the failing compat test which was incorrectly trying
to test ControlledGates with 0.20.2 generation. We should only run the
controlled gate tests starting with 0.21.0.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-17 23:50:55 +00:00
dependabot[bot] 755310e3c3
Bump hashbrown from 0.11.2 to 0.12.1 (#8201)
Bumps [hashbrown](https://github.com/rust-lang/hashbrown) from 0.11.2 to 0.12.1.
- [Release notes](https://github.com/rust-lang/hashbrown/releases)
- [Changelog](https://github.com/rust-lang/hashbrown/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/hashbrown/compare/v0.11.2...v0.12.1)

---
updated-dependencies:
- dependency-name: hashbrown
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-17 17:29:13 -04:00
Matthew Treinish 186c807877
Explicitly set MSRV for rust extension (#8196)
* Explicitly set MSRV for rust extension

This commit explicitly sets the MSRV (minimum supported rust version)
for Qiskit Terra to 1.56 which was released in October 2021 (with 1.56.1
which fixed two CVEs being released Nov. 1st 2021). Previously we had
avoided setting a hard MSRV and opted to try and just loosely support the
past 6 months of rust releases. However, managing it loosely has proven
tricky to manage in practice. This commit sets a hard version for MSRV
and modifies a test job to validate we're able to compile with the MSRV.
This should ensure we're able to avoid breaking compatibility for that
version.

* Explicitly set MSRV to 1.56.1 instead of loosely 1.56

* Explicitly set version as variable in CI config

* Assign MSRV to azure variable

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-17 19:20:42 +00:00
johannesgreiner 3577669925
Fix indent in execute_function docstring (#8181)
* fix indent in execute_function for docu

* removing trailing whitespace in qiskit/execute_function.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-17 18:14:21 +00:00
Alexander Ivrii 573198bdc5
Bug fixes in InverseCancellation pass (#8165)
* Bug fixes in InverseCancellation pass

* Fix function name

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-17 01:32:03 +00:00
Pedro Rivero f47cd45e29
Add `.clear()` and `.copy_empty_like()` functionality to QuantumCircuit. (#8134)
* Add .copy_empty_like and .clear to QuantumCircuit

* Simplify copy_empty_like in QuantumCircuit

* Update docstring for copy_empty_like in QuantumCircuit

* Deepcopy global_phase for copy_empty_like in QuantumCircuit

* Add tests and refactor

* Add release note

* Add .copy_empty_like and .clear to QuantumCircuit

* Simplify copy_empty_like in QuantumCircuit

* Update docstring for copy_empty_like in QuantumCircuit

* Deepcopy global_phase for copy_empty_like in QuantumCircuit

* Add tests and refactor

* Add release note

* Update docstring

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update docstring

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update docstring

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update test to check metadta and calibrations

* Add tests for circuit name

* Update releasenotes/notes/clear-circuit-b8edd4126f47d75a.yaml

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-16 23:10:01 +00:00
Tan Jun Liang bcd98951ea
decompose(reps=1) repeating decompose (#8142)
* decompose() repeat decompose

https://github.com/Qiskit/qiskit-terra/issues/8139#issue-1261865139   
summary:
```
circuit.decompose(reps = 5) # repeat decompose 5 times
```

* add reps parameters

forgot

* Update quantumcircuit.py

* Update qiskit/circuit/quantumcircuit.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update quantumcircuit.py

* Update quantumcircuit.py

* Update blueprintcircuit.py

* Update blueprintcircuit.py

* fixing some bug

fixed also: https://github.com/Qiskit/qiskit-terra/issues/5974#issue-823183659
but need to fix label gate repeat decompose not working.

* Update decompose.py

* Update decompose.py

* fix https://github.com/Qiskit/qiskit-terra/issues/5974

* Update decompose.py

* test_case & fix decompose repeat work with multi_gate

* Update test_decompose.py

* Update test_decompose.py

* Update test_decompose.py

* Update decompose.py

* Update decompose.py

* Update decompose.py

* Update test_decompose.py

* fix lint

* Update decompose.py

* fix lint

* change back preset

* changing back

* Update quantumcircuit.py

* original version

* release_note

* Update releasenotes/notes/add-parameters-to-decompose-5a541d1b5afe2c68.yaml

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Update add-parameters-to-decompose-5a541d1b5afe2c68.yaml

* Update add-parameters-to-decompose-5a541d1b5afe2c68.yaml

* Update releasenotes/notes/add-parameters-to-decompose-5a541d1b5afe2c68.yaml

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Update releasenotes/notes/add-parameters-to-decompose-5a541d1b5afe2c68.yaml

Co-authored-by: Jake Lishman <jake@binhbar.com>

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-16 21:20:11 +00:00
Naoki Kanazawa 7391168c89
Cleanup timeline drawer with schedule analysis pass. (#7935)
* Cleanup timeline and add schedule info to scheduled circuit.

* review comment

* fix bug

* review comments

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* lint

* disable cyclic import lint check (likely a bug)

* fix import path

* Revert "fix import path"

This reverts commit 1fa5382df4.

* fix bug

* add deprecation for unscheduled circuit drawing

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-16 17:00:14 +00:00
Prakhar Bhatnagar 5f77531a1b
Switched `dag_drawer` from `pydot` to `retworkx` (#8162)
* switched `dag_drawer` from pydot to `retworkx`

* added optional annotation to method

* added graphviz annotations to tests

* minor fixes

* added mapping to `retworkx`

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-15 22:38:09 +00:00
Naoki Kanazawa 1e872b73fb
Serializable parametric pulse (#7821)
* Symbolic parametric pulse

This PR makes following changes.

1. add `_define` method to ParametricPulse.

This method is expected to be implemented by each ParametricPulse subclass. Subclass must return Sympy or symengine symbolic equation that can be serialized. This method is called once in the constructor to fill `.definition` attribute of the instance. This definition is used for QPY serialization.

2. change behavior of `get_waveform`

This method is originally implemented as abstractmethod that calls another callback that generates numpy array of samples (thus not serializable). Now this is a baseclass method that generates waveform array from the symbolic equation.

3. minor updates

Now pulse parameters are not direct class attribute. Parameter names are defined as class attribute `PARAMS_DEF` and values are stored as instance variable `param_values`. This is good for writing serializer since it doesn't need to know attribute of each subclass, but just can call name def and values to get data to serialize.

* Improve performance of parametrized pulse evaluation

* Implement Constant pulse using Piecewise

This works around an issue with sympy where its lambda returns a scalar
instead of an array when the expression evaluates to a scalar:

https://github.com/sympy/sympy/issues/5642

* Fall back to sympy for parametric pulse evaluation

* Use sympy Symbol with sympy lambdify

* WIP: cache symbolic pulse lambda functions

* move lambdify to init subclass for called once

* turn parameter properties into attribute and remove slots

* remove attribute and add __getattr__ and readd slots for better performance.

* move symbolic funcs directly to _define

* Convert numerical_func to staticmethod

Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* remove symbolic add constraints, numerical func is renamed to definition for better integration with circuit instruction

* revert changes to parametric pulse and create new symbolic pulse file

* add ITE-like program

* sympy runtime import

* update test notebook

* add attribute docs

* fix non-constraints

* remove pulse type instance variable

* use descriptor

* remove redundant comment

* Update
- Add symbolic pulse to assemble
- Add symbplic pulse to parameter manager
- Remove risefall ratio from GaussianSquare paramters

* keep raw data for QPY encoding

* update unittest

* update helper function name

* add reno

* remove notebook

* fix lint

* fix unittest and logic

* add more docs

* review comments

* lint fix

* fix documentation

* minor drawer fix

* documentation upgrade

Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>

* review comment misc

Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* remove abstract class methods

This commit removes class methods for symbolic expression so that SymbolicPulse can be instantiated by itself. And descriptors only saves Dict[Expr, Callable], i.e. lambda cache, rather than enforcing name-based mapping.

* add error handling for amplitude

* treat amp as a special parameter

* Remove expressions for amplitude validation

* support symengine
- symengine doesn't support lamdify of complex expression, e.g. DRAG pulse
- symengine doesn't support Less expression with complex value substitution
- symengine Lambda function doesn't support args in mixture of complex and float object

To overcome these, envelope expressions are separately stored for I, Q channel, and evaluation of 'amp' is excluded from symbolic operation. Thus in this implementation symbols are all real numbers.

* use real=False option

* review comment

Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* - fix attribute
- duration and amp are required
- instantiate subclass with expression
- remove __dict__ usage in __getattr__ and readd __slots__
- fix documentation
- update private attirbute names

* undo change to requirements-dev

* fix __getattr__ mechanism

Directly accessing to the instance variable crashes copy and deepcopy because when the object is copied the __init__ is not called before the first getattr is called. Then copied instance tries to find missing (not initialized) attribute in recursive way. use of __getattribute__ fixes this problem.

* fix type hint reference

* simplification

* move amp from constructor to `parameters` dict

* review comment

Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* fix bug

- use getattr in __eq__; e.g. Waveform doesn't have envelope
- fix parameter maanger

in addition, this replaces _param_vals and _param_names tuple with _params dictionary because overhead of generating a dict is significant.

* fix typo

* add eval_conditions to skip waveform generation

* fall back to sympy lamdify when function is not supported

* documentation update

Co-authored-by: Will Shanks <willshanks@us.ibm.com>
Co-authored-by: Daniel Egger <38065505+eggerdj@users.noreply.github.com>

* replace eval_conditions with valid_amp_conditions

Co-authored-by: Will Shanks <willshanks@us.ibm.com>

* update hashing and equality, redefine expressions more immutably

* add error message for missing parameter

* cleanup

* check parameter before hashing

* move amp check to constructor

* add envelope to hash

* update docs

* Update qiskit/pulse/library/symbolic_pulses.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* lint

Co-authored-by: Will Shanks <willshanks@us.ibm.com>
Co-authored-by: Daniel J. Egger <38065505+eggerdj@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2022-06-15 21:25:04 +00:00
Kevin Hartman a0b9a846f9
Integrate `qiskit-toqm` as an optional package for layout and routing. (#7825)
* Integrate qiskit-toqm as an optional layout and routing pass.

* Run formatting.

* Add release note.

* S

* Exclude Linux aarch64 for qiskit-toqm in requirements-dev.txt.

This is currently necessary since Qiskit TOQM isn't published to PyPI
for Linux aarch64 due to a bug.

* qiskit-toqm performs layout changes always.

...when configured using one of its optimization strategies. This is because
non-optimal configurations (i.e. anything using GreedyMapper under the
hood) aren't compatible with the layout search parameter, and in fact
break when it is provided. These configurations happen to always perform
layout (without the explicit search) through a different means. To make
everything consistent, it should be assumed that no matter which optimization
strategy is used, layout changes will be made via routing.

qiskit-toqm users can still create a custom strategy if they wish to use
an optimal configuration that does not make layout changes, and then
use their own pass manager.

* Add basic testing for TOQM integration.

* Update to use qiskit-toqm 0.0.3 API.

* Add testing of 5 qubit device.

This exercises the optimal mapper code paths of qiskit-toqm
opt levels.

* Update for target awareness.

* Add extra to setup.py for toqm.

* Bump requirement-dev.txt TOQM version.
2022-06-14 19:11:06 -04:00
Jake Lishman 8061cfe04e
Fix QASM 3 exporter not respecting unknown `basis_gates` (#8160)
Previously the logic in the QASM 3 exporter was out-of-order, and would
ignore non-standard names added to `basis_gates`.  This changes the
logic order to correctly assume that everything in `basis_gates` is
automatically defined.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-14 13:49:21 +00:00
Daiki Murata b8ea2b0bc9
Add label assigned check in SparsePauliOp (#8101)
* add assign check

* Update qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>

* fix check condition

* update reno

* update reno section header

Co-authored-by: Ikko Hamamura <ikkoham@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-14 10:58:23 +00:00
Jimmy Yao be5e71a157
enables the code example (#8172) 2022-06-14 10:34:53 +02:00
Pythonix 8d2eeeac44
Fix the order of the Suzuki-Trotter formula in the documentation (#8171)
My previous commit https://github.com/Qiskit/qiskit-terra/pull/8167 corrects the documentation for the Lie-Trotter formula. According to my understanding of [1], the Suzuki-Trotter formula is second order accurate. This is now corrected in this commit.

[1] https://arxiv.org/pdf/math-ph/0506007.pdf

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-13 16:58:09 +00:00
Pythonix 027d2f1bed
Fix the order of the Lie-Trotter formula in the documentation (#8167)
* Fix the order of the Lie-Trotter formula in the documentation

The Lie-Trotter formula has a second order error [1][2].

[1] https://arxiv.org/pdf/math-ph/0506007.pdf
[2] https://simons.berkeley.edu/sites/default/files/docs/15639/trottererrortheorysimons.pdf

* Second refrence added, where Lie-Trotter scaling is easier to find

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
2022-06-13 14:18:14 +00:00
upsideon 669c7710f5
Update GaussianPulse for consistent parameter validation results whether validation occurs during or after construction. (#8151)
* Clarifying that qiskit.pulse.library.ParametricPulse.validate_parameters is for internal use only.

* Adding release note for documentation update.

* Fixing release note.

* Making GaussianSquare pulse validation consistent before and after construction.

* Removing old release note.

* Adding a new release note.

* Make Sphinx link anonymous

* Include issue link in regression test

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2022-06-13 12:39:02 +00:00
Hugo van Kemenade 5d1205a84a
Replace deprecated threading.currentThread with current_thread (#8168) 2022-06-12 22:05:01 +00:00
Chih-Han Huang a18df1456c
Fix the typo in the documentation of CSwapGate (#8144)
* Fixed typo of CSwap

1. Fixed wrong Circuit symbol of CSwap in Qiskit (document part)
2. Fixed wrong Circuit symbol of CSwap in other textbooks (document part)
3. Fixed typo of Math formula of CSwap in Qiskit (document part)

* Delete duplicated empty row

* Delete redundant space

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-10 14:20:22 +00:00
Ikko Hamamura 35fd08b6b7
Callback Protocol for Minimizer in VQE (#7846)
* Callback Protocol for Minimizer in VQE

* fix lint

* Update qiskit/algorithms/minimum_eigen_solvers/vqe.py

* Update qiskit/algorithms/minimum_eigen_solvers/vqe.py

* Apply suggestions from code review

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* black

* move Minimizer

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-09 15:40:04 +00:00
Kevin Hartman 25ab23b0e8
Use `ParameterReferences` type for `ParameterTable` values (#7408)
* Add class ReferenceListing to track param use.

* Make init consistent with other collections.

* Cleanup.

* Add from_iterable and testing.

* Address linting issues.

* Make ParameterReferences set-like, only.

Previously, ParameterReferences implemented both Set and MutableSequence.
Now, it implements MutableSet, only. Existing seq-like usages throughout
Terra have been eliminated.

* Special handling for ParameterReferences pickling.

* Address minor review comments.

* Add release note.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-09 14:44:49 +00:00
Tan Jun Liang f1591fe581
changing qc.decompose() to transpile(qc, backend) (#8129)
* Yeah I would agree. We should probably exchange all the qc.decompose() occurances to transpilations since e.g. the final decomposition of the Toffoli also doesn't use the actual basis gates of the device. Using the decomposition method is outdated (and far from optimal!) now that we don't have U1/2/3 as basis gates anymore.

Yeah I would agree. We should probably exchange all the `qc.decompose()` occurances to transpilations since e.g. the final decomposition of the Toffoli also doesn't use the actual basis gates of the device. Using the decomposition method is outdated (and far from optimal!) now that we don't have U1/2/3 as basis gates anymore.

_Originally posted by @Cryoris in https://github.com/Qiskit/qiskit-terra/issues/7796#issuecomment-1074144889_

* Fix whitespace

* Update qiskit/transpiler/__init__.py

Co-authored-by: Julien Gacon <gaconju@gmail.com>

* Change preferred import for transpile

Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2022-06-09 01:52:48 +00:00
upsideon fb201bf041
Parallelizing scheduling of multiple circuits via parallel_map. (#8110)
* Adding tests for circuit scheduler.

* Fixes #2659 by parallelizing circuit scheduling via parallel_map.

* Removing unnecessary unittest execution code.

* Adding release note.

* Ensuring scheduling of multiple circuits does not change when executed in parallel.

* Adding infrastructure for executing tests with parallelism enabled.

* Renaming enableParallelProcessing to enable_parallel_processing.

* Mocking the sys module in tests for parallel defaults.

* Fixing incorrect sys module patching.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-08 12:56:49 +00:00
Frank Harkins 792ff60b22
Add Qiskit Textbook circuit drawer style (#8147)
* Add textbook style

* Update docstring

* Add release note for textbook circuit style

* Update releasenotes/notes/add-textbook-circuit-style-98600038608c8f75.yaml

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Add test cases for textbook color scheme

* Update docstring

Co-authored-by: Jake Lishman <jake@binhbar.com>
2022-06-08 10:44:58 +00:00
Iulia Zidaru 1658bb4626
Fixed error in plot_histogram when number_to_keep is smaller that the number of keys (#7481)
* plot_histogram fails when given number_to_keep parameter #7461

* Fix style

* fix review comments

* remove temporary the release notes

* add release notes

* Reformat release notes

* Temp - remove code from release note

* Add code example in release note.

* Add code example in release note.

* Add code example in release note.

* add test for multiple executions display

* change dictionary from OderedDict to defacultdict

* small fixes

* Correct use of optional tests

* Reword release note

* Improve documentation of `number_to_keep`

* Fix crash on distance measures

* Revert if.

* refactor code & add test

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-07 13:09:06 +00:00
chetmurthy a84380d431
fix marginal_counts (which failed on pulse backend) (issue #6430) (#8099)
* fix marginal_counts (which failed on pulse backend)

this is code copied from @rithikaadiga 's branch, but it's so small I
just copied it, b/c didn't want to deal with applying all the changes
since in the main trunk.

* add release-note

* Update qiskit/result/utils.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Update releasenotes/fix-marginal_counts-on-pulse-backend.yaml

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Update releasenotes/fix-marginal_counts-on-pulse-backend.yaml

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* fix formatting (black)

Co-authored-by: rithikaadiga <56549493+rithikaadiga@users.noreply.github.com>

* minor cleanup to suggested fix.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch fix-marginal_counts-on-pulse-backend
# Your branch is up to date with 'my-fork/fix-marginal_counts-on-pulse-backend'.
#
# Changes to be committed:
#	modified:   qiskit/result/utils.py
#

* Update releasenotes/fix-marginal_counts-on-pulse-backend.yaml

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Update releasenotes/fix-marginal_counts-on-pulse-backend.yaml

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* Update test/python/result/test_result.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

* redo test per suggestion from @1ucian0

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch fix-marginal_counts-on-pulse-backend
# Your branch is up to date with 'my-fork/fix-marginal_counts-on-pulse-backend'.
#
# Changes to be committed:
#	modified:   test/python/result/test_result.py
#

* Update test/python/result/test_result.py

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: rithikaadiga <56549493+rithikaadiga@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-07 11:30:40 +00:00