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

Conversation

CalMacCQ
Copy link
Collaborator

@CalMacCQ CalMacCQ commented Aug 29, 2024

Description

Porting the manual source to MyST to allow easier use of the MyST library. We now use the MyST-nb library for building both the manual and examples pages. This ensures visual consistency of the example snippets.

Read the docs on markdown only notebooks -> https://myst-nb.readthedocs.io/en/latest/authoring/text-notebooks.html

Instructions for building the html locally -> https://github.com/CQCL/pytket-docs/tree/main/docs#building-the-docs (let me know if these are unclear)

I'd also recommend using the MyST VSCode extension in review -> https://marketplace.visualstudio.com/items?itemName=ExecutableBookProject.myst-highlight

Preview

Screenshot 2024-08-29 at 17 00 23

Most of the conversion can be done in an automated way using rst-to-myst

rst2myst convert docs/manual/*.rst

This works for just about everything apart from .. jupyter-execute:: directives which I rsubstitue with equivalent `

{code-cell} ipython3

sytax with VSCode find and replace.

Example replacement for jupyter-execute directives

```{code-cell} ipython3

from pytket import Circuit
from pytket.extensions.qiskit import AerBackend
from pytket.utils import probs_from_counts

circ = Circuit(2, 2)
circ.H(0).X(1).measure_all()
backend = AerBackend()
compiled_circ = backend.get_compiled_circuit(circ)

handle = backend.process_circuit(compiled_circ, n_shots=2000)
counts = backend.get_result(handle).get_counts()
print(counts)

print(probs_from_counts(counts))

Example replacement for jupyter-input/output directives

Input (truncated)

```{code-cell} ipython3
---
tags: [skip-execution]
---

from pytket import Circuit
from pytket.extensions.qiskit import IBMQBackend
from pytket.utils import expectation_from_counts

backend = IBMQBackend("ibmq_quito")

state = Circuit(3)
state.H(0).CX(0, 1).CX(1, 2).X(0)

Output

(1.2047999999999999-0.0015000000000000013j)

Example of a cell which raises an error

```{code-cell} ipython3
---
tags: [raises-exception]
---

from pytket import Circuit, Qubit, Bit

circ = Circuit()
# set up a circuit with qubit a[0]
circ.add_qubit(Qubit("a", 0))

# rejected because "a" is already a qubit register
circ.add_bit(Bit("a", 1))

Related issues

closes #366

@CalMacCQ CalMacCQ marked this pull request as draft August 29, 2024 12:52
@CalMacCQ CalMacCQ marked this pull request as ready for review August 29, 2024 14:07
Comment on lines 51 to 55
```

[NoClassicalControlPredicate, NoFastFeedforwardPredicate, NoMidMeasurePredicate, NoSymbolsPredicate, GateSetPredicate:{ U1 noop U2 CX Barrier Measure U3 }, DirectednessPredicate:{ Nodes: 5, Edges: 8 }]
[NoClassicalControlPredicate, NoFastFeedforwardPredicate, GateSetPredicate:{ CU1 CZ CX Unitary2qBox Sdg U1 Unitary1qBox SWAP S U2 CCX Y U3 Z X T noop Tdg Reset H }]
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra line and tabs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting these formatting issues.

I fixed them in ad08277

Copy link
Contributor

@willsimmons1465 willsimmons1465 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done! Some of the code cells are inconsistently formatted with whitespace, so the only changes needed are going through to fix that.

I'm presuming from the existing content using MyST that it fully works with CI, i.e. if a cell fails to run CI would report an error?

@CalMacCQ
Copy link
Collaborator Author

CalMacCQ commented Sep 2, 2024

Nicely done! Some of the code cells are inconsistently formatted with whitespace, so the only changes needed are going through to fix that.

Appreciate the review! I'll fix the formatting issues shortly.

I'm presuming from the existing content using MyST that it fully works with CI, i.e. if a cell fails to run CI would report an error?

Yes indeed. The sphinx build should error if the code cell raises and error and cause a C.I. failure.

The C.I. has some issues at the moment which should be fixed by #372 . After that is merged I can deliberately make a cell fail as a test to see if its picked up in C.I.

@CalMacCQ
Copy link
Collaborator Author

CalMacCQ commented Sep 3, 2024

Added some code which errored out in 0bb46c3 and this caused C.I. to fail with a CellExecutionError which is reassuring.

Comment on lines 664 to 669
```{code-cell} ipython3

from pytket.utils.stats import gate_counts

gate_counts(circ)
```
Copy link
Contributor

@willsimmons1465 willsimmons1465 Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this one in the last review, sorry

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Will, fixed in 4b7448b

Copy link
Collaborator Author

@CalMacCQ CalMacCQ Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a search to try and rule out other indentation issues, didn't find any but maybe the search pattern could be wrong.

Copy link
Contributor

@willsimmons1465 willsimmons1465 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to go! Thanks for sorting this out

@CalMacCQ CalMacCQ merged commit 5b146a6 into main Sep 5, 2024
1 check passed
@CalMacCQ CalMacCQ deleted the docs/use_myst branch September 5, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port manual source material to MyST markdown
2 participants