Commit Graph

89 Commits

Author SHA1 Message Date
Matthew Treinish 6eb12965fd
Bump minimum supported symengine version for built-in pickle support (#7682)
* 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>
2022-02-21 17:47:46 +00:00
Kevin Hartman 5ff5757a76
Use `contract_nodes` from retworkx in `DAGCircuit`. (#7665)
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.
2022-02-16 15:35:47 -05:00
Matthew Treinish 8c9e01d33f
Drop support for Python 3.6 (#7295)
* 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
2021-12-06 23:30:00 +00:00
Anton Dekusar f6b6395517
Approximate Quantum Compiler (#6727)
* initial version

* linting

* linting

* linting and black

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* linting

* hello

* linting

* remove debugging

* changed variable names, defined d, and moved -1j/2 multiply to the end

* linting

* linting

* checking

* changed variable names

* corrected typo

* corrected typo

* commented

* typo

* typo

* check

* typo

* linting

* changed variable names and commented

* linting

* changed variable names and commented

* cleaning mvp

* cleaning mvp

* cleaning mvp

* added plugin

* code review

* fix types in cnot_structures.py

* more on documentation

* Update qiskit/transpiler/synthesis/aqc/approximate.py

* Update qiskit/transpiler/synthesis/aqc/cnot_unit_objective.py

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

* Update test/python/transpiler/aqc/sample_data.py

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

* code review

* fix cache

* updated plugin, more on documentation

* restructured documentation

* default configuration, aqc plugin setup

* added reno

* Update setup.py

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

* added a test where AQC is invoked via the plugin discovery interface

* added a test where AQC is invoked via pass manager

* update scipy in requirements.txt

* Update qiskit/transpiler/synthesis/aqc/aqc.py

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

* added tests for cnot networks

* added support for plugin configuration

Co-authored-by: Liam Madden <liam.madden2@ibm.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
2021-11-23 09:47:56 -05:00
Eric Peterson 0a4c666ca0
Optimal Synthesis into RXX(theta) (#6551)
* 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>
2021-11-03 22:47:18 +00:00
Luciano Bello f10e312f09
Fix usage of deprecated sympy method expr_free_symbols() (#7117)
* scipy>=1.4,<0.19: expr_free_symbols deprecation

* Correct requirement to be sympy<1.9, not scipy

* deprecated sympy's expr.expr_free_symbols, move to atoms

* remove sympy<1.9

* Update qiskit/circuit/tools/pi_check.py

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

* remove sympy<1.9

* reno added

* black

* Fix formatting in release note

* Fix extra space in release note

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-10-14 16:24:30 +00:00
Luciano Bello ed78b2c802
Pin sympy<1.9 due to deprecation of `expr_free_symbols` (#7116)
* scipy>=1.4,<0.19: expr_free_symbols deprecation

* Correct requirement to be sympy<1.9, not scipy

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
2021-10-11 09:50:08 +00:00
Matthew Treinish 4eda7993fa
Add unitary synthesis plugin interface (#6124)
* 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>
2021-09-30 19:09:24 +00:00
Matthew Treinish 4030839248
Stop casting numpy floats on ParameterExpression bind (#7014)
* 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>
2021-09-15 21:13:28 +00:00
Ivan Carvalho 32f5216df6
More performance improvements for Collect2qBlocks (#6680)
* 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>
2021-08-27 12:49:10 +00:00
Matthew Treinish 5a66b8d1db
Revert "Pin retworkx dependency version to 0.9.0 (#6945)" (#6946)
This reverts commit 803bd0d43d.
2021-08-26 10:12:06 +00:00
Lauren Capelluto 803bd0d43d
Pin retworkx dependency version to 0.9.0 (#6945) 2021-08-25 20:37:16 +00:00
Matthew Treinish 0c2f3446ef
Remove deprecated schemas and validation modules (#6558)
* 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>
2021-07-14 11:11:03 +00:00
Matthew Treinish 927fd0226b
Make tweedledum a hard requirement (#6588)
* 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 #6333
Fixes Qiskit/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>
2021-07-01 14:46:56 +00:00
Ivan Carvalho 0240377262
Performance improvements for collect_2q_blocks (#6433)
* 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>
2021-06-08 18:42:11 +00:00
Matthew Treinish 514caef599
Use symengine for parameter and parameter expressions (#6270)
* 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.
2021-05-05 20:14:12 +00:00
Matthew Treinish 5f0fdb64f5
Remove set() cast in noise adaptive layout (#5952)
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
2021-03-03 21:55:32 +00:00
Matthew Treinish 75e600ebf7
Migrate ApproximateTokenSwapper to only use retworkx and make networkx optional (#5471)
* 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>
2020-12-07 16:17:45 -05:00
Matthew Treinish 84672ff862
Leverage retworkx for DAGCircuit.collect_runs() (#5463)
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>
2020-12-04 01:11:08 +00:00
Matthew Treinish 4e03ad1fb5
Leverage retworkx for apply_operation* inner loop (#5267)
* 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>
2020-11-25 17:42:26 +00:00
Matthew Treinish e137554c80
Remove deepcopies from DAGCircuit.__eq__ (#4992)
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.
2020-09-18 12:12:48 -04:00
Matthew Treinish 7998b60225
Drop support for python 3.5 (#4926)
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>
2020-09-01 12:12:49 -04:00
Matthew Treinish 095d008eba
Use retworkx find_adjacent_node_by_edge for nodes_on_wire() (#4569)
* 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
2020-07-17 15:42:20 -04:00
Thomas Alexander 5bdee8cf84
Pulse builder interface (#4174)
* Fix setting contexts.

* Make builder class private.

* Add group transform.

* Initial demo test is running (not necessarily doing the right thing.

* Typed context gate call parameters.

* Fix imports for builder.

* Fix bugs in tests.

* Minor changes.

* Add pad context. Rename active -> current.

* Add barrier test, expected fail.

* Added group context test.

* Fix bug in acquire instruction.

* Add instruction tests.

* Add builder utilities tests.

* Fix bug in scheduler when no gates present in circuit.

* Test transpiler and scheduler context settings / utilities.

* Made children, a public method.

* add default alignment context for builder.

* Get tests working for call_schedule and call_circuit. Rework right align transform.

* Rename test file.

* Test measure macro.

* Add delay_qubit macro test.

* Update context builder test docstring.

* Review suggestions

* Add gate tests. Running into a bug with the schedule implementation.

* Fix get_qubit_channels

* Fix bug in acquire round 2.

* Deprecation warning to use control(qubits: List) instead of control(channel: int)

* Fix mutable insert flattening schedule tree.

* Fix delay test using qubit index.

* Fix using deprecated cnotgate.

* typos

* Rename alignment contexts.

* update the control based on the new backend schema

* typos

* Unify alignment context naming.

* Unify naming of transforms and fix broken align_right.

* More logic fixes

* lint

* lint

* add older code

* More logic fixes

* lint

* Update docstrings and typehints

* Unused imports

* Release notes

* Review suggestions

* Bug fix for get_qubit_channels(0)

Updated tests too

* Review Suggestions

* lint

* Change error message of _get_channel_prefix_index

* Added raise error for backends without 'channel' information

* Update docstrings for raise errors

* Fix error messages and docstrings

* make self.channels private

* Remove collections.Counter

* Revert "Remove collections.Counter"

This reverts commit d602738387.

* Add complex test.

* Rename _schedule_lazy_circuit_before to _compile_lazy_circuit_before

* Add delay_qubits instruction. Fix bug in schedule equality test.

* Add frequency and phase offset contexts.

* Renamed builder_context to builder.

* Add inline directive.

* linting.

* Fix linting errors.

* Add rescheduler linting.

* Add transforms documentation.

* Lint test builder.

* Add macro linting.

* Schedule linting.

* lint pulse builder.

* Remove cyclical imports with compiler import in pulse builder.

* Add channel builder helper functions. Rename current to active.

* Add relative barrier directive.

* Refactor visualization namespacing.

* Add barrier directive to builder.

* Add num_qubits.

* Add measure_all builder command.

* Add acquire on qubit.

* Add error if not all channels supplied to an Instruction is a channel.

* Remove notebooks directory from hackathon.

* linting

* Fix issue with deprecated Delay.

* Add backport packages for contextvars.

* Reorder schedule and backend arguments. Make backend no longer required.

* Small builder doc update.

* Add simpler calling syntax for the builder.

* Fix python versioninign.

* Add __all__ for builder.

* Add exceptions for no active builder or no backend set.

* Update automodule

Adds documentation of all non-private member function and properties

* Remove unwanted docstrings

Also fixes some typos

* Fix pylint error - BackendNotSet not added in docstring

* Fix weird bug

* Fix 'commands' not imported

* Fix typo

* Rename pulse.reschedule -> pulse.transforms

* Update surrounding code to support rename (releasenotes, add rescheduler back for import path deprecation, API documentation, update imports in tests)

* Remove unwanted newlines

* Reapply feedback from code review

* Add test cases for issues with timeslots.'

* Fix small bug in timeslot insertion finder.

* Fixed another error in the code path.

* Remove accidental comment.

* Fix another small timeslot bug.

(cherry picked from commit 28bbbdec13ebd137ca4e5fd1c61aff0c0304988e)

* Fix small issue.

* Moved circuit_scheduler back to scheduler.

* Properly deprecate scheduler utils.

* linting

* Fix missed pieces when moving back scheduler.

* Fix circular imports by using from instead of import

* linting.

* use Constant instead of ConstantPulse.

* Rename pulse.reschedule -> pulse.transforms

* Update surrounding code to support rename (releasenotes, add rescheduler back for import path deprecation, API documentation, update imports in tests)

* Remove unwanted newlines

* Reapply feedback from code review

* Fix docs unexpected indent

* Linting.

* Change deprecation warning to emit warning at proper stack location.

* Make changes to remove deprecation warnings.

* Remove leftover files from moving of scheduler.

* Revert ordering of channel and qubit arguments compared to parameters.

* Add pulse builder documentation.

* fix up builder tests.

* Linting.

* Docs update.

* Fix deprecation warning.

* Fix reno warnings

* Some builder.py docstring updates

* Documentation updates.

* Fix issue with wrapped function not being properly documented.

* Update builder docs to use jupyter-executer

* Builder interface documentation.

* Fix issue with pulse barrier padding.

* Fix builder barrier doc.

* Structure builder imports.

* Update qiskit/pulse/instructions/directives.py

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Update qiskit/pulse/instructions/acquire.py

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Update qiskit/pulse/instructions/directives.py

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Fix call circuit.

* Enable a samples_to_time and time_to_samples method.

* Add test to builder for calling circuit with cregs.

* Update qiskit/pulse/builder.py

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Update qiskit/pulse/builder.py

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Update qiskit/pulse/builder.py

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Revert acquire import changes.

* Ignore trivial barriers.

* Add note on future deprecation of calling gates within the pulse builder interface.

* Remove commented out execution.

* Update qiskit/pulse/transforms.py

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Remove mention of quantum circuit in builder documentation intro.

* Update qiskit/pulse/builder.py

Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>

* Fix jupyter execute import style.

* Fix unclear arguments in delay_qubits doc.

* Make pulse builder warning more prominent and revise message.

* Fixed import asthetic.

* Move BackendNotSet to exceptions.

* Fix more asthetic setting of default settings in builder.

* Remove left over assert in builder.

* Remove dead comment.

* Reorder _call_circuit.

* Fix small linting error

* Fix commented out example code.

* Remove comment headers.

* Move NoActiveBuilder exception to exceptions.

* Rename time to sample and vice versa to seconds to samples

* Update macros module docstring.

* Fix measure docstring spacing.

* Update test_builder copyright.

* Fix test docstrings.

* Add notes for expected test failures.

* Rename types sections to channels.

* Fix test spacing.

* Revert test modification.

* Fix test_transform docstring.

* Add better coverage for TestRemoveTrivialBarriers

* Readd transform tests.

* Change example usage to examples for uniformity.

* linting invalid name.

* Replace mutate flag with inplace to mirror the circuit model.

* Allow passing name to pulse.build.

* Fix bad builder example assert.

* Allow frequency and phase offset contexts to broacast across channels.

* Revert delay instruction error.

* Remove unnecessary assignments for inplace schedule operations.

* Reorder sequential transform reference ordering.

* Removed unnecessary removal of barriers in transform test.

* Verify that flattened works correctly by testing aligned on grouped schedule.

* Make align right test depending on nesting. Refactor implementation of align_right.

* Use append instead of append where it makes sense. Use inplace where I can.

* Remove the pulse group instruction for now.

* Added better inlining test.

* Implement shift frequency and frequency_offset.

* Clean up builder tests #1

* Deprecate warns only once.

* Remove append_instruction from pulse namespace.

* Fix bad test name in test_instructions.

* Added beta flag.

* Update flatten transform documentation.

* Operator spaces.

* Fix unnecessary else in schedule.

* Fix operator spacing in test-transforms.

* time to seconds

* Fix misnamed test.

* Revert children to _children.

* Update pulse module docstring

* linting.

* Revert apidocs change in pulse.

* Remove call_schedule, call_circuit, call_gate from top-level import.

* Rename block to context_schedule.

* Better error message.

* Fix module level import.

* revert reno files.

* Added space in test builder.

* Added set_phase instruction.

* Revert visualization changes.

* Remove unused import

* Standardize imports for builder PR.

* Docs updates.

Co-authored-by: SooluThomas <soolu.elto@gmail.com>
Co-authored-by: Lauren Capelluto <laurencapelluto@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-08 13:24:50 +00:00
Matthew Treinish e115252b5a
Remove marshmallow from result/ and requirements (#4030)
* 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>
2020-05-07 12:22:24 +00:00
Paul Nation 3275cae1d8
Update to new NumPy RNG (#4297)
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>
2020-04-30 06:35:38 -04:00
Jessie Yu a00a2fc3b0
Allow last_update_date to be a string for BackendProperties.from_dict() (#4125)
* accept last_update_date as string

* move check and add release note

* actually add release note

* Update releasenotes/notes/properties-last-update-date-3d09884ff8634a2f.yaml

Co-Authored-By: Matthew Treinish <mtreinish@kortar.org>

* use isoparse

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-04-21 12:44:25 +00:00
Matthew Treinish dcbe138d51
Make pygments an optional dependency (#4049)
* 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.
2020-03-31 15:05:48 -04:00
Paul Nation 123993c25c
Jupyter widget for circuit library (#3861)
* add qasm lexer

* allow for formatted and saving

* lint

* style

* add to docs as submodule

* add html style

* add circuit library widget

* add line magic

* updates

* remove circuit title as it formats incorrectly

* fix colors

* change header font size

* make widget formatting a bit better

* add ignores

* remove wrong commit

* remove pygmnets from docs

* update

* add pygments directly to qasm

Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com>
2020-03-29 23:23:44 -04:00
Matthew Treinish 0ffebc01a0
Bump retworkx minimum (#3969)
Retworkx 0.3.2 has been released[1] which fixed a perforamnce issue with
the ancestors and descendants functions (see mtreinish/retworkx#41 for
more details). This commit bumps the minimum to ensure users always have
the performance fix.

[1] https://github.com/mtreinish/retworkx/releases/tag/0.3.2
2020-03-13 18:24:12 -04:00
Kevin Krsulich 95328adbab
Transition DAGCircuit to retworkx (#3916)
* 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>
2020-03-11 23:12:45 +00:00
Matthew Treinish 54b3ab1282
Remove marshmallow from Qobj (#3383)
* 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>
2020-03-10 22:36:14 +00:00
Luciano Bello 12bdac1161
Use CSPLayout in Level 2 and Level 3 (#3391)
* some utf8 art

* CSP layout

* add dependency and test

* bug in undirected cm

* release notes and changelog

* rest

* docstring

* optional req

* lint

* disable

* import

* lint

* level 3 tries CSPLayout before DenseLayout

* csp before dense

* req

* test

* level2

* remove optional req

* setup

* bug!

* remove optinal import

* extend limits for level 3

* clean up

* more cleaning

* unused import

* error in tests

* adjusting test

* lint

* release notes

* upgrade note

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
2020-02-27 19:38:34 +00:00
Matthew Treinish 37036f494d Rewrite dag drawer to not use nxpd (#3280)
* 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
2019-11-09 04:49:46 +00:00
Luciano 6745b1ecec
Parallel support for PassManager.run() (#3290)
* 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
2019-10-28 14:29:23 -04:00
Diego M. Rodríguez 1db14a2016 Update marshmallow dependency to v3 (#3084)
* 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
2019-09-17 17:19:08 -04:00
Matthew Treinish e1fc918751
Remove jsonschema cap (#3037)
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.
2019-08-23 15:35:32 -04:00
Matthew Treinish 52110adad5 Make pylatexenc and pillow optional (#2451)
* 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
2019-05-21 07:36:50 -04:00
Lev Bishop 1b4a6976b7 require scipy>=1.0 and go back to scipy.stats.unitary_group for random_unitary() (#2275) 2019-05-02 04:55:45 -04:00
Matthew Treinish d2e5281f59 Use pylatexenc utf8tolatex for gate names in latex drawer (#2246)
* 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
2019-05-01 18:20:00 -04:00
Jay Gambetta efe09ce7f7 Adding random unitary (#1857)
* Adding random unitary that does not use spicy

* Changhegog
2019-02-25 04:09:02 -05:00
Matthew Treinish 4f9034306d
Remove numpy max version cap (#1848)
* 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
2019-02-22 21:38:28 +00:00
Paul Nation 88a15d49ee
Terra no longer depends on requests (#1835)
* remove requests

* remove from setup
2019-02-19 19:15:43 -05:00
Diego M. Rodríguez a967fcd8e2 Remove travis documentation deploy, other fixes (#1678)
* 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.
2019-01-14 07:03:54 -05:00
ewinston 02f3b1f917 bump marshmallow version requirement to 2.17.0 (#1652)
marshmallow.warnings used in qiskit/_util.py was introduced after 2.16.3.
2019-01-07 23:54:21 -05:00
Diego M. Rodríguez 8a01bcb7c7
Update setup.py from requirements (#1527)
* Update setup.py from requirements

Update `setup.py` following previous changes to `requirements.txt`:
* remove `matplotlib` (already in extras)
* move `nxpd` to extras
* move `ipywidgets` to extras
* bump `sympy` to 1.3+
* reorder

* Revise dependencies (ipywidgets 7.3, pydot)
2018-12-18 13:07:01 +01:00
Paul Nation 8a5b221880
Make nxpd optional (#1515)
* make nxpd optional

* add to dev

* updates

* add missing pydot requirement

* lint

* minor msg tweak
2018-12-16 10:32:44 -05:00
Ali Javadi-Abhari b9f33d2bea Refactor DAGCircuit and Unrollers (#1210)
* 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
2018-12-01 08:17:33 -05:00
Luciano fcdb2e150d runtime matplotlib import (#1281)
* 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
2018-11-17 09:09:16 -05:00
Diego M. Rodríguez 2067a18d43
Add auto-validated objects machinery (#1249)
* 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
2018-11-14 11:40:41 +01:00