Skip to content

Commit

Permalink
fix import order and style
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed May 7, 2019
1 parent 68500f1 commit 176c745
Show file tree
Hide file tree
Showing 30 changed files with 91 additions and 99 deletions.
23 changes: 8 additions & 15 deletions adaptive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@

from contextlib import suppress

from adaptive.notebook_integration import (notebook_extension, live_plot,
active_plotting_tasks)

from adaptive import learner
from adaptive import runner
from adaptive import utils

from adaptive.learner import (
BaseLearner, Learner1D, Learner2D, LearnerND,
AverageLearner, BalancingLearner, make_datasaver,
DataSaver, IntegratorLearner
)
from adaptive import learner, runner, utils
from adaptive._version import __version__
from adaptive.learner import (AverageLearner, BalancingLearner, BaseLearner,
DataSaver, IntegratorLearner, Learner1D,
Learner2D, LearnerND, make_datasaver)
from adaptive.notebook_integration import (active_plotting_tasks, live_plot,
notebook_extension)
from adaptive.runner import AsyncRunner, BlockingRunner, Runner

with suppress(ImportError):
# Only available if 'scikit-optimize' is installed
from adaptive.learner import SKOptLearner

from adaptive.runner import Runner, AsyncRunner, BlockingRunner

from adaptive._version import __version__
del _version

del notebook_integration # to avoid confusion with `notebook_extension`
12 changes: 6 additions & 6 deletions adaptive/_version.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# This file is part of 'miniver': https://github.com/jbweston/miniver
#
from collections import namedtuple
import os
import subprocess

from collections import namedtuple
from distutils.command.build_py import build_py as build_py_orig

from setuptools.command.sdist import sdist as sdist_orig

Version = namedtuple('Version', ('release', 'dev', 'labels'))
Expand Down Expand Up @@ -53,7 +53,7 @@ def pep440_format(version_info):
if release.endswith('-dev') or release.endswith('.dev'):
version_parts.append(dev)
else: # prefer PEP440 over strict adhesion to semver
version_parts.append('.dev{}'.format(dev))
version_parts.append(f'.dev{dev}')

if labels:
version_parts.append('+')
Expand Down Expand Up @@ -146,13 +146,13 @@ def get_version_from_git_archive(version_info):
return None

VTAG = 'tag: v'
refs = set(r.strip() for r in refnames.split(","))
version_tags = set(r[len(VTAG):] for r in refs if r.startswith(VTAG))
refs = {r.strip() for r in refnames.split(",")}
version_tags = {r[len(VTAG):] for r in refs if r.startswith(VTAG)}
if version_tags:
release, *_ = sorted(version_tags) # prefer e.g. "2.0" over "2.0rc1"
return Version(release, dev=None, labels=None)
else:
return Version('unknown', dev=None, labels=['g{}'.format(git_hash)])
return Version('unknown', dev=None, labels=[f'g{git_hash}'])


__version__ = get_version()
Expand Down
6 changes: 3 additions & 3 deletions adaptive/learner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from contextlib import suppress

from adaptive.learner.average_learner import AverageLearner
from adaptive.learner.base_learner import BaseLearner
from adaptive.learner.balancing_learner import BalancingLearner
from adaptive.learner.base_learner import BaseLearner
from adaptive.learner.data_saver import DataSaver, make_datasaver
from adaptive.learner.integrator_learner import IntegratorLearner
from adaptive.learner.learner1D import Learner1D
from adaptive.learner.learner2D import Learner2D
from adaptive.learner.learnerND import LearnerND
from adaptive.learner.integrator_learner import IntegratorLearner
from adaptive.learner.data_saver import DataSaver, make_datasaver

with suppress(ImportError):
# Only available if 'scikit-optimize' is installed
Expand Down
4 changes: 2 additions & 2 deletions adaptive/learner/balancing_learner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-

import os.path
from collections import defaultdict
from collections.abc import Iterable
from contextlib import suppress
from functools import partial
from operator import itemgetter
import os.path

import numpy as np

Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(self, learners, *, cdims=None, strategy='loss_improvements'):
self._pending_loss = {}
self._cdims_default = cdims

if len(set(learner.__class__ for learner in self.learners)) > 1:
if len({learner.__class__ for learner in self.learners}) > 1:
raise TypeError('A BalacingLearner can handle only one type'
' of learners.')

Expand Down
2 changes: 1 addition & 1 deletion adaptive/learner/base_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from contextlib import suppress
from copy import deepcopy

from adaptive.utils import save, load
from adaptive.utils import load, save


def uses_nth_neighbors(n):
Expand Down
2 changes: 1 addition & 1 deletion adaptive/learner/data_saver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

from collections import OrderedDict
import functools
from collections import OrderedDict

from adaptive.learner.base_learner import BaseLearner
from adaptive.utils import copy_docstring_from
Expand Down
3 changes: 2 additions & 1 deletion adaptive/learner/integrator_coeffs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
# Based on an adaptive quadrature algorithm by Pedro Gonnet

from fractions import Fraction
from collections import defaultdict
from fractions import Fraction

import numpy as np
import scipy.linalg

Expand Down
15 changes: 7 additions & 8 deletions adaptive/learner/integrator_learner.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
# Based on an adaptive quadrature algorithm by Pedro Gonnet

import sys
from collections import defaultdict
from math import sqrt
from operator import attrgetter
import sys

import numpy as np
from scipy.linalg import norm
Expand All @@ -14,9 +14,8 @@
from adaptive.notebook_integration import ensure_holoviews
from adaptive.utils import cache_latest, restore

from .integrator_coeffs import (b_def, T_left, T_right, ns, hint,
ndiv_max, min_sep, eps, xi, V_inv,
Vcond, alpha, gamma)
from .integrator_coeffs import (T_left, T_right, V_inv, Vcond, alpha, b_def,
eps, gamma, hint, min_sep, ndiv_max, ns, xi)


def _downdate(c, nans, depth):
Expand Down Expand Up @@ -298,10 +297,10 @@ def complete_process(self, depth):

def __repr__(self):
lst = [
'(a, b)=({:.5f}, {:.5f})'.format(self.a, self.b),
'depth={}'.format(self.depth),
'rdepth={}'.format(self.rdepth),
'err={:.5E}'.format(self.err),
f'(a, b)=({self.a:.5f}, {self.b:.5f})',
f'depth={self.depth}',
f'rdepth={self.rdepth}',
f'err={self.err:.5E}',
'igral={:.5E}'.format(self.igral if hasattr(self, 'igral') else np.inf),
]
return ' '.join(lst)
Expand Down
4 changes: 2 additions & 2 deletions adaptive/learner/learner1D.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-

from copy import deepcopy
import heapq
import itertools
import math
from collections.abc import Iterable
from copy import deepcopy

import numpy as np
import sortedcontainers
import sortedcollections
import sortedcontainers

from adaptive.learner.base_learner import BaseLearner, uses_nth_neighbors
from adaptive.learner.learnerND import volume
Expand Down
3 changes: 1 addition & 2 deletions adaptive/learner/learner2D.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-

import itertools
from collections import OrderedDict
from copy import copy
import itertools
from math import sqrt

import numpy as np
Expand All @@ -12,7 +12,6 @@
from adaptive.notebook_integration import ensure_holoviews
from adaptive.utils import cache_latest


# Learner2D and helper functions.

def deviations(ip):
Expand Down
18 changes: 9 additions & 9 deletions adaptive/learner/learnerND.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# -*- coding: utf-8 -*-

from collections import OrderedDict
from collections.abc import Iterable
import functools
import heapq
import itertools
import random
from collections import OrderedDict
from collections.abc import Iterable

import numpy as np
from scipy import interpolate
import scipy.spatial
from scipy import interpolate
from sortedcontainers import SortedKeyList

from adaptive.learner.base_learner import BaseLearner, uses_nth_neighbors
from adaptive.learner.triangulation import (Triangulation, circumsphere,
fast_det, point_in_simplex,
simplex_volume_in_embedding)
from adaptive.notebook_integration import ensure_holoviews, ensure_plotly
from adaptive.learner.triangulation import (
Triangulation, point_in_simplex, circumsphere,
simplex_volume_in_embedding, fast_det)
from adaptive.utils import restore, cache_latest
from adaptive.utils import cache_latest, restore


def to_list(inp):
Expand Down Expand Up @@ -573,8 +573,8 @@ def _update_losses(self, to_delete: set, to_add: set):
if subtri is not None:
pending_points_unbound.update(subtri.vertices)

pending_points_unbound = set(p for p in pending_points_unbound
if p not in self.data)
pending_points_unbound = {p for p in pending_points_unbound
if p not in self.data}
for simplex in to_add:
loss = self._compute_loss(simplex)
self._losses[simplex] = loss
Expand Down
2 changes: 1 addition & 1 deletion adaptive/learner/skopt_learner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-

import numpy as np
from skopt import Optimizer

from adaptive.learner.base_learner import BaseLearner
from adaptive.notebook_integration import ensure_holoviews
from adaptive.utils import cache_latest
from skopt import Optimizer


class SKOptLearner(Optimizer, BaseLearner):
Expand Down
16 changes: 8 additions & 8 deletions adaptive/learner/triangulation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import math
from collections import Counter
from collections.abc import Sized, Iterable
from itertools import combinations, chain
from collections.abc import Iterable, Sized
from itertools import chain, combinations
from math import factorial

import numpy as np
import math
import scipy.spatial
from math import factorial


def fast_norm(v):
Expand Down Expand Up @@ -624,8 +624,8 @@ def get_neighbors_from_vertices(self, simplex):

def get_face_sharing_neighbors(self, neighbors, simplex):
"""Keep only the simplices sharing a whole face with simplex."""
return set(simpl for simpl in neighbors
if len(set(simpl) & set(simplex)) == self.dim) # they share a face
return {simpl for simpl in neighbors
if len(set(simpl) & set(simplex)) == self.dim} # they share a face

def get_simplices_attached_to_points(self, indices):
# Get all simplices that share at least a point with the simplex
Expand Down Expand Up @@ -667,8 +667,8 @@ def hull(self):
raise RuntimeError("Broken triangulation, a (N-1)-dimensional"
" appears in more than 2 simplices.")

hull = set(point for face, count in counts.items() if count == 1
for point in face)
hull = {point for face, count in counts.items() if count == 1
for point in face}
return hull

def convex_invariant(self, vertex):
Expand Down
3 changes: 1 addition & 2 deletions adaptive/notebook_integration.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-

import asyncio
from contextlib import suppress
import datetime
import importlib
import random
import warnings

from contextlib import suppress

_async_enabled = False
_holoviews_enabled = False
Expand Down
4 changes: 2 additions & 2 deletions adaptive/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import abc
import asyncio
import concurrent.futures as concurrent
from contextlib import suppress
import functools
import inspect
import os
import sys
import time
import traceback
import warnings
from contextlib import suppress

from adaptive.notebook_integration import live_plot, live_info, in_ipynb
from adaptive.notebook_integration import in_ipynb, live_info, live_plot

try:
import ipyparallel
Expand Down
6 changes: 3 additions & 3 deletions adaptive/tests/algorithm_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# Copyright 2017 Christoph Groth

import warnings
from fractions import Fraction as Frac
from collections import defaultdict
from fractions import Fraction as Frac

import numpy as np
from numpy.testing import assert_allclose
from scipy.linalg import norm, inv

from scipy.linalg import inv, norm

eps = np.spacing(1)

Expand Down
2 changes: 1 addition & 1 deletion adaptive/tests/test_balancing_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from adaptive.learner import Learner1D, BalancingLearner
from adaptive.learner import BalancingLearner, Learner1D
from adaptive.runner import simple


Expand Down
Loading

0 comments on commit 176c745

Please sign in to comment.