Giter Site home page Giter Site logo

oxfordiontrapgroup / oitg Goto Github PK

View Code? Open in Web Editor NEW
13.0 11.0 8.0 6.48 MB

Python package of helper routines (result loading, fitting, etc) for the Oxford Ion-Trap Group (OITG).

Home Page: https://oxfordiontrapgroup.github.io/oitg/

Python 100.00%
python artiq quantum-computing ion-trap

oitg's Introduction

Oxford Ion-Trap Group routines

Contains common routines and convenience functions used in the Oxford Ion Trap Quantum Computing group.

  • ARTIQ result file loading
  • Fitting routines
  • Generation of qubit circuits for a variety of protocols, and analysis/visualisation of the results

To view the API documentation, run

$ cd docs/
$ make html

and open docs/_build/html/index.html in a web browser. (Builds of the most recent main repository master branch commit are also available online at https://oxfordiontrapgroup.github.io/oitg/.)

oitg's People

Contributors

cjbe avatar dnadlinger avatar dougalmain24 avatar ljstephenson avatar pathfinder49 avatar pmldrmota avatar tballance avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oitg's Issues

Global Fit Optimisation Routine

We may want a routine for global fit optimisation of binomial (or other) distributed data.

This should give the global optimum parameter estimates and their covariances. Ideally, it should be capable of producing a plot of P(parameters|data).

Broken out from this issue

Line fitting fails for two data points

The following code fails

from oitg.fitting import line
line.fit([0,1],[0,1])

with error

Traceback (most recent call last):
  File "C:\Users\LocalAdmin\Miniconda3\envs\artiq-env\lib\site-packages\oitg-0.1-py3.9.egg\oitg\fitting\FitBase.py", line 249, in fit
  File "C:\Users\LocalAdmin\Miniconda3\envs\artiq-env\lib\site-packages\scipy\optimize\minpack.py", line 795, in curve_fit
    res = least_squares(func, p0, jac=jac, bounds=bounds, method=method,
  File "C:\Users\LocalAdmin\Miniconda3\envs\artiq-env\lib\site-packages\scipy\optimize\_lsq\least_squares.py", line 805, in least_squares
    raise ValueError("`x0` is infeasible.")
ValueError: `x0` is infeasible.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "y:/testing/scratch_mfg/line_fit.py", line 2, in <module>
    line.fit([0,1],[0,1])
  File "C:\Users\LocalAdmin\Miniconda3\envs\artiq-env\lib\site-packages\oitg-0.1-py3.9.egg\oitg\fitting\FitBase.py", line 255, in fit
oitg.fitting.FitBase.FitError: `x0` is infeasible.

One obvious thing that would fail is the parameter_initialiser in line.py

def parameter_initialiser(x, y, p):
k = (y[-1] - y[1]) / (x[-1] - x[1])
p['a'] = y[1] - x[1] * k
p['b'] = k

which would give division by 0 errors for a size two array.

v_function: improve heuristics

The heuristics for v_function are currently not great.

Thoughts

  • API: currently the v function is described by positive and negative gradients. IMHO that's non-ideal since there isn't an easy way to constrain the fit to be symmetric. Might be better to do something like a gradient and an asymmetry factor (which can usually default to 1)
  • putting x0 as mean(x) only works if the v function is decently well centred. I've found this to be pretty fragile
  • similarly, putting the offset as the mean of y doesn't work that well in my experience
  • maybe a better way is to first figure out which way up the v function is (maybe add a sign parameter so users can specify this, and then enforce that the other gradients are strictly positive). once we know that we can easily generate good guesses for the other parameters
  • maybe one way of guessing which way up it is is to find the min/max points, then look at the max/max on either side of them. e.g. on a downwards v function, should have higher points on either side of the minimum. This doesn't work if the minimum is off the end of the dataset in one direction, but I don't see an obviously better way (other than just try fitting for both signs and see which gives lower residuals).

I'd be interested in input on better ideas if people have them?

FitBase: expose **kwargs of curve_fit

Fitting with parameter values far from unity can be improved by passing characteristic parameter scales to curve_fit using the optional the x_scale keyword argument.
This argument is documneted under scipy.optimize.least_squares. curve_fit calls this function internally. **kwargs to curve_fit are passed to scipy.optimize.least_squares.

upstream the results code

Looks clean, generic, and mature. Is ARTIQ-specific but experiment-agnostic.
Any chance to get a PR for it?

(maybe without artiq_results_path())

Robust sinc^2-like frequency scan fit for arbitrary pulse areas

It would be nice to have a robust way of fitting the spectra from scanning over a two-level-like transition with constant pulse area (i.e. sinc^2-like if area is exactly ฯ€).

I expect this to be a bit flaky if both pulse area and upper/lower levels are floated, but the user could always constrain these for better convergence.

Fitting with no parameter bounds raises exception

Fits with no bounds call scipy leastsq instead of scipy least_squares. See curve_fit documentation

kwargs

Keyword arguments passed to leastsq for method='lm' or least_squares otherwise.

this case raises FitError: leastsq() got an unexpected keyword argument 'x_scale'

Proposed solution: set the method to always use scipy least_squares

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.