Skip to content

Commit

Permalink
Merge 8f65b23 into d6d1649
Browse files Browse the repository at this point in the history
  • Loading branch information
rum1887 committed Jun 3, 2023
2 parents d6d1649 + 8f65b23 commit 90dffa2
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 8 deletions.
Binary file added doc/.DS_Store
Binary file not shown.
Binary file added doc/source/.DS_Store
Binary file not shown.
Binary file added doc/source/tutorials-website/.DS_Store
Binary file not shown.
145 changes: 145 additions & 0 deletions doc/source/tutorials-website/create_tutorials_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@

import base64
import re
from jinja2 import Environment, FileSystemLoader, select_autoescape
import requests
import subprocess


def atoi(text):
return int(text) if text.isdigit() else text


def natural_keys(text):
return [atoi(c) for c in re.split('(\d+)', text)]


class notebook:
def __init__(self, path, title):
# remove ../ from path
self.path = path.replace('https://github.com/qutip/qutip-tutorials/tree/main/', '')
self.title = title
# set url and update from markdown to ipynb
self.url = url_prefix + self.path.replace(".md", ".ipynb")


def get_title(filename, dir, version):
""" Reads the title from the notebook """
file_url = f"https://api.github.com/repos/qutip/qutip-tutorials/contents/{version}/{dir}/{filename}"
response = requests.get(file_url)
file_content = response.json()['content']
decoded_text= base64.b64decode(file_content).decode('utf-8')
lines = decoded_text.split("\n")
for line in lines:
# trim leading/trailing whitespaces
line = line.strip()
# check if line is the title
if line.startswith('#'):
# return title
title = line[2:]
return title


def get_directory_contents(directory, version):
url = f"https://api.github.com/repos/qutip/qutip-tutorials/contents/{version}/{directory}"
response = requests.get(url)
if response.status_code == 200:
contents = response.json()
file_names = [content['name'] for content in contents if content['type'] == 'file']
return file_names

else:
print(response.status_code)
return None

def get_notebooks(path,version,dir):
""" Gets a list of all notebooks in a directory """
# get list of files and their titles
try:
filesintut = get_directory_contents(dir,version)
files = [path + f for f in filesintut if f.endswith('.md') ]
except FileNotFoundError:
return {}
titles = [get_title(f,dir,version) for f in filesintut]
# sort the files and titles for display: TODO : files_sorted, titles_sorted = sort_files_titles(files, titles)
# generate notebook objects from the lists and return
notebooks = [notebook(f, t) for f, t in zip(files, titles)]
return notebooks


def generate_index_html(version_directory, version, tutorial_directories, title,
version_note):
""" Generates the index html file from the given data"""
# get tutorials from the different directories
tutorials = {}
for dir in tutorial_directories:
tutorials[dir] = get_notebooks(version_directory + dir + '/', version, dir)

# Load environment for Jinja and template
env = Environment(
loader=FileSystemLoader("../"),
autoescape=select_autoescape()
)
template = env.get_template("tutorials-website/tutorials.html.jinja")

# render template and return
html = template.render(tutorials=tutorials, title=title,
version_note=version_note)
return html


# url prefix for the links
url_prefix = "https://nbviewer.org/urls/qutip.org/qutip-tutorials/"
# tutorial directories
tutorial_directories = [
'quantum-circuits',
'pulse-level-circuit-simulation',
]

# +++ READ PREFIX AND SUFFIX +++
prefix = ""
suffix = ""

#with open('prefix.html', 'r') as f:
# prefix = f.read()
#with open('suffix.html', 'r') as f:
# suffix = f.read()

# +++ VERSION 4 INDEX FILE +++
title = 'Tutorials'
version_note = 'This are the tutorials for QuTiP-qip Version 4. You can \
find the tutorials for QuTiP Version 5 \
<a href="./qutip-qip-v5.html">here</a>.'
version_directory= 'https://github.com/qutip/qutip-tutorials/tree/main/tutorials-v4/'
html = generate_index_html('https://github.com/qutip/qutip-tutorials/tree/main/tutorials-v4/', "tutorials-v4", tutorial_directories, title,version_note)
with open('qutip-qip.html', 'w+') as f:
f.write(prefix)
f.write(html)
f.write(suffix)

# +++ VERSION 5 INDEX FILE +++
title = 'Tutorials'
version_note = 'This are the tutorials for QuTiP Version 5. You can \
find the tutorials for QuTiP Version 4 \
<a href="./qutip-qip.html">here</a>.'

html = generate_index_html('https://github.com/qutip/qutip-tutorials/tree/main/tutorials-v5/', "tutorials-v5",tutorial_directories, title,version_note)
with open('qutip-qip-v5.html', 'w+') as f:
f.write(prefix)
f.write(html)
f.write(suffix)

# convert html to rst
def convert_html_to_rst(html_file_path, rst_file_path):
# Use the subprocess module to call the pandoc command-line tool
subprocess.run(['pandoc', html_file_path, '-o', rst_file_path])

html_file_path = 'qutip-qip.html'
html_file_path_v5 = 'qutip-qip-v5.html'

rst_file_path = '../tutorials.rst'
rst_file_path_v5 = '../tutorials_v5.rst'

convert_html_to_rst(html_file_path, rst_file_path)
convert_html_to_rst(html_file_path_v5, rst_file_path_v5)

39 changes: 39 additions & 0 deletions doc/source/tutorials-website/tutorials.html.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<div class="row">
<div class="col-md-12">
<h1>{{ title }}</h1><br>
</div>
</div>

<h4 id="quantum-information-processing">Quantum information processing</h4>
<p>This section contains tutorials for QuTiP Version 4. You can find the tutorials for QuTiP Version 5 <a href="">here</a>.
</p>

<h5 id="qip-circuits">Quantum circuits and algorithms</h5>
<ul>
{% for item in tutorials['quantum-circuits'] %}
<li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}
</ul>

<h5 id="qip-pulse-level">Pulse-level circuit simulation</h5>
<ul>
{% for item in tutorials['pulse-level-circuit-simulation'] %}
<li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}
</ul>

<div class="row">
<div class="col-md-12">
<h3 id="contributing">Contributing</h3>
<p>If you would like to contribute a notebook or report a bug, you may open
an issue or pull request in the
<a href="https://github.com/qutip/qutip-tutorials">qutip-tutorials</a>
GitHub repository.
</p>
<p>A few of the notebooks are still maintained in the repository
<a href="https://github.com/qutip/qutip-notebooks">qutip-notebooks</a> and
a complete archive of older versions of the tutorials is maintained there.
</p>

</div>
</div>
69 changes: 61 additions & 8 deletions doc/source/tutorials.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
.. _tutorials:
.. container:: row

************
Tutorials
************
.. container:: col-md-12

Tutorials related to using quantum gates and circuits in ``qutip-qip`` can be
found `here <https://qutip.org/tutorials#quantum-information-processing>`_ and
those related to using noise simulators are available at this
`link <https://qutip.org/tutorials#nisq>`_.
.. rubric:: Tutorials
:name: tutorials

Quantum information processing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This section contains tutorials for QuTiP Version 4. You can find the
tutorials for QuTiP Version 5 `here <>`__.

.. _qip-circuits:

Quantum circuits and algorithms
'''''''''''''''''''''''''''''''

- `Imports and Exports QASM
circuit <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/quantum-circuits/qasm.ipynb>`__
- `Decomposition of the Toffoli gate in terms of CNOT and single-qubit
rotations <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/quantum-circuits/qip-toffoli-cnot.ipynb>`__
- `QuTiP example: Quantum Gates and their
usage <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/quantum-circuits/quantum-gates.ipynb>`__
- `Quantum Teleportation
Circuit <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/quantum-circuits/teleportation.ipynb>`__

.. _qip-pulse-level:

Pulse-level circuit simulation
''''''''''''''''''''''''''''''

- `Compiling and simulating a 10-qubit Quantum Fourier Transform (QFT)
algorithm <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/pulse-level-circuit-simulation/qip-10-qubit-QFT-algorithm.ipynb>`__
- `Custimize the pulse-level
simulation <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/pulse-level-circuit-simulation/qip-customize-device.ipynb>`__
- `Examples for
OptPulseProcessor <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/pulse-level-circuit-simulation/qip-optpulseprocessor.ipynb>`__
- `Simulating the Deutsch–Jozsa algorithm at the pulse
level <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/pulse-level-circuit-simulation/qip-processor-DJ-algorithm.ipynb>`__
- `Simulating randomized
benchmarking <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/pulse-level-circuit-simulation/qip-randomized-benchmarking.ipynb>`__
- `measuring the relaxation time with the idling
gate <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/pulse-level-circuit-simulation/qip-relaxation-measurement-with-the-idling-gate.ipynb>`__
- `Scheduler for quantum gates and
instructions <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v4/pulse-level-circuit-simulation/qip-scheduler.ipynb>`__

.. container:: row

.. container:: col-md-12

.. rubric:: Contributing
:name: contributing

If you would like to contribute a notebook or report a bug, you
may open an issue or pull request in the
`qutip-tutorials <https://github.com/qutip/qutip-tutorials>`__
GitHub repository.

A few of the notebooks are still maintained in the repository
`qutip-notebooks <https://github.com/qutip/qutip-notebooks>`__ and
a complete archive of older versions of the tutorials is
maintained there.
63 changes: 63 additions & 0 deletions doc/source/tutorials_v5.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.. container:: row

.. container:: col-md-12

.. rubric:: Tutorials
:name: tutorials

Quantum information processing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This section contains tutorials for QuTiP Version 4. You can find the
tutorials for QuTiP Version 5 `here <>`__.

.. _qip-circuits:

Quantum circuits and algorithms
'''''''''''''''''''''''''''''''

- `Imports and Exports QASM
circuit <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/quantum-circuits/qasm.ipynb>`__
- `Decomposition of the Toffoli gate in terms of CNOT and single-qubit
rotations <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/quantum-circuits/qip-toffoli-cnot.ipynb>`__
- `QuTiP example: Quantum Gates and their
usage <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/quantum-circuits/quantum-gates.ipynb>`__
- `Quantum Teleportation
Circuit <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/quantum-circuits/teleportation.ipynb>`__

.. _qip-pulse-level:

Pulse-level circuit simulation
''''''''''''''''''''''''''''''

- `Compiling and simulating a 10-qubit Quantum Fourier Transform (QFT)
algorithm <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/pulse-level-circuit-simulation/qip-10-qubit-QFT-algorithm.ipynb>`__
- `Custimize the pulse-level
simulation <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/pulse-level-circuit-simulation/qip-customize-device.ipynb>`__
- `Examples for
OptPulseProcessor <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/pulse-level-circuit-simulation/qip-optpulseprocessor.ipynb>`__
- `Simulating the Deutsch–Jozsa algorithm at the pulse
level <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/pulse-level-circuit-simulation/qip-processor-DJ-algorithm.ipynb>`__
- `Simulating randomized
benchmarking <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/pulse-level-circuit-simulation/qip-randomized-benchmarking.ipynb>`__
- `measuring the relaxation time with the idling
gate <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/pulse-level-circuit-simulation/qip-relaxation-measurement-with-the-idling-gate.ipynb>`__
- `Scheduler for quantum gates and
instructions <https://nbviewer.org/urls/qutip.org/qutip-tutorials/tutorials-v5/pulse-level-circuit-simulation/qip-scheduler.ipynb>`__

.. container:: row

.. container:: col-md-12

.. rubric:: Contributing
:name: contributing

If you would like to contribute a notebook or report a bug, you
may open an issue or pull request in the
`qutip-tutorials <https://github.com/qutip/qutip-tutorials>`__
GitHub repository.

A few of the notebooks are still maintained in the repository
`qutip-notebooks <https://github.com/qutip/qutip-notebooks>`__ and
a complete archive of older versions of the tutorials is
maintained there.

0 comments on commit 90dffa2

Please sign in to comment.