Skip to content
Snippets Groups Projects
Verified Commit cc679d1c authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
*~
.ipynb_checkpoints
site
docs
*.pyc
__pycache__
image: quantumtinkerer/research
stages:
- build
- deploy
build lectures:
stage: build
before_script:
- pip install -U mkdocs mkdocs-material python-markdown-math notedown
script:
- python execute.py
- mkdocs build
artifacts:
paths:
- site
expire_in: 1 week
.prepare_deploy: &prepare_deploy
stage: deploy
only:
- branches@sconesaboj/qm1-notes
before_script:
## Install ssh-agent if not already installed, it is required by Docker.
## (change apt-get to yum if you use an RPM-based image)
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
## Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
## Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
## We're using tr to fix line endings which makes ed25519 keys work
## without extra base64 encoding.
## https://gitlab.com/gitlab-examples/ssh-private-key/issues/1#note_48526556
- echo "$WEBSITE_UPLOAD_KEY" | tr -d '\r' | ssh-add - > /dev/null
## Create the SSH directory and give it the right permissions
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan tnw-tn1.tudelft.net >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- "rsync -rv site/* qm1@tnw-tn1.tudelft.net:$DEPLOY_PATH"
deploy master version:
<<: *prepare_deploy
only:
- master@sconesaboj/qm1-notes
variables:
DEPLOY_PATH: ""
environment:
name: $CI_COMMIT_REF_NAME
url: "https://qm1.quantumtinkerer.tudelft.nl"
deploy test version:
<<: *prepare_deploy
except:
- master@sconesaboj/qm1-notes
variables:
DEPLOY_PATH: "test_builds/$CI_COMMIT_REF_NAME"
environment:
name: $CI_COMMIT_REF_NAME
url: "https://qm1.quantumtinkerer.tudelft.nl/test_builds/$CI_COMMIT_REF_NAME"
on_stop: undeploy test version
undeploy test version:
<<: *prepare_deploy
except:
- master@sconesaboj/qm1-notes
when: manual
variables:
DEPLOY_PATH: "test_builds/$CI_COMMIT_REF_NAME"
script:
- mkdir empty/
- "rsync -rlv --delete empty/ solidstate@tnw-tn1.tudelft.net:$DEPLOY_PATH"
environment:
name: $CI_COMMIT_REF_NAME
action: stop
<!--
Thanks for providing feedback!
Please provide the information below.
-->
## File in which the problem appears
## Problematic sentence
## Correct version
The following people contributed to making of these lecture notes:
* Sonia Conesa Boj
<!--
Execute
git shortlog -s | sed -e "s/^ *[0-9\t ]*//"| xargs -i sh -c 'grep -q "{}" AUTHORS.md || echo "{}"'
To check if any authors are missing from this list.
-->
Copyright Delft University of Technology and contributors 2019.
## Contents
[![Creative Commons License](https://i.creativecommons.org/l/cc-by-sa-nc/4.0/88x31.png)](http://creativecommons.org/licenses/cc-by-sa-nc/4.0/ "Creative Commons License")
This work is licensed under a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/cc-by-sa-nc/4.0/).
## Source code
The source code for building the website and producing the plots is available under BSD license.
Copyright (c) 2019, Delft University of Technology and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL DELFT UNIVERSITY OF TECHNOLOGY BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Quantum mechanics 1 lecture notes
Lecture notes and teaching material used for the Delft University of Technology course awesome course.
The compiled materials are available at https://qm1.quantumtinkerer.tudelft.nl
# Origin and technical support
This repository is based on a template for publishing lecture notes, developed
by Anton Akhmerov, who also hosts such repositories for other courses.
from pathlib import Path
import shutil
import mimetypes
import nbconvert
import notedown
from traitlets.config import Config
from nbconvert_fix import ExtractOutputPreprocessor
reader = notedown.MarkdownReader(code_regex='fenced')
mimetypes.add_type('application/vnd.plotly.v1+json', '.json')
src = Path('src')
target = Path('docs')
shutil.rmtree(target, ignore_errors=True)
target.mkdir(exist_ok=True)
shutil.copytree(src / 'figures', target / 'figures')
shutil.copytree(src / 'scripts', target / 'scripts')
output_extractor = ExtractOutputPreprocessor()
output_extractor.extract_output_types = (
output_extractor.extract_output_types
| {'application/vnd.plotly.v1+json'}
)
exporter = nbconvert.MarkdownExporter(
config=Config(dict(
MarkdownExporter=dict(
preprocessors=[
nbconvert.preprocessors.ExecutePreprocessor,
output_extractor,
],
exclude_input=True,
template_file='extra_markdown.tpl',
),
NbConvertBase=dict(
display_data_priority=[
'text/html',
'text/markdown',
'image/svg+xml',
'text/latex',
'image/png',
'application/vnd.plotly.v1+json',
'image/jpeg',
'text/plain'
]
),
))
)
writer = nbconvert.writers.FilesWriter(build_directory=str(target))
for source_file in src.glob('*.md'):
fname = source_file.name[:-len('.md')]
notebook = reader.reads(source_file.read_text())
output, resources = exporter.from_notebook_node(
notebook,
resources={
'unique_key': fname,
'output_files_dir': 'figures',
}
)
writer.write(output, resources, fname)
{% extends 'markdown.tpl' %}
{%- block data_other -%}
{%- for type in output.data | filter_data_type -%}
{%- if type == 'application/vnd.plotly.v1+json' -%}
{%- set fname = output.metadata.filenames['application/vnd.plotly.v1+json'] -%}
{%- set plotly_url = fname | path2url -%}
{%- set div_id = fname.split('/') | last -%}
<div id="{{cookiecutter.div_id}}"><img ></img></div>
<script>
window.addEventListener('load', function() {
Plotly.d3.json('../{{cookiecutter.plotly_url}}', function(error, fig) {
Plotly.plot('{{cookiecutter.div_id}}', fig.data, fig.layout).then(
function(value) {Plotly.relayout('{{cookiecutter.div_id}}', {height: ' '})}
);
});
});
</script>
{%- endif -%}
{%- endfor -%}
{%- endblock -%}
{% block error %}
{% endblock error %}
{% block stream %}
{%- if output.name == 'stdout' -%}
{{cookiecutter. output.text | indent }}
{%- endif -%}
{% endblock stream %}
site_name: Quantum mechanics 1 lecture notes
repo_url: https://gitlab.kwant-project.org/sconesaboj/qm1-notes
repo_name: source
edit_uri: edit/master/src/
site_description: |
Lecture notes for QM1
nav:
- Intro: 'index.md'
theme:
name: material
palette:
primary: 'white'
accent: 'indigo'
markdown_extensions:
- mdx_math:
enable_dollar_delimiter: True
- toc:
permalink: True
- admonition
- pymdownx.details
- abbr
- footnotes
- meta
extra_javascript:
- 'https://cdn.plot.ly/plotly-latest.min.js'
- 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-AMS_HTML'
- 'scripts/mathjaxhelper.js'
copyright: "Copyright © 2019 Delft University of Technology, CC-BY-SA-NC 4.0."
import sys
import os
import json
from mimetypes import guess_extension
from binascii import a2b_base64
from nbformat.notebooknode import NotebookNode
import nbconvert
from nbconvert.preprocessors.extractoutput import guess_extension_without_jpe
class ExtractOutputPreprocessor(nbconvert.preprocessors.ExtractOutputPreprocessor):
# Patches against gh-846 following
# https://github.com/jupyter/nbconvert/pull/847
def preprocess_cell(self, cell, resources, cell_index):
"""
Apply a transformation on each cell,
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into the Jinja engine.
cell_index : int
Index of the cell being processed (see base.py)
"""
#Get the unique key from the resource dict if it exists. If it does not
#exist, use 'output' as the default. Also, get files directory if it
#has been specified
unique_key = resources.get('unique_key', 'output')
output_files_dir = resources.get('output_files_dir', None)
#Make sure outputs key exists
if not isinstance(resources['outputs'], dict):
resources['outputs'] = {}
#Loop through all of the outputs in the cell
for index, out in enumerate(cell.get('outputs', [])):
if out.output_type not in {'display_data', 'execute_result'}:
continue
#Get the output in data formats that the template needs extracted
for mime_type in self.extract_output_types:
if mime_type in out.data:
data = out.data[mime_type]
# If data was JSON, it will become a NotebookNode at this point.
if isinstance(data, NotebookNode):
data = json.dumps(data)
#Binary files are base64-encoded, SVG is already XML
if mime_type in {'image/png', 'image/jpeg', 'application/pdf'}:
# data is b64-encoded as text (str, unicode),
# we want the original bytes
data = a2b_base64(data)
elif sys.platform == 'win32':
data = data.replace('\n', '\r\n').encode("UTF-8")
else:
data = data.encode("UTF-8")
ext = guess_extension_without_jpe(mime_type)
if ext is None:
ext = '.' + mime_type.rsplit('/')[-1]
if out.metadata.get('filename', ''):
filename = out.metadata['filename']
if not filename.endswith(ext):
filename+=ext
else:
filename = self.output_filename_template.format(
unique_key=unique_key,
cell_index=cell_index,
index=index,
extension=ext)
# On the cell, make the figure available via
# cell.outputs[i].metadata.filenames['mime/type']
# where
# cell.outputs[i].data['mime/type'] contains the data
if output_files_dir is not None:
filename = os.path.join(output_files_dir, filename)
out.metadata.setdefault('filenames', {})
out.metadata['filenames'][mime_type] = filename
if filename in resources['outputs']:
raise ValueError(
"Your outputs have filename metadata associated "
"with them. Nbconvert saves these outputs to "
"external files using this filename metadata. "
"Filenames need to be unique across the notebook, "
"or images will be overwritten. The filename {} is "
"associated with more than one output. The second "
"output associated with this filename is in cell "
"{}.".format(filename, cell_index)
)
#In the resources, make the figure available via
# resources['outputs']['filename'] = data
resources['outputs'][filename] = data
return cell, resources
# Nice title
!!! summary "Learning goals"
After following this course you will be able to:
- Solve awesome problems
- Tell exciting stories
In these notes our aim is to provide learning materials which are:
- self-contained
- easy to modify and remix, so we provide the full source, including the code
- open for reuse: see the license below.
Whether you are a student taking this course, or an instructor reusing the materials, we welcome all contributions, so check out the [course repository](https://gitlab.kwant-project.org/sconesaboj/qm1-notes), especially do [let us know](https://gitlab.kwant-project.org/sconesaboj/qm1-notes/issues/new?issuable_template=typo) if you see a typo!
MathJax.Hub.Config({
config: ["MMLorHTML.js"],
jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
tex2jax: {
inlineMath: [ ['$','$'] ],
processEscapes: true
},
extensions: ["MathMenu.js", "MathZoom.js"]
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment