Skip to content

Commit

Permalink
Merge branch 'api-design'
Browse files Browse the repository at this point in the history
  • Loading branch information
jbweston committed Dec 14, 2018
2 parents 489b0e4 + 1d0cdd3 commit 8e0a0a1
Show file tree
Hide file tree
Showing 32 changed files with 3,247 additions and 1,753 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
semicon/_static_version.py export-subst
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ ENV/
# this project
kp_models/cache.json
.pytest_cache
semicon/model_cache.json
29 changes: 24 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
image: kwant/testing

stages:
- build
- test

build package:
stage: build
test package:
stage: test
script:
- python3 setup.py build
- pip3 install sympy==1.1.1
- pip3 install -e .
- py.test -r w --cov semicon --cov-report term --flakes semicon


test package:
test package with latest scipy:
stage: test
script:
- pip3 install sympy==1.1.1 scipy==1.2.0rc2
- pip3 install -e .
- py.test -r w --cov semicon --cov-report term --flakes semicon


test package with latest SymPy and Kwant stable:
stage: test
script:
- pip3 install sympy
- pip3 install git+https://gitlab.kwant-project.org/kwant/kwant.git@stable
- pip3 install -e .
- py.test -r w --cov semicon --cov-report term --flakes semicon

test packaging:
stage: test
script:
- pip3 install sympy==1.1.1
- pip3 install .
- cd / # make sure we don't import the cloned version
- python3 -c 'import semicon; semicon.test()'
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include LICENSE README.md
include semicon/databank/*.yml
872 changes: 93 additions & 779 deletions notebooks/hamiltonian_and_bulk_bands.ipynb

Large diffs are not rendered by default.

229 changes: 197 additions & 32 deletions notebooks/interface sketch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,229 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# basic interface idea (prototype)"
"# Idea of API\n",
"\n",
"See corresponding [issue](https://gitlab.kwant-project.org/semicon/semicon/issues/16)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic idea"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"import semicon\n",
"from semicon.models import ZincBlende\n",
"from semicon.helpers import interpolate_parameters\n",
"\n",
"bands = ['gamma_6c', 'gamma_8v', 'gamma_7v']\n",
"\n",
"# this will be probably a sympy model, that\n",
"# can directly be used by ``kwant.continuum.discretizer``.\n",
"# coords describe space dependence of parameters\n",
"# bands and components are sequence of strings\n",
"model = ZincBlende(coords='z', bands=..., components=...)\n",
"\n",
"hamiltonian = semicon.models.kane(\n",
" components=['base', 'zeeman', 'dresselhaus'], \n",
" bands=bands,\n",
" coords='z',\n",
")\n",
"\n",
"# hamiltonian property returned as sympy object\n",
"smp_ham = model.hamiltonian\n",
"\n",
"\n",
"# parameters returned via method of model\n",
"# this method has access to \"bands\" and \"components\" and return\n",
"# a parameter class object: subclass of dict with extra method\n",
"# for removing spurious solutions\n",
"pInAs = model.parameters(material='InAs', databank=lawaetz)\n",
"pInAs = pInAs.renormalize(gamma_0=1)\n",
"\n",
"\n",
"# this will be a dictionary that can be passed into ``params`` of kwant system.\n",
"# possible it will also have attributes with extra information about material\n",
"# sources, etc.\n",
"\n",
"parameters = semicon.parameters.two_deg(\n",
" bank='lawaetz',\n",
" materials=['AlSb', 'InAs', 'GaSb', 'InAs'],\n",
" widths=[5, 12.5, 5, 5],\n",
" valence_band_offsets=[.18, .0, .56, .18]\n",
" extra_constants={'hbar': 1, 'e': 1},\n",
" bands=bands,\n",
"# these could be for example combined with helper function\n",
"# to provide interpolated smooth functions for a \"sandwich\"\n",
"# two-deg system\n",
"parameters = {k: model.parameters(material=k).renormalize(gamma_0=1) \n",
" for k in ['InAs', 'GaSb', 'AlSb']}\n",
"\n",
"syst = ... # user defines his system of appropriate shape and fill \n",
" # with smp_ham through discretizer on his own\n",
"\n",
"# assingment is mapping from coords to material name\n",
"parameters = interpolate_parameters(syst, parameters, assingment)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## basic bulk example"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from semicon.models import ZincBlende\n",
"\n",
"model = ZincBlende(\n",
" bands=('gamma_6c', 'gamma_8v', 'gamma_7v'),\n",
" components=('base', 'zeeman', 'strain'),\n",
")\n",
"\n",
"params = model.parameters(material='InAs').renormalize(gamma_0=1)\n",
"\n",
"\n",
"# and standard kwant code (for continuum disp)\n",
"\n",
"shape = semicon.shapes.two_deg(L=sum(parameters.widths))"
"disp = kwant.continuum.lambdify(model.hamiltonian)\n",
"e_k = lambda kx, ky, kz: disp(k_x=kx, k_y=ky, k_z=kz, **params)\n",
"...\n",
"\n",
"\n",
"# and standard kwant code (for tb dispersion)\n",
"\n",
"template = kwant.continuum.discretize(model.hamiltonian, grid_spacing=0.5)\n",
"syst = kwant.wraparound.wraparound(template).finalized()\n",
"e_k = lambda kx, ky, kz: syst.hamiltonian_submpatrix(params=dict('k_x': k_x, ..., **params))\n",
"..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## basic two-deg example"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"from semicon.models import ZincBlende\n",
"import semicon\n",
"\n",
"\n",
"model = ZincBlende(\n",
" coords='z',\n",
" bands=('gamma_6c', 'gamma_8v', 'gamma_7v'),\n",
" components=('base', 'zeeman', 'strain'),\n",
")\n",
"\n",
"parameters = {k: model.parameters(material=k).renormalize(gamma_0=1) \n",
" for k in ['InAs', 'GaSb', 'AlSb']}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### get system"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import kwant\n",
"template = kwant.continuum.discretize(hamiltonian, coords='z', grid_spacing=0.5)\n",
"grid = 0.5\n",
"L = 20\n",
"\n",
"template = kwant.continuum.discretize(model.hamiltonian, coords='z', grid_spacing=a)\n",
"syst = kwant.Builder()\n",
"\n",
"shape = semicon.shapes.twodeg(start=0 - a/2, end=L + a/2)\n",
"syst.fill(template, shape, (0,))\n",
"syst = syst.finalized()\n",
"syst = syst.finalized()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## get 2deg parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def twodeg_mapping(z):\n",
" \"\"\"User specified mapping from coord to material.\"\"\"\n",
" return 'AlSb' if z < 5 or z > 5 else 'InAs'\n",
" \n",
" \n",
"pars_2deg = semicon.helpers.interpolate(\n",
" syst=syst,\n",
" parameters=parameters,\n",
" mapping=twodeg_mapping \n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## and finally obtain hamiltonian and do simulation"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ham = syst.hamiltonian_submatrix(params=pars_2deg)\n",
"..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# further nice helpers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## different growth direction\n",
"\n",
"Basic idea about the rotation of coordinates is explained in this [notebook](./rotations.ipynb) and discussed in this [issue](https://gitlab.kwant-project.org/semicon/semicon/issues/12).\n",
"\n",
"From the notebook it is clear that applying rotation produce ugly numerical coefficients in the Hamiltonian. Therefore it may be good idea to chain this method with ``prettify`` functionality."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from semicon.models import ZincBlende\n",
"\n",
"model = ZincBlende(\n",
" bands=('gamma_6c', 'gamma_8v', 'gamma_7v'),\n",
" components=('base', 'zeeman', 'strain'),\n",
")\n",
"\n",
"R = ... # 3x3 rotation matrix\n",
"model = model.rotate(R, act_on=semicon.symbols.momenta) \\ \n",
" .prettify(zero_atol=1e-8, nsimplify=True)\n",
"\n",
"\n",
"ham = syst.hamiltonian_submatrix(params=parameters)"
"# note: Using \"act_on\" to specify rotation of only momenta\n",
"# allows to leave coords unchanged (treat them as they \n",
"# would be already defined in simulation coordinate system)"
]
}
],
Expand All @@ -81,7 +246,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.6"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 8e0a0a1

Please sign in to comment.