Skip to content

Conversation

ajavadia
Copy link
Member

@ajavadia ajavadia commented Apr 29, 2018

Working towards plug-and-play interchangability of simulator backends, ensuring input/outputs are the same.

Resolves #281 (Simulator Interfaces)
Resolves #314 (Simulator testing)
Resolves #324 (Sympy Simulator testing).

Description

  • Adds 2 new backends: statevector_simulator_cpp and statevector_simulator_py, used for simulating the wavefunction for a single shot, without noise and measurement. The result is returned in the statevector field of the result dictionary

  • Adds a new snapshot command for saving snapshots of simulator internal representations, over all qubits. For the python simulator, this is only the quantum_state. For the cpp simulator, this can be quantum_state, density_matrix, probabilities, etc. (refer to doc). The following simulator commands are treated like barriers to prevent reordering: snapshot, noise, save, load

  • Converts the qasm_simulator_sympy to statevector_simulator_sympy, since the point of a sympy simulator is to preserve precise amplitudes, not to do measurements and counts.

  • Adds a mechanism for providers to report information about aliased names and deprecated names.
    Aliased names are useful since there could be several implementations of functionally similar backends within a provider. So, for example, the user can just write get_backend('local_qasm_simulator'), and this would return an instance of QasmSimulatorCpp(). If that is not built, then an instance of QasmSimualtorPy().
    Deprecated names are useful since backend names could change. For example, now all previous code that use local_qiskit_simulator will automatically redirect to local_qasm_simualtor_cpp, with a deprecation warning.

  • Adds an optional compact flag when inquiring backend names from the wrapper. For example, wrapper.local_backends() returns:

['local_qasm_simulator',
 'local_clifford_simulator',
 'local_unitary_simulator',
 'local_statevector_simulator']

but wrapper.local_backends(compact=False) returns:

['local_qasm_simulator_cpp',
 'local_qasm_simulator_py',
 'local_qasm_simulator_projectq',
 'local_statevector_simulator_cpp',
 'local_statevector_simulator_py',
 'local_statevector_simulator_sympy',
 'local_unitary_simulator_sympy',
 'local_unitary_simulator_py',
 'local_clifford_simulator_cpp']
  • One positive effect of the above is that all previous code that simply used local_qasm_simulator now run with a faster version, if available. This speeds up running the test suite.

  • Adds a _validate() method to several simulators, which is called immediately before a qobj is run(). This can validate semantic things that a schema cannot, such as measurements being at the end of circuit.

  • The behavior of getting the quantum_state by setting shots=1 in the simulators is now deprecated. You can either use the local_statevector_simulator to do this automatically, or use the local_qasm_simulator and place an explicit snapshot command. However, backwards compatibility is still preserved.

  • This PR touches a lot of files, but most are only minor name changes.
    New names are in accordance with this (also see picture below):

PROVIDERNAME_SIMPLEALIAS_simulator_LANGUAGEORPROJECT

image

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

ajavadia and others added 28 commits April 28, 2018 21:20
Serializable Qobj + Pass cpp/projectq simulator tests
* fixing up the backend in the example

* Adding the wrappers to an inport as in the examples this feel the more natural way to use them.
% Your branch is up to date with 'origin/master'.

* Making cleaner and removing the commeted try

* fixing readme
* Remove TestQuantumProgram.test_gate_after_measure

* Merge pull request Qiskit#399 from diego-plan9/fix/qp-discovery-stable

Reintroduce openquantumcompiler.dag2json()

* Remove extra barriers temporalily from compile() (author: @ajavadia)

* Remove unnecessary headers
* no name in the registers means no name :-/

* backend=None as a skip translation

* skip_translation flag

* tests for skip_translation

* linting

* style

* diff simplyfication

* support in execute

* style

* add skip_translation to the execute functions in wrapper and _compiler

* update docstrings

* style

* make default skip_translation False
* DAGCircuit.layers changed to yield a generator
* DAGCircuit.serial_layers changed to yield a generator
* Mapper has been adjust to consume generators instead of lists for
layers
* Backporting changes from stable-0.4.14 to master, manually.
This will remove IBM online simualtors from the tests related
to configuration checking.

* * Temporarily remove remote IBM simulators from tests
* Added a check for making sure basis_gates config parameter
  doesn't conflict with gate_set

* Making peace with the Linter
- Parallelisation is now handled exclusively by OpenMP
- No longer parallelisation over shots on Xcode-clang build
- Also adds text param support for snapshot, save, load instructions
@ajavadia ajavadia mentioned this pull request Apr 29, 2018
9 tasks
@ajavadia ajavadia requested a review from chriseclectic April 29, 2018 03:03
@ajavadia ajavadia requested a review from diego-plan9 April 29, 2018 03:03
@ajavadia
Copy link
Member Author

@diego-plan9 @chriseclectic I think I'm done with this PR.



@unittest.skipIf(_skip_class, 'C++ simulators unavailable')
class TestCrossSimulation(QiskitTestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the functionality for testing the alias and deprecated mechanism included elsewhere? If not, could you please add another TestCase on this file that exercises only that functionality it a bit (ie. without compiling or running - only making sure that querying based on an alias returns a backend as expected, that deprecated backends are converted to the current ones, etc)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@diego-plan9
Copy link
Member

Just a public note following the private discussion to remember that, when merging, this PR should get squashed as the git story is not clean (in particular, it is showing some "duplicated" commits from master with different hashes and content) and might cause issues on upcoming PRs. Can you manually verify that the changes from these commits are included in this PR:

298d42d Circuit drawing improvement
ea195d7 Backporting changes from stable-0.4.14 to master, manually.
f813445 DAGCircuit layer functions yield generators
c1752f4 Compiling with skip_translation
77ffd96 Resyncing master stable
182c2ee fixing up the backend in the example
3f6c023 WIP: Serializable Qobj + Pass cpp/projectq simulator tests

@ajavadia
Copy link
Member Author

@diego-plan9 added more tests and confirmed that all previous PRs are intact.

@ajavadia ajavadia force-pushed the simulator-backends branch 3 times, most recently from 1dd8bf4 to 12afcc8 Compare April 30, 2018 16:37
@ajavadia ajavadia force-pushed the simulator-backends branch from 12afcc8 to dba2a1a Compare April 30, 2018 16:42
@diego-plan9
Copy link
Member

Finally merging, thanks @ajavadia !

@diego-plan9 diego-plan9 merged commit a3cab9b into Qiskit:master Apr 30, 2018
@jaygambetta jaygambetta mentioned this pull request May 18, 2018
77 tasks
@ajavadia ajavadia deleted the simulator-backends branch July 21, 2018 00:08
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* port simulator files. remove a bunch of FIXME since API got better

* moved compact flag from defaultqiskitprovider to wrapper

* dont try to format counts when no cbit exists in qasm_simualtor_py

* choose whichever statevector simualtor is available in tests

* diego comments. restoring the yield PR

* rzz in standard extensions

* no qubit arg for simulator instructions snapshot, load, save, noise

* adding new names for simulator files

* aliased and deprecated dictionaries in ibmqprovider

* compact flag. resolve_backend_name method in default provider. assume name in all configs.

* updated dagcircuit so simulator instructions are known, and treated like barrier

* changed names for ibmqx online simulators

* fix snapshotting of multiple circuits in py simulator

style

* Fixes issue with c++11 async in simulator by removing it.

- Parallelisation is now handled exclusively by OpenMP
- No longer parallelisation over shots on Xcode-clang build
- Also adds text param support for snapshot, save, load instructions

* tests for simulator extensions and input output interfaces

* dont print wait

* turn off auto profiling in test_qasm_simulator_py

* skip cpp tests when not built (i.e. online)

* rename quantum_state to statevector in simulator output

* add tests for aliased, deprecated backends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sympy backends need more testing The simulators need more testing Simulator Interfaces
7 participants