* Bump minimum supported symengine version for built-in pickle support
The new symengine 0.9 release added native support in the package for
pickling symengine objects. Previously we had been converting symengine
objects to sympy objects so we could pickle them. With native support
for pickle in symengine now we no longer need this which besides
removing unnecessary should hopefully make pickling (which we do
internally as part of using multiprocessing) more reliable.
This also seems to fix the hanging we were seeing with multiprocessing
with Python 3.9 on Linux. While investigating that issue it points to
the underlying cause being a bug in cPython with the `fork()` based
start method, but we were only able to reliably trigger it after
switching to symengine in #6270 and having to rely on importing
symengine to pickle the symengine objects. Since we're no longer doing
that after bumping the minimum symengine version this removes the
default disabling of parallel dispatch with Python 3.9. While I'm not
100% confident this fixes the bug, in my testing locally I haven't been
able to reproduce the hang we were encountering (but this is ancedotal
at best). If we do encounter issues with multiprocess hanging in the
future we can look at rewriting the internals of `parallel_map()` or
switching it back to disabled by default.
Fixes#6188
* Fix typos in release notes
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>
Replaces the bulk of the implementation of DAGCircuit.replace_block_with_op with the
generic retworkx method PyDiGraph.contract_nodes, added in Qiskit/retworkx#487.
At a minimum, this change rids Terra of graph manipulation code that is more widely
applicable in a generic graph library. For our current use cases (the ConsolidateBlocks
pass) this change might improve performance slightly, but the primary speedup would
be observed by replace_block_with_op callers that pass cycle_check=True, since
retworkx's contract_nodes performs this check prior to modifying the DAG, and without
making a backup copy.
Resolves#7418
* Use contract_nodes from rx in DAGCircuit.
* Bump min retworkx version and add release note.
* Remove temp variable.
* Drop support for Python 3.6
As has been advertised for some time the Qiskit 0.19.0 release is the
last release which supports Python 3.6 (which goes End of Life in
Decemeber). This commit drops support accordingly so that the minimum
supported Python version is 3.7.
* Add release note
* refer to monodromy for rzx decomposition
* copy/paste monodromy submodule into qiskit
* add reno slug
* satisfy linter
* attempt to fix circular imports
* add copyright headers
* fix logic in test_add_strengths, add an iterator to improve coverage
* remove paths from file comments
* remove stray mention of xx_decompose
* prefer compose to +=
* drop the default error model
* only use RZX gates in the default embodiment dictionary
* rename to xx_decompose; also fix a test error
* Apply suggestions from code review
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
* more PR suggestions
* use local random seeds
* add a unit test for _check_embodiments
* add a requirements line for dataclasses on pythons < 3.7
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Add unitary synthesis plugin interface
This commit adds the initial steps for a unitary synthesis plugin
interface. It enables external packages to ship plugin packages that
then integrate cleanly into qiskit's transpiler without any need for
extra imports or qiskit changes. The user can then just specify the
'unitary_synthesis_method' kwarg on the transpile() call and use the
name of the external plugin and the UnitarySynthesis pass will leverage
that plugin for synthesizing the unitary.
* Also add qubits in payload with coupling map
* Fix lint
* Fix logic
* Add documentation about the plugin interface
* Export get_unitary_synthesis_plugin_names from qiskit.transpiler.passes
* Fix lint
* Tweak doc organization slightly
* Use UnitarySynthesis for unroll3q step
The usefulness of the plugin for unitaries >2q in the default pass
manager pipelines was limited by the fact that previously the pass
managers were all setup to run unroll3q before the unitary synthesis
pass is ever run. The unroll3q pass just calls the circuit.data to
decompose gates >=3q which for unitary gate objects just calls an
inlined equivalent of the 'default' plugin. The purpose of this is to
ensure later passes only ever need to deal with 2q gates. However with
plugins now if a plugin only works on > 2q we'll never actually be
passing an >= 3q unitaries to the plugin in the default pipelines. To
fix this issue, this commit calls unitary synthesis before unroll 3q to
use the synthesis pass to unroll any unitary gates instead of relying on
the gate class's internal decomposition method which will always use the
qiskit decomposition techniques.
* Run black
* Tweak doc organization slightly
* Fix lint
* Fix pylint errors
* Apply suggestions from code review
Co-authored-by: Jake Lishman <jake@binhbar.com>
* Update plugin interface docs
* Review comment updates on UnitarySynthesis pass
* Fix typos
* Include release notes
* Fix docstring typo
* Update qiskit/transpiler/passes/synthesis/unitary_synthesis.py
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
* Ignore deprecation warnings from importlib metadata
Since the importlib metadata 4.8.0 release in late August 2021,
stevedore <= 4.8.0 has raised a deprecation warning around using tuple
based access (which was deprecated in 4.8.1 after 4.8.0 removed it and
broke everything using stevedore). While this has been fixed on the
master branch of stevedore (see:
11da137e3f
) Until that fix is released this commit adds a deprecation warning
ignore because there isn't anything we can do about the warning in
qiskit. Once stevedore has a release that includes this fix we can
remove the ignore from the tests.
* Pin importlib-metadata
The previous commit tried to fix the failures in CI around the
deprecation warnings but while I'm unable to reproduce those locally
with the warning ignore in place it still fails in CI. I expect there is
a similar incompatibility around the 4 frequent importlib-metadata
releases >=4.7.0 (2 of which were yanked) causing issues in the CI
environment. Since things were working fine for the several months this
PR was open prior to 4.7.0 this commit just pins the version in the
constraints file to fix CI.
* Add length units to docstring
* Add min and max qubit abstract properties
This commit adds 2 new required properties to the plugin class interface
for min and max qubits. These enable a plugin author to specify the
number of qubits the plugin supports and if the unitary to be
synthesized is outside that range it will just fallback to using the
``default`` plugin.
* Add option to automatically find basis for a run() call
* Fix typo
* Update gate errors docstring
* Remove approximation degree from plugin interface
* Fix docstring typos
Co-authored-by: Eric Peterson <peterson.eric.c@gmail.com>
* Apply suggestions from code review
Co-authored-by: Jake Lishman <jake@binhbar.com>
* Update qiskit/transpiler/passes/synthesis/unitary_synthesis.py
Co-authored-by: Jake Lishman <jake@binhbar.com>
* Update docstrings and naming and default to 'default' plugin in kwarg
This commit updates several aspects of the documentation to make it more
clear how to use the plugin interface. It also updates the naming of
supported_basis to be supported_bases as it's actually plural. The last
change in this commit is making the default kwarg value for the
unitary synthesis method default to 'default' (for the default built-in
method) instead of None. This simplifies the logic in the unitary
synthesis pass.
* Make coupling_map run() kwarg a tuple
* Add comment on why we don't use a shared global instance
* Fix straggler basis->bases typos
* Apply suggestions from code review
Co-authored-by: Jake Lishman <jake@binhbar.com>
* Document supported_bases handling of no matching basis
Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Eric Peterson <peterson.eric.c@gmail.com>
* Stop casting numpy floats on ParameterExpression bind
In #6368 we added a float cast to the ParameterExpression.bind() method
if any of the specified values were a numpy float type. This was to
workaround a limitation in symengine that it couldn't handle a 16 bit or
32 bit float and would error (see symengine/symengine.py#351). This
syemengine limitation was fixed in symengine/symengine.py#352 and
included in the recent 0.8.0 release. Since we no longer need to casting
to a python float prior to passing the floats to symengine this PR bumps
the min version in the requiremts file and removes the casting. It also
adds a test (which was missing from #6368) to ensure we can use a
numpy.float16 and numpy.float32 with ParameterExpression.bind().
* Update test/python/circuit/test_parameters.py
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
* Use retworkx collect_bicolor_runs in collect_2q
* Temporarily fetch latest retworkx version
* Create collect_2q_runs function in dagcircuit
* Fix black lint
* Remove unused imports
* Fix imports
* Use None instead of -1 in color_fn
* Point to qiskit/retworkx@main
* Use DAGOpNode check instead of .type check
* Bump retworkx version
* Bump retworkx again
* Add reno for retworkx bump
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
* Remove deprecated schemas and validation modules
This commit removes the deprecated schema support from the repo. This
was deprecated in the 0.17.0 release and has been replaced by a
dedicated repository for ibm's payload schemas:
https://github.com/Qiskit/ibm-quantum-schemas
This also removes jsonschema and fastjsonschema from the requirements
list as they're no longer used which will improve the import
performance.
* Remove docs for validation module
Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Make tweedledum a hard requirement
This commit switches the tweedledum requirement from being optional to a
hard requirement for installing qiskit-terra. We rely on tweedledum to
synthesize phase oracles which is commonly used functionality and several
issues have been opened. This use of tweedledum will likely continue to
grow so we should just list it as a requirement moving forward.
We originally made it optional because the functionality depending on
tweedledum was isolated to just the classical function compiler which
wasn't widely used. There were also packaging issues in the past where
the available precompiled binaries for tweedledum didn't support all of
our supported environments, but those have been resolved. There is still
an issue for arm64 macOS binaries but Qiskit doesn't have wide support
for that yet (although there is a job for terra).
At the same time this commit cleans up the optional requirements list
so that aer is no longer listed there and we add an 'all' extra so that
people can have a simple entypoint to install all the optional extras at
once.
Fixes#6333FixesQiskit/qiskit#1253
* Remove unused imports
* Cleanup docstrings
* black setup
* Update requirements.txt
Co-authored-by: Bruno Schmitt <bruno.schmitt@epfl.ch>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Bruno Schmitt <bruno.schmitt@epfl.ch>
* Use find_successors_by_edge in quantum_successors
* Add is_successors to DAGCircuit and collect_2q
* Replace qargs with _qargs in collect_2q_blocks
* Replace op with _op in collect_2q_blocks
* Add tests for is_sucessor/is_predecessor
* Modify requirements.txt temporarily to fetch latest retworkx code
* Correct syntax in requirements.txt to temporarily fetch latest retworkx
* Use Qiskit/retworkx@main
* Update requirements.txt
* Add release note about retworkx upgrade
* Update releasenotes/notes/bump-retworkx-59c7ab59ad02c3c0.yaml
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Fix indentation in release note
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Use symengine for parameter and parameter expressions
This commit uses symengine by default everywhere sympy was previously
used. Symengine is a symbolic engine written in C++ that offers
significantly improved performance over sympy. However, because there
isn't 32 bit wheels available on pypi we can't have it as a hard
requirement in all environments. This adds it as a requirement on
supported platforms 64bit intel, arm64/aarch64, and ppc64le so by
default we have the better performance where available and in the code
there is a fallback to use sympy if it's not available.
* Add pickle support
* Pickle fixes
* Convert to sympy expression for eq and str
* Fix lint
* Fix vector pickle
* Avoid runtime import for symengine
Local benchmarking shows that importing symengine is not nearly as slow
as importing sympy. So to avoid the runtime overhead and reduce the
complexity this commit switches to use module level imports for
symengine.
* Fix test failures due to precision differences
* More fixes from subtle behavior differences
* Fix some of the gradient failures
* Fix failure in sympy fallback path
* Fix gradient tests
* Adjust complex check logic
* Fix lint
* Workaround pulse failure
* Adjust failing test to use np allclose
* Add release note
* Add is_real method to parameterexpression
* Run black post-rebase
* Remove symengine/sympy usage from gradients tests
* Remove unused import
* Fix Delay instruction's new validate is_real check
The definition of the Delay's validate_parameter method was changed in
PR #6225, this just updates it to use the new
ParameterExpression.is_real() so it works in a world with symengine.
In #5847 we added a set() cast to calls to retworkx's graph neighbors
method. This was to workaround a bug in retworkx where duplicate node
indices would be returned if there were parallel edges to a successor
node. In the recent retworkx 0.8.0 release this issue has been fixed
[1][2] so there is no need to cast to a set anymore. Removing the set
cast will remove a duplicate iteration (to generate the set) over the
neighbors list, marginally improving performance.
[1] https://retworkx.readthedocs.io/en/stable/release_notes.html#bug-fixes
[2] 49727f82c4
* Migrate ApproximateTokenSwapper to only use retworkx
This commit removes the networkx usage in the ApproximateTokenSwapper to
use retworkx instead. Besides being speeding up the execution of the
pass what's more important here is that this was the last networkx usage
in qiskit-terra (with the exeception of a couple compatibility
converters in qiskit.dagcircuit). So this commit also makes networkx an
optional dependency and updates the 3 methods (which are outside the
common usage scenarios) to use runtime imports and emit a more detailed
import error if networkx isn't installed.
Fixes: #5470
Related to: #5100
* Remove unecessary duplicate None check
* Add networkx to requirements-dev.txt
There is a single dagcircuit test that uses the to_networkx() method. So
we need to install networkx in test environments.
* Remove _T type
* Update releasenotes/notes/nx-optional-6b8ad63529fe32ca.yaml
Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>
* Remove _V type
Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>
In the recent retworkx 0.7.0 release a new function that can be used for
collect runs. This commit migrates the collect_runs implementation to
leverage retworkx's collect_runs() function. This provides a ~2x speedup
for the optimize_1q_gats transpiler pass.
Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
* Leverage retworkx for apply_operation* inner loop
This commit migrates the inner loop for apply_operation_back and
apply_operation_front to leverage retworkx's
insert_node_between_multiple PyDiGraph method. This retworkx method
performs essentially the same loop internally but executes faster.
Depends on https://github.com/Qiskit/retworkx/pull/181 being included in
a release.
* DNM: Test with retworkx branch
* Update for retworkx 0.6.0 release
* Remove stray kwarg from earlier revision
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
The __eq__ method of the dagcircuit class was previously deep copying
the retworkx PyDAG objects for both self and other to force a reindexing
of the node indices in the graphs to acvoid a bug in retworkx (see
Qiskit/retworkx#27 for more details). In the next retworkx a workaround
for that bug was introduced which removes the need for doing the deepcopy
calls. This commit does that and removes the deep copies which should
improve the performance of run __eq__ o dagcircuit objects.
This commit drops support for running with python 3.5. It marks the
minimum supported version of the package as python 3.6, removes python
3.5 package pins, removes the 3.5 CI jobs, and removes the warning on
python 3.5. Looking at the PyPI stats since the deprecation period
started the number of users on Python 3.5 has diminished significantly,
but not disappeared. There were 783 downloads with pip from pypi out of
total of 25782 total pip downloads in the last 30 days. Compared to the
roughly 10% figure when we deprecated Python 3.5.
Merging this means we can not release until after the documented EoL
date for Python 3.5 support of September 13. This shouldn't be a problem
because with #4767 we will need to coordinate the release of all the
qiskit elements and are planning to do that after 09/13/2020.
It's worth noting that we should start planning to deprecate python 3.6
support sooner rather than later it goes EoL upstream at the end of
next year [1] and some of our other upstream dependencies (mainly numpy
et al) are going to remove support before the upstream Python EoL date
[2].
[1] https://devguide.python.org/#branchstatus
[2] https://numpy.org/neps/nep-0029-deprecation_policy.html
Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
* Use retworkx find_adjacent_node_by_edge for nodes_on_wire()
In the retworkx 0.4.0 release a new PyDAG method is being added for
finding an adjacent node based on an edge. [1] Given a node index it and
a callable that takes in an edge data payload it will return a child node
that has an edge matching that matches that condition. This commit
updates the nodes_on_wires() DAGCircuit method to leverage this function and
speed up it's execution.
[1] fca125d333
* Bump minimum retworkx version
* Fix exception name
* Fix indentation
* Remove marshmallow from result/ and requirements
This commit finishes the process of removing marshmallow from terra. It
rebuilds the result class as bare python classes or SimpleNamespace
subclasses (for classes that allow arbitrary fields). After the result
class has been converted there is nothing using marshmallow or all the
support code in qiskit/validation. So this continues the removal process
by removing those and removing marshmallow and marshmallow-polyfield
from the requirements list.
This commit depends on #4027 and #4016 and can't be merged without
those.
* Fixes from testing
Now #4016 has merged this is unblocked on the terra side. This commit
makes some changes and fixes issues found from testing.
* Abandon SimpleNamespace for Result and ExperimentResult
While both Result and ExperimentResult take arbitrary key value date via
the kwargs using SimpleNamespace as a parent class like in other places
is not a good fit. This is because the signatures for these classes are
signfiicantly different from the base SimpleNamespace. So when Results
are pickled via async execution (like in the BasicAer and Aer providers)
this causes it to either fail or if a custom __reduce__ method is
defined it to not work as expected. This commit pivots the new classes
to be bare objects that store the arbitrary kwargs as a private
dictionary attribute. Attribute access for these fields are implemented
via a custom __getattr__.
* Use correct header type in tests
The results tests were using a raw Marshmallow.Obj object in the tests
to construct the Result qobj headers and relying on the schema to
convert it to a QobjExperimentHeader when it was passed to the Result
constructor. When marshmallow was removed this was updated to a dict()
since that was the closest mapping, but that ignored the transform
marshmallow would do. This commit corrects that oversight and
constructs QobjExperimentHeader object where dict was incorrectly used
before. This is probably what the original tests should have done for
clarity anyway.
* Fix lint
* Fix docstring
* Add release notes
* Fix docs issues from review comments
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
fixes#4273
We used RandomState a lot, but that is now legacy code. This moves us to np.random.default_rng:
https://numpy.org/doc/stable/reference/random/generator.html?highlight=default_rng#numpy.random.default_rng
that makes use of PCG64:
https://numpy.org/doc/stable/reference/random/bit_generators/pcg64.html#numpy.random.PCG64
Besides removing legacy code, this is also 4x faster at initializing the generators.
* move to new rng
* more updates
* update to new rng
* fix issue after merging conflicts
* fix additional merge issue
* update
* update numpy versions
* missed one
* generators in docs
* swear I fixed this earlier
* we using very old scipy
* Fix rebase spots
Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Jay Gambetta <jay.gambetta@us.ibm.com>
* Make pygments an optional dependency
This commit switches to make pygments an optional dependency. Pygments
is solely a visualization requirement. It is used to provide syntax
highlighting for qasm code either in the qasm() circuit method or in a
jupyter widget. We typically do not add visualization dependencies to
the requirements list, so this commit remvoes it from the requirements
lists and adds it to the optional extras list for visualization. All the
uses of pygments are put behind try except blocks. It is added to
requirements-dev because while there are no tests for the pygments
output the docs build depends on it.
At the same time this bumps the minimum version we specified to a
working version. The minimum version of 2.2 was too low and caused
issues for users on 2.3.
Fixes#4048
* Fix lint
* Fix __init__ imports
* Adjust imports to avoid importing qiskit.qasm.pygments without pygments
This commit adjusts the import structure to avoid importing
qiskit.qasm.pygments automatically from qiskit if pygments is not
installed. This is done by not directly importing qiskit.qasm.pygments
from anywhere unless pygments has been installed. Previously this was
done by pulling HAS_PYGMENTS from qiskit.qasm.pygments.lexer, but doing
that meant that qiskit.qasm.pygments.lexer had to always be
importable which required an if statement around all the pygments
subclasses. This commit removes that and instead checks for pygments
importability directly.
* Move networkx towards retworkx syntax and consolidate differences.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Adjust networkx node_id handling to be zero indexed.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Consolidate edge inspection calls requiring data=True.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Change networkx multi_graph indexes from DAGNodes to integers.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Use retworkx if os.environ['USE_RETWORKX'].lower() == 'y'.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Move networkx/retworkx variants to be DAGCircuit subclasses.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Add TravisCI job to run with Retworkx DAGCircuit.
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Switch to retworkx as default
This commit switches the default from the networkx implementation to the
retworkx implemenation, retworkx is added to the requirements list
accordingly because it is now a required dependency.
* Fix rebase mistake
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
* Remove marshmallow from Qobj
This commit removes Marshmallow from qobj. Marshamllow is used
primarily to abstract away the conversion from serialization format from
the python objects. However, this abstraction has a large cost.
Primarily it makes it very difficult to use or figure out exactly how
to construct these objects. This is mostly because of how marshmallow is
used in terra which separates the schema definition from the object
type. It means that there is no way to actually discover what fields (if
any) are required. In many cases the marshmallow objects are just
essential wrappers around dicts and only used to coerce types into the
serialization format. But this is actually undesireable because qobj is
not strictly a serialization format as it's used by terra. It is used as
the transport object passed between different backends to describe
circuits. When the backend is not remote (such as a local simulator) or
not IBMQ and doesn't use qobj schema as the wire protocol this makes it
more difficult to use. Especially for local backends because it means we
have to do an expensive serialization for c native types and then
convert it back just to run experiments in memory. This is also overkill
because there are only really 2 types that need to be coerced from the
output dict and that's not difficult enough to warrant an entire
abstraction layer.
This commit removes marshmallow and replaces Qobj with a class built
using native python types. This is a drop in replacement for the
marshmallow types with the exception that it doesn't json serialize the
output dict (which as described before is an advantage). The actual
serialization should be handled in the providers and in the case of qobj
there are only 2 types which need to be coearced numpy arrays and
complex numbers which can be accomplished with 6 lines defining a custom
json encoder (this was needed for only 1 test). Also, by default
validation is disabled everywhere since this is exceedingly slow and we
should only need validation in testing to verify that things work as
expected. There is flag on the to_dict() method for Qobj 'validate'
which when set true will run it through fastjsonschema which is the
fastest way we can validate the output.
Follow on work from here is to look at using this model in all places
marshmallow is used. We also need to revisit the class heirarchy because
there are too many unecessary layers to this model which makes it harder
to debug or use. But for backwards compatibility this was left alone for
now.
* Apply suggestions from code review
Co-Authored-By: Lauren Capelluto <laurencapelluto@gmail.com>
* Simplify __eq__ methods and dedup dict classes
This commit updates the __eq__ methods to simplify the logic slightly
and make it easier to read. Additionally there were several classes in
qiskit/qobj/qasm_qobj.py that were all essentially the same
implementing a generic qobj/marsmallow wrapper to an arbitrary
dictionary. This commit creates a single class, QobjDictField, that has
all that logic and makes all those duplicate classes a subclass with
overloaded __eq__ methods to have a stricter type check.
* Refactor instruction classes to be attribute based
The 2 instruction clasess PulseQobjInstruction and QasmQobjInstruction
were previously built around a dictionary attribute and all the
attributes were either added or removed from this dictionary. This was
done to simplifying the to_dict() method to basically be returning that
dict. However, because of the normal attribute based access pattern for
instructions and that the all the fields are defined up front (as
opposed to the config and header classes which allow free form
attributes) this makes the code needlessly complex. This commit switches
both classes to use normal instance attributes to store the various
fields and changes the to_dict() method to just build a dict by looping
over the allowed attributes. While marginally slower this way it should
not be noticeable.
* Add error messages to raised attribute errors
* Fix copy paste error
The previous commit adding exception messages to the raised
AttributeErrors had a small copy and paste issue where one __getattr__
method used the arg attr instead of the arg name. This caused an error
because the variable name was not defined. This commit fixes this by
updating the variable name used in the error message.
* Rebase fixes
* Add backwards compat shim for Qobj class
* Fix lint
* Fix lint again
* Fix lint failure
* Add support for parametric pulses
* Add back missing type hint
* Fix tests
* Make PulseQobjInstruction.discriminators a QobjMeasurementOption list
* Preserve required fields in PulseQobjConfig
* Remove unnecessary super calls
* Fix config type on PulsqQobj docstring
* Add missing attributes from PulseQobj
* Update discriminators from_dict() too
* Fix docstring typo in QasmQobjInstruction
* Update input checks for QasmQobjInstruction.__init__
* Deduplicate eq check for QobjDictField subclasses
* Make qobj_id and config required for pulse
* Use attributes instead of dict for QobjMeasurementOption
This commit updates the structure of the QobjMeasurementOption class so
that it uses attributes instead of a private dict. The dict usage only
is only needed for classes that take arbitrary key value input (which is
typically only config and header classes). We should be using standard
attributes if the class doesn't need to handle arbitrary fields.
* Make experiments a required field on PulseQobj
* Make instructions a required param in PulseQobjExperiment
The instructions parameter is required for PulseQobjExperiment, it also
was in the wrong order for backwards compat (it should have been the
first arg, not the last). This commit corrects the oversight.
* Add missing kwargs from PulseQobjExperimentConfig
* Move pulse jsonschema validation into a separate method
* Fix lint again
* Use QobjDictField for pulse qobj classes
This commit makes the pulse qobj classes that take in arbitrary key
value fields (mainly config) inherit from QobjDictField. QobjDictField
contains the definitions needed for getattr, eq etc. The pulse qobj
objects that inherit override things as necessary to ensure
functionality but now rely on the base class where possible.
* Pivot arbitrary key value classes to SimpleNamespace
The arbitrary key value classes (namely headers and some config) were
using a custom built class which basically just duplicated why the
SimpleNamespace class offers from stdlib. This commit pivots those
classes to just reuse SimpleNamespace class as the base instead of
reinventing it.
* Fix lint again
* Apply suggestions from code review
Co-Authored-By: Luciano Bello <luciano.bello@ibm.com>
* Fix docs warnings
* Update SimpleNamespace usage
* Fix pulse qobj docstring
* Update qasm qobj based on review comments
* Fix docs builds
Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>
Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Rewrite dag drawer to not use nxpd
The nxpd library is quite stale and hasn't seen an update in 3 years.
The most recent release of networkx 2.4 is incompatible with nxpd now
because nxpd was using deprecated (and now removed) api calls from
networkx. Additionally, the functionality provided by nxpd already
exists in networkx so there is no reason to rely on an additional
library outside of networkx and pydot. This commit updates the dag
drawer to no longer use nxpd and uses networkx's drawing features
instead.
* Cap networkx for python 3.5
In the networkx release notes for 2.4 [1] it states clearly that the 2.4
release is the last release with python 3.5 support. Since the release
timeline is not fixed and we may end up support python 3.5 in terra
longer than networkx this adds a capped version of networkx on 2.4 for
python 3.5.
[1] https://networkx.github.io/documentation/stable/release/release_2.4.html
* Adjust python 3.5 cap
Since networkx 2.4 is seemingly relying on the guaranteed insertion
ordering for dicts introduced in 3.6 for how we're using topological
sort this adjusts the cap previously introduced to be <2.4 instead of
<=2.4. This should avoid the failures related to this on python 3.5 and
networx 2.4.
* Avoid duplicate requirements with cap
* split!
* passes()
* max_iteration
* replace
* some RunningPassManager clean up
* callback support
* property_set result
* lint
* cleaning up runninpassmanager
* docstring
* args
* parallel
* test
* parallelize using dill
* dill in requirements.txt
* lint
* runningpassmanager style
* dill in setup
* fix the drawer with the new format from passes
* new refs
* Update qiskit/visualization/pass_manager_visualization.py
Co-Authored-By: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
* no label for linear
* refs
* _pass_sets
* pass set in a docstring
* lint
* different circuits
* circuit_or_circuits -> circuits
* Remove silencing ChangedInMarshmallow3Warning
* Fix passing missing when required=True
* Handle unknown keys via unknown=INCLUDE
* Update ModelValidationError
* Update qiskit.validation.fields
* Add **kwargs to different functions
* Remove explicit strict parameter
* Update imports and other tweaks
* Remove load_additional_data from base
Remove the load_additional_data hook, as it is handled by the `unknown`
mechanism.
* Update kwargs for base
* Update dump and load expected return
* Updates and tweaks to fields
* Fix wrong `Mapping` import introduced in an eaerlier commit.
* Expand the `ByType` catching of unserializable/undeserializable fields
as exceptions are no longer swallowed.
* Adjust to renamed `container` member.
* Use make_error instead of fail
* Wrap serialize errors into dict
During a field's `_serialize`, the exceptions raised did not contain
the nested structure that allows identifying the field. This commit
updates `InstructionParameter` so the message is nested.
* Use pre_load for qobj.type and qobj.schema_version
* Lint and kwargs fixes
* Bump marshmallow and marshmallow_polyfield version
* Revert extra import
We have had the jsonschema version capped since it was introduced as a
requirement into terra. There is no clear reason for this and it limits
interoperability with other python packages. Especially because
jsonschema is commonly used library across the python ecosystem. The
version we were capping to was also quite old being release 2.5 years
ago. This commit removes the cap so that people can run terra in
environments where newer jsonschema is required.
* Make pylatexenc and pillow optional
The pylatexenc and pillow requirements are only used in the latex and
latex_source circuit drawers. Since this isn't used by everyone and is a
non-default circuit drawer there is no reason we should force our users
to install these by default. This commit updates the requirements list
and setup.py to make these 2 requirements optional and included in the
visualization setuptools extras to ease installation. If the packages
are not installed it will raise an ImportError with a detailed exception
explaining how to install the missing dependency.
Fixes#2417
* Fix lint
* Fix lint again
* Use pylatexenc utf8tolatex for gate names in latex drawer
When the latex drawer goes to draw custom gates they can be named and
valid unicode string. That's because the gate name attribute is a
string. However, latex doesn't know how to handle all utf8 characters
and requires escaping or custom libraries to render many of them.
Instead of trying to handle every edge case this commit uses the
pylatexenc lib (which is a MIT licensed lib with no additional
dependencies) which contains a mapping of all the unicode characters
with the latex equivalent. This means that things like '_' in custom
gate names will render properly now.
Partially Addresses #2235
* Fix lint
* Remove numpy max version cap
The version cap was put in place to prevent a potential incompatibility
but removing doesn't seem to cause any issues. Having it in place on
terra will cause an issue with ignis which requires numpy>=1.16.0 to
work as expected. While they're both co-installable because pip doesn't
have a depedency solver this only works if ignis is installed second.
(as installing terra second pip will use it's requirements with the
version cap, instead of ignis which has already been installed). To
avoid any potential confusion just removing the version cap is easiest.
* Disable misbehaving pylint checks
* Remove documentation deploy
Remove documentation script and travis job.
* Remove deploy stage from travis
Remove the "deploy doc and pypi" stage entirely, and revise the
"subclassing" of the osx jobs.
* Fix travis script make invocation
* Fix extra lint script commands
* Pin numpy version to <1.16
Pin the numpy version to <1.16 until the potential incompatibilities
are fixed.
* Remove numpy from whitelist, ignore random instead
Remove `numpy` from the `extension-pkg-whitelist`, and instead manually
ignore the check for the members of `numpy.random`, as it was the
only place where the check was significant.
* apply_operation_back/front take the op object
* remove wire_type and index input/output_map over objects
* restore qargs/cargs fields to op nodes
* define wire as (Register,int) object
* remove unused concept of precision in unrollers and dag
* add more dag tests. new function get_op_nodes
* factor out tests into setUp
* update unrollers
* simplify dagunroller and dagbackend
* decomposition rules in gate definitions as list of DAGs
* fix cyclic import by moving visualization import inside circuit.draw()
* recursive unrolling until hitting basis
* adding more mini dags to standard gates
* fix unroll AST to DAG
* update test_unroller.py
* convert load qasm to go qasm, ast, dag, circuit.
* remove unrollers _circuitbackend and _printerbackend
* instruction.param are qasm.node objects. convert to real or sym at your will.
* tweaks to jsonbackend and dagbackend
* return register objects in visualization.utils.get_instructions.
visualizers get param from node['op'].param now.
* Instruction param as sympy objects
* unify generation of json for all instructions, including basics
* update aer tests to not use unrollers, add simulator extensions as dag
basis
* clean decomposition rules per gate
* snapshot label/slot must be string. clarify allowed instruction param formats
* style and lint
* make all node names str.
* update mapper to new dag
* docstring
* lint
* broken test/python/aer/test_statevector_simulator.py
* lint
* bug
* fix bug in constructing DAG from AST node with conditional
* fix get_instructions test
* tests
* test_dagcircuit.TestDagRegisters.test_add_qreg_creg had empty assert
* get_qubits
* fix accessing None conditions
* fixing backend configuration to new diego style
* test dag equality not qasm equality
* fixes#1235 by @1ucian0
* use bin_to_hex_keys in qasm simulator py test
* update swap mapper to work with new dag
* ground truth in test.python.circuit.test_circuit_load_from_qasm.LoadFromQasmTest
* import errors
* test_qasm_file
* update check on qargs
* binding mistake
* some variation in the test
* fix serializing QuantumRegister for c++ sim
* op.qargs -> qargs
* test.python.test_mapper.TestMapper.test_yzy_zyz_cases
* fix some mapper tests. json backend gets qarg from node['qarg'] not op.qarg
* keep layouts in old format in transpiler. convert to (reg, int) in mapper
* check_map
* lint
* run a slow test with cpp simulator
* typo
* test.python.test_mapper_coupling
* temporarily skip two tests due to wire fragment bug in mapper
* test_circuit_operations.py
* test_dag_to_dag_expand_gates_default_basis
* test_from_ast_to_dag
* test_qobj_2_circuits
* style in qiskit/
* style in test/
* docstrings in DAGCircuit
* circuit equivalence
* dag comparison
* pass correct conditional in apply_operation_back
* re-remove get_qasm_snapshot test
* lint
* CHANGELOG. update sympy requirement.
* replace one more qasm comparison with circuit comparison
* readjust the tests
* linting
* no skip in test_visualization
* a deeper catch
* simpler
* test_qcvv_fitters does not depend on matplotlib
* matplotlib from requirements to requirements-dev
* style
* linting
* Add skeleton models and schemas in qiskit.models
Add `qiskit.models`, with the basis for defining objects (models) that
are used for interfacing with terra and formally defined in the specs
(schema). The classes in `base` are meant to be subclasses for each
entity - an example is included in `backend_status`.
* Update requirements
* Add tests for qiskit.models
* Adding validator decorator and moving to Marshmallow 2 (#7)
* Adding validator decorator and moving to Marshmallow 2
* Adding docstrings
* Documenting returns
* Feature/polyfields (#8)
* Moving validation infrastructure to qiskit.validation
* Providing a PolyField basic implementation
* The decorators raises when trying to bind the same schema twice.
* Better PolyField building blocks
* Move fields to own file, tweak and document
Move the Fields related code to `qiskit.validation.fields`, for clarity.
Update `BasePolyField` and `TryFrom` with tweaks to match the expected
functionality, linter and add documentation. Add tests, reorganizing
them slightly into TestCases.
* Revise validation documentation
* Add ByAttribute polymorphic field, fixes
Add the `ByAttribute` polymorphic field, allowing to chose an schema
based on the presence of an attribute. Fix the `to_dict_selector`s in
order to use inspection on the Models directly. Add tests.
* Remove BackendStatusSchema
Remove the `BackendStatusSchema` implementation, in order to introduce
it in future PRs along with its usage.
* Allow for top-level validation in instantiation (#9)
* Allow for top-level validation in instantiation
Update the instantation of a `Model` from kwargs in order to perform
a validation of the regular, top-level fields but not full validation
of the compound fields via a `schemalite` attribute.
* Update top-level validation during instantiation
Fix top-level validation during instantiation, making it take into
account other types of fields. Update tests and style and naming
tweaks.
* Rename test_models to test_validation
For consistency with the module name `qiskit.validation`.
* Updates to validation.base from review