Skip to main content

Implementation of Guided-SPSA

Project description

Guide-SPSA Gradients

Static Badge Static Badge

This repository implements the Guided-SPSA gradients introduced in "Guided-SPSA: Simultaneous Perturbation Stochastic Approximation assisted by the Parameter Shift Rule by M. Periyasamy et. al."

Features

  • Integration: Easily integrate with Qiskit and Tensorflow-Quantum APIs. The code inherits the respective differentiators provided by the APIs. Hence, one can use this implementation in any standard machine learning work that deals with gradient estimation via "expectation values" in Qiskit or TensorFlow-Quanutm.

Setup and Installation

The library requires an installation of python > 3.9 , and following libraries:

  • Qiskit version
    • qiskit
    • qiskit-algorithms
  • Tensorflow-Quantum version
    • tensorflow
    • tesnroflow-quantum

The package can be installed via pip:

  • package without other dependencies

    pip install gspsa-gradients
    
  • To install the with qiskit dependency:

    pip install gspsa-gradients[qiskit]
    
  • To install the with tfq dependency:

    pip install gspsa-gradients[tfq]
    
  • The package gspsa-gradients can be installed locally via:

    git clone https://github.com/maniraman-periyasamy/gspsa-gradients.git
    cd gspsa-gradients
    pip install -e .
    

Usage and Examples

Usage

  • Qiskit version
    from gspsa_gradients.qiskit_gradient import GSPSAEstimatorGradient
    from qiskit.primitives import Estimator
    gradient = GSPSAEstimatorGradient(total_steps = num_epochs, estimator=Estimator(), num_observables = len(observables), 
        tau=0.5, spsa_epsilon=0.01, damping_coeff=0.5)
    qnn1 = EstimatorQNN(
        circuit=qc, input_params=inputParams, weight_params=circuitParams, observables=observables, gradient=gradient, input_gradients=False)
    
    ...
    
  • TFQ verison
    from gspsa_gradients.tfq_gradient import GSPSAGradient
    diff=GSPSAGradient(total_steps=num_epochs, input_dims=num_inputs, tau=0.5, spsa_epsilon=0.01, damping_coeff=0.5)
    quantum_layer = tfq.layers.ControlledPQC(circuit, observables, differentiator=diff, repetitions=1024) # make repitions to 0 for exact expectation value estimation 
    
    ...
    

Example

Qml examples are provided in the examples folder

Acknowledgements

We use qiskit software framework: https://github.com/Qiskit and tensorflow-quantumsoftware framework: https://github.com/tensorflow/quantum

Citation

If you use the gspsa-gradients or results from the paper, please cite our work as

@misc{periyasamy2024guidedspsa,
      title={Guided-SPSA: Simultaneous Perturbation Stochastic Approximation assisted by the Parameter Shift Rule}, 
      author={Maniraman Periyasamy and Axel Plinge and Christopher Mutschler and Daniel D. Scherer and Wolfgang Mauerer},
      year={2024},
      eprint={2404.15751},
      archivePrefix={arXiv},
      primaryClass={quant-ph}
}

Version History

Initial release (v0.1.0): May 2024

License

Apache 2.0 License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gspsa_gradients-0.0.4.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gspsa_gradients-0.0.4-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file gspsa_gradients-0.0.4.tar.gz.

File metadata

  • Download URL: gspsa_gradients-0.0.4.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for gspsa_gradients-0.0.4.tar.gz
Algorithm Hash digest
SHA256 55e145939a5fb4153d71a4cf8f5a24f7d027473b410e1f70e49e1d45a8f2c513
MD5 6f6130b038fb337c33522a043ca7172d
BLAKE2b-256 3a7f97eca64c3d1b63842e861591c90332fd70f49ce34f1de4461f86940289f5

See more details on using hashes here.

File details

Details for the file gspsa_gradients-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for gspsa_gradients-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ee67c218afdf4657d90529184e092f2d3e7b391f8f02b189b661ff7b3eba19f2
MD5 e60c0dbd409f46d79c34ac16de0b6709
BLAKE2b-256 64e301056cb7784b68fe90d2f9462aa7b493c4eb6c5b0c16d8d865d47e0ae093

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page