Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor simulator #213

Merged

Conversation

JamesB-1qbit
Copy link
Contributor

@JamesB-1qbit JamesB-1qbit commented Sep 15, 2022

Makes each target it's own class with SimulatorBase as a parent class. The majority of the code is copied/pasted.

@JamesB-1qbit JamesB-1qbit changed the title Refactor simulator WIP Refactor simulator Sep 30, 2022
@JamesB-1qbit JamesB-1qbit marked this pull request as ready for review September 30, 2022 13:19
Copy link
Collaborator

@ValentinS4t1qbit ValentinS4t1qbit left a comment

Choose a reason for hiding this comment

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

I think we can improve a few things, overall I think this redesign is great and what we needed. Thank you for pushing this forward.

You probably have done it already, but think about how your design will be able to handle the multiplication of simulators / backends coming from Cirq, Qiskit, Qualms etc that we may want to support, as well as new simulator frameworks that simply have not been integrated to Tangelo at all.

tangelo/linq/target/target_cirq.py Outdated Show resolved Hide resolved
tangelo/linq/target/target_cirq.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/target/__init__.py Show resolved Hide resolved
tangelo/linq/target/target_cirq.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
examples/linq/1.the_basics.ipynb Show resolved Hide resolved
tangelo/linq/target/target_cirq.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@ValentinS4t1qbit ValentinS4t1qbit left a comment

Choose a reason for hiding this comment

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

I apologize, I reviewed a bit too quickly the first time and I think your Simulator wrapper function requires work.

I'm grateful for the opportunity to think about this design change, which brings out some subtleties we hadn't faced before.

tangelo/linq/target/__init__.py Outdated Show resolved Hide resolved
tangelo/linq/target/__init__.py Outdated Show resolved Hide resolved
tangelo/linq/target/target_qulacs.py Outdated Show resolved Hide resolved
tangelo/linq/tests/test_simulator.py Outdated Show resolved Hide resolved
tangelo/toolboxes/measurements/qubit_terms_grouping.py Outdated Show resolved Hide resolved
tangelo/helpers/utils.py Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/tests/test_simulator_noisy.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@ValentinS4t1qbit ValentinS4t1qbit left a comment

Choose a reason for hiding this comment

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

A number of improvements to make. I want to recognize that this PR is getting a lot of comments because:

  • you are introducing several non-trivial badass features
  • you are introducing patterns we haven't used before, therefore learning and challenging us and yourself.

As far as I'm concerned, this is an amazing PR. Please keep up the good work and take us to the finish line.

tangelo/linq/tests/test_simulator.py Outdated Show resolved Hide resolved
tangelo/linq/tests/test_simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator_base.py Outdated Show resolved Hide resolved
tangelo/linq/simulator_base.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@alexfleury-sb alexfleury-sb left a comment

Choose a reason for hiding this comment

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

I reviewed only the big picture, and I like the modularity it will bring. While looking at TrueFalseSimulator, it seems easy to implement another backend rapidly.

Copy link
Collaborator

@ValentinS4t1qbit ValentinS4t1qbit left a comment

Choose a reason for hiding this comment

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

I swear we are getting there.

We are currently importing a class (SimulatorBase) but in reality we just need a function that does not care at all about anything class-related. Instead let's define and import a standalone function. The SimulatorBase can then use that function to implement a method with the same name, and that method can then be automatically leveraged by the children classes, as it currently does. Let's make that method available at the right level of the package using the __init__ files.

This way we have no loss of functionality, and the imports are straightforward. This also means we never need to instantiate SimulatorBase, which is intended to just be a base class for target simulators. Everything seems to fit into place with a clear role, which is a sign of a good design.

tangelo/linq/simulator.py Outdated Show resolved Hide resolved
tangelo/linq/simulator.py Outdated Show resolved Hide resolved
examples/linq/2.qpu_connection.ipynb Outdated Show resolved Hide resolved
tangelo/linq/simulator_base.py Outdated Show resolved Hide resolved
tangelo/toolboxes/post_processing/histogram.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@ValentinS4t1qbit ValentinS4t1qbit left a comment

Choose a reason for hiding this comment

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

Great job James, glad to see this now part of our code !

@ValentinS4t1qbit ValentinS4t1qbit merged commit 25d5a58 into sandbox-quantum:develop Oct 13, 2022
ValentinS4t1qbit added a commit that referenced this pull request Nov 9, 2022
* Formula for estimating n_measurements for exp value to given accuracy updated with simpler form. (#192)
* Fix operator_expectation bug qith qubit operator / hamiltonian. (#191)
* iqcc ilc solver fork (#179)
* Make circuit iterable (#194)
* copy method for circuits + get_resources adjusted for some variations of VQE + invertible swap gate fix (#193)
* Release guide for project maintainers + version string (#195)
* Notebook: Important aspects of QChem modelling for QComputing (#199)
* Notebooks enabled for Google colab ("No local install" needed) (#198)
* Docker fix (#200)
* Excited states (#197)
* Translation function for qubit operators (#196)
* c2v axis definition changed (#205)
* Bidirectional conversion for Qiskit quantum circuits (#203)
* QEMISTClientConnection class (#207)
* Add n_qubits option to MultiformOperator compress function (#209)
* Quantum Signal Processing time-evolution (#204)
* added even trotter order > 2 (#210)
* Fixed number of qubits with scBK in ADAPT. (#214)
* Export coverage output file in github actions (#158)
* JKMN vector prep should return np array of int. (#215)
* Support for additional IonQ gates (#212)
* Remove unused n_min_orbitals attribute. (#218)
* Change JKMN Majorana definition so mapped Hamiltonian is real (#219)
* Relaxing condition fot iQCC-ILC test. (#221)
* Histogram class (#217)
* Compute energy from RDMs with FermionOperator (#220)
* IonQConnection: control update prints / verbosity. (#225)
* Refactor simulator (#213)
* added __repr__ method to Gate (#229)
* New bidirectional circuit translation functions and interface (#223)
* Add circuit.depth() in get_resources methods (#235)
* Variance and standard error of an expectation value (#238)
* VQESolver cleanup (#230)
* TETRIS-ADAPT-VQE (#241)
* TETRISADAPTSolver implementation + #224 fix
* Trotter order and active electrons for (i)QCC (#234)
* Symmetry post-selection (#232)
* Qiskit runtime integration (IBM quantum only) (#222)
* Add multi-control support for trotterization (#244)
* Compatibility with new QCloud outputs. (#246)
* Deprecate Simulator, introduce get_backend as replacement (#245)
* compute_rdms function (#228)
* Expanded FermionOperator attributes, defined logical and mathematical operations on it (add, mul, eq, etc)
* Bumping Tangelo version number in _version.py
* Update CHANGELOG.md

Co-authored-by: Valentin Senicourt <41597680+ValentinS4t1qbit@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: AlexandreF-1qbit <76115575+AlexandreF-1qbit@users.noreply.github.com>
Co-authored-by: James Brown <james.brown@1qbit.com>
Co-authored-by: JamesB-1qbit <84878946+JamesB-1qbit@users.noreply.github.com>
Co-authored-by: MPCoons <84400409+MPCoons@users.noreply.github.com>
Co-authored-by: elloyd-1qbit <58313607+elloyd-1qbit@users.noreply.github.com>
Co-authored-by: KrzysztofB-1qbit <86750444+KrzysztofB-1qbit@users.noreply.github.com>
Co-authored-by: Rudi Plesch <rudi.plesch@1qbit.com>
Co-authored-by: GitHub Actions <noreply@github.com>
Co-authored-by: Valentin Senicourt <valentin.senicourt@1qbit.com>
Co-authored-by: Joshua Goings <3915169+jjgoings@users.noreply.github.com>
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.

3 participants