Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: port manual source material to MyST markdown #370

Merged
merged 17 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Pytket is a python module for interfacing with tket, a quantum computing toolkit

This repository contains the pytket user manual and example notebooks content in the `docs` directory. It does not contain source code for pytket itself. The source code is maintained on the [tket repository](https://github.com/CQCL/tket).

The manual and examples are built and deployed as html pages using the [jupyter-sphinx](https://jupyter-sphinx.readthedocs.io/en/latest/) and [myst-nb](https://myst-nb.readthedocs.io/en/latest/) libraries. Instructions on building the docs locally can be found [here](https://github.com/CQCL/pytket-docs/blob/main/docs/README.md).
The manual and examples are built and deployed as html pages using the [myst-nb](https://myst-nb.readthedocs.io/en/latest/) library. Instructions on building the docs locally can be found [here](https://github.com/CQCL/pytket-docs/blob/main/docs/README.md).

Note that the TKET website is not deployed from this repository. This repository just contains the content for the documentation.

Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
extensions = [
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"jupyter_sphinx",
"sphinx_copybutton",
"sphinx.ext.autosectionlabel",
"myst_nb",
Expand Down
160 changes: 160 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---
file_format: mystnb
kernelspec:
name: python3
---

# Getting Started

## Building a circuit with the `Circuit` class

You can create a circuit by creating an instance of the `Circuit`
class and adding gates manually.


```{code-cell} ipython3

from pytket import Circuit

ghz_circ = Circuit(3)
ghz_circ.H(0)
ghz_circ.CX(0, 1)
ghz_circ.CX(1, 2)
ghz_circ.add_barrier(ghz_circ.qubits)
ghz_circ.measure_all()
```

Now let’s draw a nice picture of the circuit with the circuit renderer


```{code-cell} ipython3

from pytket.circuit.display import render_circuit_jupyter

render_circuit_jupyter(ghz_circ)
```

See also the [Circuit
construction](https://tket.quantinuum.com/user-manual/manual_circuit.html)
section of the user manual.

## Build a `Circuit` from a QASM file

Alternatively we can import a circuit from a QASM file using
[pytket.qasm](https://tket.quantinuum.com/api-docs/qasm.html). There
are also functions for generating a circuit from a QASM string or
exporting to a qasm file.

Note that its also possible to import a circuit from quipper using
[pytket.quipper](https://tket.quantinuum.com/api-docs/quipper.html)
module.


```{code-cell} ipython3

from pytket.qasm import circuit_from_qasm

w_state_circ = circuit_from_qasm("examples/qasm/W-state.qasm")
render_circuit_jupyter(w_state_circ)
```

## Import a circuit from qiskit (or other SDK)

Its possible to generate a circuit directly from a qiskit
`QuantumCircuit` using the
[qiskit_to_tk](https://tket.quantinuum.com/extensions/pytket-qiskit/api.html#pytket.extensions.qiskit.tk_to_qiskit)
function.


```{code-cell} ipython3

from qiskit import QuantumCircuit

qiskit_circ = QuantumCircuit(3)
qiskit_circ.h(range(3))
qiskit_circ.ccx(2, 1 ,0)
qiskit_circ.cx(0, 1)
print(qiskit_circ)
```


```{code-cell} ipython3

from pytket.extensions.qiskit import qiskit_to_tk

tket_circ = qiskit_to_tk(qiskit_circ)

render_circuit_jupyter(tket_circ)
```

Note that pytket and qiskit use opposite qubit ordering conventions. So
circuits which look identical may correspond to different unitary
operations.

Circuit conversion functions are also available for
[pytket-cirq](https://tket.quantinuum.com/extensions/pytket-cirq/),
[pytket-pennylane](https://tket.quantinuum.com/extensions/pytket-pennylane/),
[pytket-braket](https://tket.quantinuum.com/extensions/pytket-braket/)
and more.

## Using Backends

In pytket a `Backend` represents an interface to a quantum device or
simulator.

We will show a simple example of running the `ghz_circ` defined above
on the `AerBackend` simulator.


```{code-cell} ipython3

render_circuit_jupyter(ghz_circ)
```


```{code-cell} ipython3

from pytket.extensions.qiskit import AerBackend

backend = AerBackend()
result = backend.run_circuit(ghz_circ)
print(result.get_counts())
```

The `AerBackend` simulator is highly idealised having a broad gateset,
and no restrictive connectivity or device noise.

The Hadamard and CX gate are supported operations of the simulator so we
can run the GHZ circuit without changing any of the operations. For more
realistic cases a compiler will have to solve for the limited gateset of
the target backend as well as other backend requirements.

See the [Running on
Backends](https://tket.quantinuum.com/user-manual/manual_backend.html)
section of the user manual and the [backends example
notebook](https://tket.quantinuum.com/examples/backends_example.html)
for more.

```{toctree}
:caption: Manual
:maxdepth: 2

manual/manual_intro.rst
manual/manual_circuit.rst
manual/manual_backend.rst
manual/manual_compiler.rst
manual/manual_noise.rst
manual/manual_assertion.rst
manual/manual_zx.rst
```

```{toctree}
:caption: Example Notebooks
:glob: true
:maxdepth: 2

examples/circuit_construction/*
examples/backends/*
examples/circuit_compilation/*
examples/algorithms_and_protocols/*
```
146 changes: 0 additions & 146 deletions docs/index.rst

This file was deleted.

Loading