Commit 7e7c3d94 authored by Joseph Weston's avatar Joseph Weston

Merge branch 'stable'

parents 691d8c85 f04429f9
image: kwant/testing
image: gitlab.kwant-project.org:5005/kwant/testing
stages:
- build
......@@ -12,7 +12,7 @@ variables:
IGNORE_HOSTKEY: "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
build package:
.build: &build
stage: build
script:
- echo -e "[DEFAULT]\ndefine_macros = CYTHON_TRACE=1" >build.conf
......@@ -22,12 +22,74 @@ build package:
untracked: true
expire_in: 1 hour
.stable-env: &stable_env
before_script:
- source deactivate
- source activate kwant-stable
- unset CFLAGS # https://github.com/conda-forge/toolchain-feedstock/issues/41
.no-extras-env: &no_extras_env
before_script:
- source deactivate
- source activate kwant-stable-no-extras
- unset CFLAGS # https://github.com/conda-forge/toolchain-feedstock/issues/41
# Note that this is 'latest' as of when the image was last built
.latest-env: &latest_env
before_script:
- source deactivate
- source activate kwant-latest
- unset CFLAGS # https://github.com/conda-forge/toolchain-feedstock/issues/41
.bleeding-edge-env: &bleeding_edge_env
before_script:
- source deactivate
- conda env update -f /kwant-latest.yml
- source activate kwant-latest
.ubuntu-env: &ubuntu_env
image: gitlab.kwant-project.org:5005/kwant/testing/ubuntu
.debian-env: &debian_env
image: gitlab.kwant-project.org:5005/kwant/testing/debian
## Build Jobs
build:ubuntu:
<<: *build
<<: *ubuntu_env
build:debian:
<<: *build
<<: *debian_env
build:stable:
<<: *build
<<: *stable_env
build:no-extras:
<<: *build
<<: *no_extras_env
build:latest:
<<: *build
<<: *latest_env
build:bleeding-edge:
<<: *build
<<: *bleeding_edge_env
only:
- schedules
## Test Jobs
check whitespace style:
stage: build
stage: test
script: ./check_whitespace
allow_failure: true
check for dependencies installed:
stage: test
script:
......@@ -35,10 +97,63 @@ check for dependencies installed:
allow_failure: true
.test: &test
stage: test
script:
- py.test -r w --cov=kwant --cov-report term --cov-report html --flakes kwant --junitxml=tests.xml
artifacts:
paths:
- htmlcov
reports:
junit: tests.xml
test:stable:
<<: *test
<<: *stable_env
dependencies:
- build:stable
test:no-extras:
<<: *test
<<: *no_extras_env
dependencies:
- build:no-extras
test:ubuntu:
<<: *test
<<: *ubuntu_env
dependencies:
- build:ubuntu
test:debian:
<<: *test
<<: *debian_env
dependencies:
- build:debian
test:latest:
<<: *test
<<: *latest_env
dependencies:
- build:latest
test:bleeding-edge:
<<: *test
<<: *bleeding_edge_env
dependencies:
- build:bleeding-edge
only:
- schedules
## Documentation building
build documentation:
<<: *latest_env
dependencies:
- build:latest
stage: test
script:
- pip3 install --upgrade matplotlib
- make -C doc realclean; make -C doc html SPHINXOPTS='-A website_deploy=True -n -W' SOURCE_LINK_TEMPLATE="$CI_PROJECT_URL"/blob/\$\$r/\$\$f
artifacts:
paths:
......@@ -46,10 +161,11 @@ build documentation:
expire_in: 1 month
build PDF documentation:
<<: *latest_env
dependencies:
- build:latest
stage: test
script:
- pip3 install sympy
- pip3 install --upgrade matplotlib
- make -C doc latex SPHINXOPTS='-n -W'
- cd doc/build/latex
- make all-pdf
......@@ -58,24 +174,18 @@ build PDF documentation:
- doc/build/latex/kwant.pdf
expire_in: 1 month
run tests:
stage: test
script:
- py.test -r w --cov=kwant --cov-report term --cov-report html --flakes kwant --junitxml=tests.xml
artifacts:
paths:
- htmlcov
reports:
junit: tests.xml
check for broken links in doc:
<<: *latest_env
dependencies:
- build:latest
stage: test
script:
- make -C doc linkcheck
allow_failure: true
## Conda package building
.conda-template: &conda_job
stage: deploy
image: condaforge/linux-anvil
......@@ -109,6 +219,7 @@ build and upload conda package (manual):
- master@kwant/kwant
when: manual
## Upload coverage reports and dev documentation
upload coverage:
stage: deploy
......@@ -196,7 +307,8 @@ upload dev version docs:
after_script:
- rm -rf ~/.ssh
# tagged version deploy
## Build documentation for tagged releases
.tagged-version: &tagged_version
only:
......
......@@ -158,7 +158,15 @@ def sympify(expr, locals=None):
'"locals" will not be used.',
RuntimeWarning,
stacklevel=2)
return expr
# We assume that all present functions, like "sin", "cos", will be
# provided by user during the final evaluation through "params".
# Therefore we make sure they are defined as AppliedUndef, not built-in
# sympy types.
subs = {r: sympy.Function(str(r.func))(*r.args)
for r in expr.atoms(sympy.Function)}
return expr.subs(subs)
# if ``expr`` is not a "sympy" then we proceed with sympifying process
if locals is None:
......@@ -189,14 +197,6 @@ def sympify(expr, locals=None):
else:
del converter[list]
# We assume that all present functions, like "sin", "cos", will be
# provided by user during the final evaluation through "params".
# Therefore we make sure they are define as AppliedUndef, not built-in
# sympy types.
subs = {r: sympy.Symbol(str(r.func))(*r.args)
for r in hamiltonian.atoms(sympy.Function)}
hamiltonian = hamiltonian.subs(subs)
return hamiltonian
......
......@@ -502,9 +502,16 @@ def _discretize_expression(expression, coords):
class _NumericPrinter(LambdaPrinter):
def __init__(self):
LambdaPrinter.__init__(self)
if 'allow_unknown_functions' in LambdaPrinter._default_settings:
settings = {'allow_unknown_functions': True}
else:
# We're on Sympy without "allow_unknown_functions" setting
settings = {}
LambdaPrinter.__init__(self, settings=settings)
self.known_functions = {}
self.known_constants = {'pi': 'pi', 'Pi': 'pi'}
self.known_constants = {'pi': 'pi', 'Pi': 'pi', 'I': 'I'}
def _print_ImaginaryUnit(self, expr):
# prevent sympy from printing 'I' for imaginary unit
......@@ -678,7 +685,10 @@ def _builder_value(expr, coords, grid_spacing, onsite,
header = 'def {}({}):'.format(name, site_string)
func_code = separator.join([header] + list(lines))
namespace = {'pi': np.pi}
# Add "I" to namespace just in case sympy again would miss to replace it
# with Python's 1j as it was the case with SymPy 1.2 when I was argument
# of some function.
namespace = {'pi': np.pi, 'I': 1j}
namespace.update(_cache)
source = []
......
......@@ -20,17 +20,18 @@ from kwant.continuum._common import lambdify
com_A, com_B, com_C = sympy.symbols('A B C')
fA, fB, fC = sympy.symbols('A B C', cls=sympy.Function)
x_op, y_op, z_op = position_operators
kx, ky, kz = momentum_operators
@pytest.mark.parametrize('input_expr, output_expr', [
('k_x * A(x) * k_x', kx * com_A(x_op) * kx),
('[[k_x * A(x) * k_x]]', sympy.Matrix([kx * com_A(x_op) * kx])),
('k_x * A(x) * k_x', kx * fA(x_op) * kx),
('[[k_x * A(x) * k_x]]', sympy.Matrix([kx * fA(x_op) * kx])),
('k_x * sigma_y + k_y * sigma_x', kx * msigma(2) + ky * msigma(1)),
('[[k_x*A(x)*k_x, B(x, y)*k_x], [k_x*B(x, y), C*k_y**2]]',
sympy.Matrix([[kx*com_A(x_op)*kx, com_B(x_op, y_op)*kx],
[kx*com_B(x_op, y_op), com_C*ky**2]])),
sympy.Matrix([[kx*fA(x_op)*kx, fB(x_op, y_op)*kx],
[kx*fB(x_op, y_op), com_C*ky**2]])),
('kron(sigma_x, sigma_y)', TensorProduct(msigma(1), msigma(2))),
('identity(2)', sympy.eye(2)),
('eye(2)', sympy.eye(2)),
......@@ -46,7 +47,7 @@ def test_sympify(input_expr, output_expr):
('k_x', kx + ky, {'k_x': 'k_x + k_y'}),
('x', x_op + y_op, {'x': 'x + y'}),
('A', com_A + com_B, {'A': 'A + B'}),
('A', com_A + com_B(x_op), {'A': 'A + B(x)'}),
('A', com_A + fB(x_op), {'A': 'A + B(x)'}),
('A', msigma(2), {'A': "[[0, -1j], [1j, 0]]"}),
])
def test_sympify_substitutions(input_expr, output_expr, subs):
......@@ -102,10 +103,11 @@ def test_make_commutative():
matr_monomials = sympify("[[x+y, a*x**2 + b*y], [y, x]]")
x, y, z = position_operators
a, b = sympy.symbols('a, b')
fA, fB = sympy.symbols('A B', cls=sympy.Function)
@pytest.mark.parametrize('expr, gens, output', [
(x * a(x) * x + x**2 * a, None, {x**2: a(x), a*x**2: 1}),
(x * a(x) * x + x**2 * a, [x], {x**2: a(x) + a}),
(x * fA(x) * x + x**2 * a, None, {x**2: fA(x), a*x**2: 1}),
(x * fA(x) * x + x**2 * a, [x], {x**2: fA(x) + a}),
(x**2, [x], {x**2: 1}),
(2 * x + 3 * x**2, [x], {x: 2, x**2: 3}),
(2 * x + 3 * x**2, 'x', {x: 2, x**2: 3}),
......
This diff is collapsed.
......@@ -39,6 +39,7 @@ from kwant import plotter
from kwant import _plotter # for mpl_available
@pytest.mark.skipif(not plotter.mpl_available, reason="Matplotlib unavailable.")
def test_matplotlib_backend_unset():
"""Simply importing Kwant should not set the matplotlib backend."""
assert matplotlib_backend_chosen is False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment