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

Added setup.py and modification for live info during retrieval #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine toml
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ scripts/results/

Thumbs.db

.idea

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include README.md
include LICENSE
include pypret/VERSION

1 change: 1 addition & 0 deletions pypret/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
4 changes: 2 additions & 2 deletions pypret/retrieval/nlo_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _scalar_objective(self, x):
R = self._Rr(r)
# printing and logging
if rs.nfev % 100 == 0 and self.verbose:
print(rs.nfev, R)
self.print(rs.nfev, R)
if self.logging:
log.trace_error.append(R)
rs.nfev += 1
Expand All @@ -37,7 +37,7 @@ def _vector_objective(self, x):
R = self._Rr(np.sum(diff * diff))
# printing and logging
if rs.nfev % 100 == 0 and self.verbose:
print(rs.nfev, R)
self.print(rs.nfev, R)
if self.logging:
log.trace_error.append(R)
rs.nfev += 1
Expand Down
27 changes: 21 additions & 6 deletions pypret/retrieval/retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ def __init__(self, pnps, logging=False, verbose=False, **kwargs):
self.log = None
rs = self._retrieval_state = SimpleNamespace()
rs.running = False
if 'status_sig' in kwargs:
self.print = kwargs['status_sig'].emit
else:
self.print = print

if 'callback' in kwargs:
self.callback = kwargs['callback']
else:
self.callback = None

if 'step_command' in kwargs:
self.step_command = kwargs['step_command']
else:
self.step_command = None

if (self.supported_schemes is not None and
pnps.scheme not in self.supported_schemes):
raise ValueError("Retriever '%s' does not support scheme '%s'. "
Expand Down Expand Up @@ -139,12 +154,12 @@ def _retrieve_begin(self, measurement, initial_guess, weights):
else:
self.log = None
if self.verbose:
print("Started retriever '%s'" % self.method)
print("Options:")
print(self.options)
print("Initial trace error R = {:.10e}".format(res.trace_error))
print("Starting retrieval...")
print()
self.print("Started retriever '%s'" % self.method)
self.print("Options:")
self.print(str(self.options))
self.print("Initial trace error R = {:.10e}".format(res.trace_error))
self.print("Starting retrieval...")
self.print("")

def _retrieve_end(self):
rs = self._retrieval_state
Expand Down
16 changes: 10 additions & 6 deletions pypret/retrieval/step_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def _retrieve(self):
# accept the new spectrum
spectrum[:] = new_spectrum
if self.verbose:
if self.callback is not None:
self.callback([rs.mu * rs.Tmn - self.Tmn_meas, self.parameter, self.pnps.process_w, new_spectrum])
if i == 0:
print("iteration".ljust(10) + "trace error".ljust(20))
self.print("iteration".ljust(10) + "trace error".ljust(20))
s = "{:d}".format(i + 1).ljust(10)
if rs.approximate_error:
s += "~"
Expand All @@ -50,14 +52,16 @@ def _retrieve(self):
s += "{:.10e}".format(R)
if R == res.trace_error:
s += "*"
print(s)
self.print(s)
if not rs.running:
break
if self.step_command is not None:
self.step_command()
if self.verbose:
print()
print("~ approximate trace error")
print("* accepted as best trace error")
print()
self.print("")
self.print("~ approximate trace error")
self.print("* accepted as best trace error")
self.print("")

# return the retrieved spectrum
# for a more detailed analysis call self.result()
Expand Down
39 changes: 39 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[metadata]
name = pypret_pymodaq
version = file: pypret/VERSION
description = fork of Python for Pulse Retrieval for PyMoDAQ
long_description = This project aims to provide numerical algorithms for ultrashort laser pulse measurement methods
license = MIT
licence_file = LICENSE
url = https://github.com/PyMoDAQ/pypret_pymodaq
author = S. J. Weber
author_email = [email protected]
classifiers =
Programming Language :: Python :: 3
Development Status :: 5 - Production/Stable
Environment :: Other Environment
Intended Audience :: Science/Research
Topic :: Scientific/Engineering :: Human Machine Interfaces
Topic :: Scientific/Engineering :: Visualization
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Software Development :: User Interfaces

[options]
py_module = pypret
python_requires = >=3.6, <3.9
install_requires=
h5py
loky
scipy

package_dir =
=.
packages = find:
include_package_data = True

[options.packages.find]
where = .


2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from setuptools import setup
setup()