Skip to content

Commit

Permalink
Added support for SamplerV2 primitives (#49)
Browse files Browse the repository at this point in the history
* Migrating `qiskit_algorithms` (qiskit-community#817)

* Update README.md

* Generalize the Einstein summation signature

* Add reno

* Update Copyright

* Rename and add test

* Update Copyright

* Add docstring for `test_get_einsum_signature`

* Correct spelling

* Disable spellcheck for comments

* Add `docstring` in pylint dict

* Delete example in docstring

* Add Einstein in pylint dict

* Add full use case in einsum dict

* Spelling and type ignore

* Spelling and type ignore

* Spelling and type ignore

* Spelling and type ignore

* Spelling and type ignore

* Remove for loop in einsum function and remove Literal arguments (1/2)

* Remove for loop in einsum function and remove Literal arguments (1/2)

* Remove for loop in einsum function and remove Literal arguments (2/2)

* Update RuntimeError msg

* Update RuntimeError msg - line too long

* Trigger CI

* Merge algos, globals.random to fix

* Fixed `algorithms_globals`

* Import /tests and run CI locally

* Fix copyrights and some spellings

* Ignore mypy in 8 instances

* Merge spell dicts

* Black reformatting

* Black reformatting

* Add reno

* Lint sanitize

* Pylint

* Pylint

* Pylint

* Pylint

* Fix relative imports in tutorials

* Fix relative imports in tutorials

* Remove algorithms from Jupyter magic methods

* Temporarily disable "Run stable tutorials" tests

* Change the docstrings with imports from qiskit_algorithms

* Styling

* Update qiskit_machine_learning/optimizers/gradient_descent.py

Co-authored-by: Declan Millar <[email protected]>

* Update qiskit_machine_learning/optimizers/optimizer_utils/learning_rate.py

Co-authored-by: Declan Millar <[email protected]>

* Add more tests for utils

* Add more tests for optimizers: adam, bobyqa, gsls and imfil

* Fix random seed for volatile optimizers

* Fix random seed for volatile optimizers

* Add more tests

* Pylint dict

* Activate scikit-quant-0.8.2

* Remove scikit-quant methods

* Remove scikit-quant methods (2)

* Edit the release notes and Qiskit version 1+

* Edit the release notes and Qiskit version 1+

* Add Qiskit 1.0 upgrade in reno

* Add Qiskit 1.0 upgrade in reno

* Add Qiskit 1.0 upgrade in reno

* Apply line breaks

* Restructure line breaks

---------

Co-authored-by: FrancescaSchiav <[email protected]>
Co-authored-by: M. Emre Sahin <[email protected]>
Co-authored-by: Declan Millar <[email protected]>

* Revamp readme pt2 (qiskit-community#822)

* Restructure README.md
---------

Co-authored-by: Steve Wood <[email protected]>

* V2 Primitive Support for SamplerQNN and Gradients

* Update base_sampler_gradient.py

* Update qiskit_machine_learning/gradients/param_shift/param_shift_sampler_gradient.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Update qiskit_machine_learning/gradients/spsa/spsa_sampler_gradient.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Update qiskit_machine_learning/gradients/spsa/spsa_sampler_gradient.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Update qiskit_machine_learning/neural_networks/sampler_qnn.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Update qiskit_machine_learning/neural_networks/sampler_qnn.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Update qiskit_machine_learning/neural_networks/sampler_qnn.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Update qiskit_machine_learning/neural_networks/sampler_qnn.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Update qiskit_machine_learning/neural_networks/sampler_qnn.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Update qiskit_machine_learning/neural_networks/sampler_qnn.py

Co-authored-by: Edoardo Altamura <[email protected]>

* Fix lint errors due to Pylint 3.3.0 update in CI (qiskit-community#833)

* disable=too-many-positional-arguments

* Transfer pylint rc to toml

* Transfer pylint rc to toml

* Minor fixes

* Remove Python 3.8 from CI (qiskit-community#824) (qiskit-community#826)

* Remove Python 3.8 in CI (qiskit-community#824)

* Correct `tmp` dirs (qiskit-community#818)

* Correct unit py version (qiskit-community#818)

* Add reno (qiskit-community#818)

* Finalze removal of py38 (qiskit-community#818)

* Spelling

* Remove duplicate tmp folder

* Updated the release note

* Bump min pyversion in toml

* Remove ipython constraints

* Update reno

* Updated test for test_sampler_qnn

* Fix: output_shape

* Adding optimisation level to TestSamplerQNN SamplerV2 option

* Correcting the PUB prep for SamplerV2 by changing max iterator from n to len(job_param_values). Added a load of print statements to investigate behaviour when self._output_shape = (2, 3) - a tuple as this was failing tests due to a comparison in line 166. This has lead me to think that the way we are calculating QuasiDistribution is wrong as we need to know which real qubits the virtual qubits have been transpiled too to calculate the correct dist for SamplerV2. Following this up with IBM runtime.

* Update sampler_qnn.py for correcting tuple output_shape when interpret is provided.

* Adding ISA capabilities to gradients

* Fix output shape and its default for V2

* Implement SamplerV2 for bayesian inference

* Implement SamplerV2 for bayesian inference

* Adding ISA capabilities to SamplerQNN and ParamShiftSamplerGradient

* Removing unused backend

* Removing failed merge conflicts

* Removing residual merge conflicts

* added SamplerV2 support for ComputeUncompute

* Removing multiple tranpilations within same test

* Formatting

* Linting

* Adding measure_all to setUp

* removing default pm

---------

Co-authored-by: Edoardo Altamura <[email protected]>
Co-authored-by: FrancescaSchiav <[email protected]>
Co-authored-by: Declan Millar <[email protected]>
Co-authored-by: Steve Wood <[email protected]>
Co-authored-by: oscar-wallis <[email protected]>
  • Loading branch information
6 people authored Nov 7, 2024
1 parent 9e53371 commit 2bbb57c
Show file tree
Hide file tree
Showing 54 changed files with 1,150 additions and 634 deletions.
4 changes: 2 additions & 2 deletions .github/actions/run-tests/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2023.
# (C) Copyright IBM 2021, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -36,7 +36,7 @@ runs:
if [ "${{ inputs.event-name }}" == "schedule" ] || [ "${{ inputs.run-slow }}" == "true" ]; then
export QISKIT_TESTS="run_slow"
fi
if [ "${{ inputs.os }}" == "ubuntu-latest" ] && [ "${{ inputs.python-version }}" == "3.8" ]; then
if [ "${{ inputs.os }}" == "ubuntu-latest" ] && [ "${{ inputs.python-version }}" == "3.9" ]; then
export PYTHON="coverage3 run --source qiskit_machine_learning --parallel-mode"
fi
stestr --test-path test run 2> >(tee /dev/stderr out.txt > /dev/null)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-code.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2023.
# (C) Copyright IBM 2021, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -25,7 +25,7 @@ jobs:
id-token: write
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2023.
# (C) Copyright IBM 2021, 2024.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]
steps:
- uses: actions/checkout@v4
with:
Expand Down
34 changes: 15 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: [3.9]
steps:
- name: Print Concurrency Group
env:
Expand Down Expand Up @@ -112,14 +112,14 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8, 3.9, '3.10', 3.11, 3.12]
python-version: [3.9, '3.10', 3.11, 3.12]
include:
- os: macos-latest
python-version: 3.8
python-version: 3.9
- os: macos-latest
python-version: 3.12
- os: windows-latest
python-version: 3.8
python-version: 3.9
- os: windows-latest
python-version: 3.12
# macos-14 is an Arm64 image
Expand Down Expand Up @@ -165,7 +165,7 @@ jobs:
run: |
coverage3 combine
mv .coverage ./ci-artifact-data/ml.dat
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.8 }}
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9 }}
shell: bash
- uses: actions/upload-artifact@v4
with:
Expand All @@ -188,7 +188,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8, 3.12]
python-version: [3.9, 3.12]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -251,29 +251,25 @@ jobs:
# cd docs/_build/html
# mkdir artifacts
# tar -zcvf artifacts/tutorials.tar.gz --exclude=./artifacts .
# if: ${{ matrix.python-version == 3.8 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
# if: ${{ matrix.python-version == 3.9 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
# shell: bash
# - name: Run upload stable tutorials
# uses: actions/upload-artifact@v4
# with:
# name: tutorials-stable${{ matrix.python-version }}
# path: docs/_build/html/artifacts/tutorials.tar.gz
# if: ${{ matrix.python-version == 3.8 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
# if: ${{ matrix.python-version == 3.9 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
Deprecation_Messages_and_Coverage:
needs: [Checks, MachineLearning, Tutorials]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.9]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/download-artifact@v4
with:
name: ubuntu-latest-3.8
path: /tmp/u38
- uses: actions/download-artifact@v4
with:
name: ubuntu-latest-3.9
Expand All @@ -292,16 +288,16 @@ jobs:
path: /tmp/u312
- uses: actions/download-artifact@v4
with:
name: macos-latest-3.8
path: /tmp/m38
name: macos-latest-3.9
path: /tmp/m39
- uses: actions/download-artifact@v4
with:
name: macos-latest-3.12
path: /tmp/m312
- uses: actions/download-artifact@v4
with:
name: windows-latest-3.8
path: /tmp/w38
name: windows-latest-3.9
path: /tmp/w39
- uses: actions/download-artifact@v4
with:
name: windows-latest-3.12
Expand All @@ -319,10 +315,10 @@ jobs:
shell: bash
- name: Combined Deprecation Messages
run: |
sort -f -u /tmp/u38/ml.dep /tmp/u39/ml.dep /tmp/u310/ml.dep /tmp/u311/ml.dep /tmp/u312/ml.dep /tmp/m38/ml.dep /tmp/m312/ml.dep /tmp/w38/ml.dep /tmp/w312/ml.dep /tmp/a310/ml.dep /tmp/a312/ml.dep || true
sort -f -u /tmp/u39/ml.dep /tmp/u310/ml.dep /tmp/u311/ml.dep /tmp/u312/ml.dep /tmp/m39/ml.dep /tmp/m312/ml.dep /tmp/w39/ml.dep /tmp/w312/ml.dep /tmp/a310/ml.dep /tmp/a312/ml.dep || true
shell: bash
- name: Coverage combine
run: coverage3 combine /tmp/u38/ml.dat
run: coverage3 combine /tmp/u39/ml.dat
shell: bash
- name: Upload to Coveralls
env:
Expand Down
4 changes: 2 additions & 2 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
queue_rules:
- name: automerge
conditions:
- check-success=Deprecation_Messages_and_Coverage (3.8)
- check-success=Deprecation_Messages_and_Coverage (3.9)

pull_request_rules:
- name: automatic merge on CI success and review
conditions:
- check-success=Deprecation_Messages_and_Coverage (3.8)
- check-success=Deprecation_Messages_and_Coverage (3.9)
- "#approved-reviews-by>=1"
- label=automerge
- label!=on hold
Expand Down
16 changes: 12 additions & 4 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ armijo
arxiv
asmatrix
aspuru
assertraises
async
autoencoder
autoencoders
Expand Down Expand Up @@ -136,6 +137,7 @@ elif
endian
entangler
enum
eol
eps
estimatorqnn
et
Expand All @@ -158,6 +160,7 @@ farhi
farrokh
fi
fidelities
fidelity
fidelityquantumkernel
filippo
fletcher
Expand Down Expand Up @@ -201,13 +204,15 @@ hadfield
hamiltonian
hamiltonians
hao
hartree
hashable
hatano
havlíček
heidelberg
hessians
hilbert
hoc
homebrew
hopkins
hoyer
html
Expand Down Expand Up @@ -259,6 +264,7 @@ kwargs
labelled
lagrange
langle
linux
larrañaga
lcu
len
Expand Down Expand Up @@ -347,6 +353,7 @@ o'brien
objval
observables
oct
october
olson
onboarding
onodera
Expand Down Expand Up @@ -452,10 +459,12 @@ rhs
rightarrow
robert
romero
rosenbrock
rosen
runarsson
runtime
runtimes
RuntimeError
rx
ry
rz
Expand Down Expand Up @@ -495,6 +504,9 @@ sqrt
statefn
statevector
statevectors
stdlib
stdout
stfc
stddev
stdlib
stdout
Expand Down Expand Up @@ -594,7 +606,3 @@ zz
θ
ψ
ω
assertRaises
RuntimeError
Rosenbrock
fidelities
Loading

0 comments on commit 2bbb57c

Please sign in to comment.