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

Add circuit-runner, sampler and custom VQE programs from Qiskit-Runtime #157

Merged
merged 108 commits into from
Jan 29, 2022

Conversation

rmoyard
Copy link
Contributor

@rmoyard rmoyard commented Nov 10, 2021

Add a new device that will run on the Qiskit-runtime program circuit_runner, where we can specify a specific IBMQ backend.

  1. Circuit Runner
IBMQ.enable_account(token)
dev = IBMQCircuitRunnerDevice(wires=2, backend="ibmq_qasm_simulator", shots=shots)

@qml.qnode(dev)
def circuit(theta, phi):
    qml.RX(theta, wires=0)
    qml.RX(phi, wires=1)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))

theta = 0.432
phi = 0.123

res = circuit(theta, phi)
  1. Sampler
IBMQ.enable_account(token)
dev = IBMQSamplerDevice(wires=2, backend="ibmq_qasm_simulator", shots=shots)

@qml.qnode(dev)
def circuit(theta, phi):
    qml.RX(theta, wires=0)
    qml.RX(phi, wires=1)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))

theta = 0.432
phi = 0.123

res = circuit(theta, phi)
  1. Custom VQE
    Upload the program once and get the id.
IBMQ.enable_account(token)

program_id = upload_vqe_runner(hub="ibm-q", group="open", project="main")

Use the id to run the program for a PennyLane Hamiltonian and ansatz circuit.

def vqe_circuit(params):
    qml.RX(params[0], wires=0)
    qml.RY(params[1], wires=0)

coeffs = [1, 1]
obs = [qml.PauliX(0), qml.PauliZ(0)]
hamiltonian = qml.Hamiltonian(coeffs, obs)

job = vqe_runner(
    program_id=program_id,
    backend="ibmq_qasm_simulator",
    hamiltonian=hamiltonian,
    ansatz=vqe_circuit,
    x0=[3.97507603, 3.00854038],
    shots=shots,
    optimizer="SPSA",
    optimizer_config={"maxiter": 40},
    kwargs={"hub": "ibm-q", "group": "open", "project": "main"},
)

@rmoyard rmoyard added the WIP label Nov 10, 2021
@rmoyard rmoyard changed the title Add circuit-runner program from Qiskit-Runtime [WIP] Add circuit-runner program from Qiskit-Runtime Nov 10, 2021
@codecov
Copy link

codecov bot commented Nov 10, 2021

Codecov Report

Merging #157 (81afdde) into master (acd6c0e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #157   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         6    -1     
  Lines          305       291   -14     
=========================================
- Hits           305       291   -14     
Impacted Files Coverage Δ
pennylane_qiskit/__init__.py 100.00% <100.00%> (ø)
pennylane_qiskit/qiskit_device.py 100.00% <100.00%> (ø)
pennylane_qiskit/ibmq.py

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30be008...81afdde. Read the comment docs.

@antalszava
Copy link
Contributor

[sc-9609]

@rmoyard rmoyard changed the title [WIP] Add circuit-runner program from Qiskit-Runtime [WIP] Add circuit-runner, sampler and VQE programs from Qiskit-Runtime Nov 22, 2021
doc/devices/runtime.rst Outdated Show resolved Hide resolved
doc/devices/runtime.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@KetpuntoG KetpuntoG left a comment

Choose a reason for hiding this comment

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

Perfect!

Co-authored-by: antalszava <antalszava@gmail.com>
Copy link
Contributor

@antalszava antalszava left a comment

Choose a reason for hiding this comment

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

Looks good to me! ⭐ 🥇 Amazing effort here @rmoyard, thanks for hanging in there with the review and for pushing this through. Great addition!

@antalszava
Copy link
Contributor

Note: the tests using IBMQ and Qiskit Runtime have been skipped and their coverage has been omitted as we've experienced many timeouts when running them.

@rmoyard rmoyard merged commit 66e2185 into master Jan 29, 2022
@rmoyard rmoyard deleted the runtime branch January 29, 2022 00:28
rmoyard added a commit that referenced this pull request Feb 14, 2022
…me (#157)

* Small change.

* First commit

* Working circuit runner.

* Sampler

* Sampler

* VQE is working.

* Headers.

* Update for batches.

* Update docstrigs.

* CodeFactor.

* Add tests for runtime.

* Tests.

* Test.

* Test circuit runner.

* Test Sampler.

* Correct generate_samples

* Add entry points.

* More shots.

* Add token arg.

* Change import

* Change Sampler sample.

* Circuit runner kwargs test.

* Shots kwargs

* Change import.

* Add kwargs Sampler test.

* Import.

* Impport again.

* Import change

* Add test tracker.

* Update track tests.

* Update tracker runtime.

* Update tracker.

* Update.

* Codfactor changes.

* Update.

* Update codefactor

* More codefactor.

* Add callback

* Update

* Move vqe

* Update.

* Add test VQE.

* Update.

* delete

* Update VQE test.

* Add shots.

* Update test

* Update delete

* Unused import.

* More iteration.

* m

* Change tol.

* More VQE tests.

* Black

* Update.

* Update.

* Update

* Update pennylane_qiskit/vqe/__init__.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update from review.

* Update tests.

* Typo.

* Update from tests.

* Runtime updated.

* Runtime updated.

* Update vqe

* Update

* Update from Antal review.

* Update

* Black.

* More test.

* Update parameters

* Codefactor update.

* Update.

* Update.

* Change order jac.

* Typo.

* Params.

* Update tests.

* ValueError.

* print

* Update.

* Tol.

* Update review.

* Add doc.

* Unused variable.

* Update tests.

* Update params.

* Update review.

* Readd mthree

* Typo.

* Path.

* Black

* Change path.

* Update runtime_programs/vqe_runtime_program.py

* Update doc/devices/runtime.rst

Co-authored-by: antalszava <antalszava@gmail.com>

* Update review.

* coverarc

* coverarc omit + skip IBMQ and Runtime tests

* Changelog

Co-authored-by: antalszava <antalszava@gmail.com>
antalszava added a commit that referenced this pull request Feb 15, 2022
* Small change.

* Update header.html

* Add native support for the SX gate (#158)

* Add SX support

* changelog

* SX inverse tests

* Define the `QiskitDevice.batch_execute` method (#156)

* first draft

* license

* apply; compile in the method

* statevector & batch generate samples

* docstrings

* tests

* batch_params check & check call count for batch_execute

* IBMQ check

* docstrings

* batch execution pipeline test for gradient computation

* IBMQ grad test

* state

* no single tape case; re-add basis state prep to the test

* name and docstring

* renames

* comment

* docstrings, names

* remove unnecessary reset

* Update pennylane_qiskit/qiskit_device.py

Co-authored-by: Romain <rmoyard@gmail.com>

* Update pennylane_qiskit/qiskit_device.py

Co-authored-by: Romain <rmoyard@gmail.com>

Co-authored-by: Romain <rmoyard@gmail.com>

* Update the batch execution tests to use the new QNode (#159)

* batch execute call counter

* get PennyLane master

* comment

* flaky

* Update test_expval.py

* more flaky

Co-authored-by: Romain <rmoyard@gmail.com>

* Change token for IBMQ tests (#161)

* Small change.

* Change token.

* Add env.

* Not device test.

* Batch execute twice

* Add job_time (#160)

* commit

* black

* test

* checking coverage

* reset test

* qasm_simulator

* test

* test

* change

* update

* record

* Romain changes

* Update ibmq.py

* final change

* Update test_ibmq.py

* Update CHANGELOG.md

Co-authored-by: Romain <rmoyard@gmail.com>

* Add the `qml.Identity` operation to PennyLane-Qiskit (#162)

* Add the qml.Identity gate to the Qiskit plugin

* Add Identity to converter test

* Fix pylint:f-string in qiskit_device.py

* Changelog & additional test

* Update CHANGELOG.md

Co-authored-by: Romain <rmoyard@gmail.com>

* Fix `batch_execute` output type for QNodes with multiple outputs (#163)

* asarray

* check type

* changelog

* Update the tracker used with batch execution (#167)

* tracker test

* changelog

* Update tests/test_integration.py

Co-authored-by: Romain <rmoyard@gmail.com>

Co-authored-by: Romain <rmoyard@gmail.com>

* Update header.html

* Python 3.10 (#170)

* changelog & tests

* changelog

* Version bump (#168)

* Version bump
s Please enter the commit message for your changes. Lines starting

* add pl version

Co-authored-by: Josh Izaac <josh146@gmail.com>

* v0.21.0-dev version bump (#172)

* inc version

* add flaky

* Improve token-specified login flow. (#169)

* Test that we can create multiple IBMQ devices using an environment token.

* Improve token-specified login flow.

* Fix formatting.

* extend skipping logic

* Test token login elision.

* Temporarily restrict code coverage analysis.

* Update changelog.

* Fix formatting.

* more no cover for the IBMQ device

* Update tests/test_ibmq.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update tests/test_ibmq.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update test_ibmq.py

Co-authored-by: Antal Szava <antalszava@gmail.com>

* Change IBMQ login (#175)

* Small change.

* Change test.

* Test.

* Update.

* Change tests.

* Fix bugs for the trainable arguments update (#177)

* Small change.

* Tests

* Exchange.

* Update.

* Update.

* Add circuit-runner, sampler and custom VQE programs from Qiskit-Runtime (#157)

* Small change.

* First commit

* Working circuit runner.

* Sampler

* Sampler

* VQE is working.

* Headers.

* Update for batches.

* Update docstrigs.

* CodeFactor.

* Add tests for runtime.

* Tests.

* Test.

* Test circuit runner.

* Test Sampler.

* Correct generate_samples

* Add entry points.

* More shots.

* Add token arg.

* Change import

* Change Sampler sample.

* Circuit runner kwargs test.

* Shots kwargs

* Change import.

* Add kwargs Sampler test.

* Import.

* Impport again.

* Import change

* Add test tracker.

* Update track tests.

* Update tracker runtime.

* Update tracker.

* Update.

* Codfactor changes.

* Update.

* Update codefactor

* More codefactor.

* Add callback

* Update

* Move vqe

* Update.

* Add test VQE.

* Update.

* delete

* Update VQE test.

* Add shots.

* Update test

* Update delete

* Unused import.

* More iteration.

* m

* Change tol.

* More VQE tests.

* Black

* Update.

* Update.

* Update

* Update pennylane_qiskit/vqe/__init__.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update from review.

* Update tests.

* Typo.

* Update from tests.

* Runtime updated.

* Runtime updated.

* Update vqe

* Update

* Update from Antal review.

* Update

* Black.

* More test.

* Update parameters

* Codefactor update.

* Update.

* Update.

* Change order jac.

* Typo.

* Params.

* Update tests.

* ValueError.

* print

* Update.

* Tol.

* Update review.

* Add doc.

* Unused variable.

* Update tests.

* Update params.

* Update review.

* Readd mthree

* Typo.

* Path.

* Black

* Change path.

* Update runtime_programs/vqe_runtime_program.py

* Update doc/devices/runtime.rst

Co-authored-by: antalszava <antalszava@gmail.com>

* Update review.

* coverarc

* coverarc omit + skip IBMQ and Runtime tests

* Changelog

Co-authored-by: antalszava <antalszava@gmail.com>

* Add and change some docstrings for a better quality (#174)

* Small change.

* First check.

* Typo.

* Add link.

* Change.

* Change.

* Update pennylane_qiskit/qiskit_device.py

* Update from review.

* Typo

* Update docstring transpiler.

* Update.

Co-authored-by: antalszava <antalszava@gmail.com>

* Changes.

* Review

* Review

* Wrong changelog number

Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
Co-authored-by: Tanner Rogalsky <tanner@tannerrogalsky.com>
antalszava added a commit that referenced this pull request Feb 15, 2022
* changelog and bump version

* Change callback function for Sicpy intermediate results (#187)

* Small change.

* Update header.html

* Add native support for the SX gate (#158)

* Add SX support

* changelog

* SX inverse tests

* Define the `QiskitDevice.batch_execute` method (#156)

* first draft

* license

* apply; compile in the method

* statevector & batch generate samples

* docstrings

* tests

* batch_params check & check call count for batch_execute

* IBMQ check

* docstrings

* batch execution pipeline test for gradient computation

* IBMQ grad test

* state

* no single tape case; re-add basis state prep to the test

* name and docstring

* renames

* comment

* docstrings, names

* remove unnecessary reset

* Update pennylane_qiskit/qiskit_device.py

Co-authored-by: Romain <rmoyard@gmail.com>

* Update pennylane_qiskit/qiskit_device.py

Co-authored-by: Romain <rmoyard@gmail.com>

Co-authored-by: Romain <rmoyard@gmail.com>

* Update the batch execution tests to use the new QNode (#159)

* batch execute call counter

* get PennyLane master

* comment

* flaky

* Update test_expval.py

* more flaky

Co-authored-by: Romain <rmoyard@gmail.com>

* Change token for IBMQ tests (#161)

* Small change.

* Change token.

* Add env.

* Not device test.

* Batch execute twice

* Add job_time (#160)

* commit

* black

* test

* checking coverage

* reset test

* qasm_simulator

* test

* test

* change

* update

* record

* Romain changes

* Update ibmq.py

* final change

* Update test_ibmq.py

* Update CHANGELOG.md

Co-authored-by: Romain <rmoyard@gmail.com>

* Add the `qml.Identity` operation to PennyLane-Qiskit (#162)

* Add the qml.Identity gate to the Qiskit plugin

* Add Identity to converter test

* Fix pylint:f-string in qiskit_device.py

* Changelog & additional test

* Update CHANGELOG.md

Co-authored-by: Romain <rmoyard@gmail.com>

* Fix `batch_execute` output type for QNodes with multiple outputs (#163)

* asarray

* check type

* changelog

* Update the tracker used with batch execution (#167)

* tracker test

* changelog

* Update tests/test_integration.py

Co-authored-by: Romain <rmoyard@gmail.com>

Co-authored-by: Romain <rmoyard@gmail.com>

* Update header.html

* Python 3.10 (#170)

* changelog & tests

* changelog

* Version bump (#168)

* Version bump
s Please enter the commit message for your changes. Lines starting

* add pl version

Co-authored-by: Josh Izaac <josh146@gmail.com>

* v0.21.0-dev version bump (#172)

* inc version

* add flaky

* Improve token-specified login flow. (#169)

* Test that we can create multiple IBMQ devices using an environment token.

* Improve token-specified login flow.

* Fix formatting.

* extend skipping logic

* Test token login elision.

* Temporarily restrict code coverage analysis.

* Update changelog.

* Fix formatting.

* more no cover for the IBMQ device

* Update tests/test_ibmq.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update tests/test_ibmq.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update test_ibmq.py

Co-authored-by: Antal Szava <antalszava@gmail.com>

* Change IBMQ login (#175)

* Small change.

* Change test.

* Test.

* Update.

* Change tests.

* Fix bugs for the trainable arguments update (#177)

* Small change.

* Tests

* Exchange.

* Update.

* Update.

* Add circuit-runner, sampler and custom VQE programs from Qiskit-Runtime (#157)

* Small change.

* First commit

* Working circuit runner.

* Sampler

* Sampler

* VQE is working.

* Headers.

* Update for batches.

* Update docstrigs.

* CodeFactor.

* Add tests for runtime.

* Tests.

* Test.

* Test circuit runner.

* Test Sampler.

* Correct generate_samples

* Add entry points.

* More shots.

* Add token arg.

* Change import

* Change Sampler sample.

* Circuit runner kwargs test.

* Shots kwargs

* Change import.

* Add kwargs Sampler test.

* Import.

* Impport again.

* Import change

* Add test tracker.

* Update track tests.

* Update tracker runtime.

* Update tracker.

* Update.

* Codfactor changes.

* Update.

* Update codefactor

* More codefactor.

* Add callback

* Update

* Move vqe

* Update.

* Add test VQE.

* Update.

* delete

* Update VQE test.

* Add shots.

* Update test

* Update delete

* Unused import.

* More iteration.

* m

* Change tol.

* More VQE tests.

* Black

* Update.

* Update.

* Update

* Update pennylane_qiskit/vqe/__init__.py

Co-authored-by: antalszava <antalszava@gmail.com>

* Update from review.

* Update tests.

* Typo.

* Update from tests.

* Runtime updated.

* Runtime updated.

* Update vqe

* Update

* Update from Antal review.

* Update

* Black.

* More test.

* Update parameters

* Codefactor update.

* Update.

* Update.

* Change order jac.

* Typo.

* Params.

* Update tests.

* ValueError.

* print

* Update.

* Tol.

* Update review.

* Add doc.

* Unused variable.

* Update tests.

* Update params.

* Update review.

* Readd mthree

* Typo.

* Path.

* Black

* Change path.

* Update runtime_programs/vqe_runtime_program.py

* Update doc/devices/runtime.rst

Co-authored-by: antalszava <antalszava@gmail.com>

* Update review.

* coverarc

* coverarc omit + skip IBMQ and Runtime tests

* Changelog

Co-authored-by: antalszava <antalszava@gmail.com>

* Add and change some docstrings for a better quality (#174)

* Small change.

* First check.

* Typo.

* Add link.

* Change.

* Change.

* Update pennylane_qiskit/qiskit_device.py

* Update from review.

* Typo

* Update docstring transpiler.

* Update.

Co-authored-by: antalszava <antalszava@gmail.com>

* Changes.

* Review

* Review

* Wrong changelog number

Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
Co-authored-by: Tanner Rogalsky <tanner@tannerrogalsky.com>

* Update CHANGELOG.md

Co-authored-by: Romain <rmoyard@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Guillermo Alonso-Linaje <65235481+KetpuntoG@users.noreply.github.com>
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
Co-authored-by: Jay Soni <jbsoni@uwaterloo.ca>
Co-authored-by: Tanner Rogalsky <tanner@tannerrogalsky.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants