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

Frontend/Backend docs clean up #2124

Merged
merged 4 commits into from
Dec 14, 2023
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
5 changes: 2 additions & 3 deletions docs/source/examples/cirq-ibmq-backends.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down Expand Up @@ -39,7 +39,6 @@ USE_REAL_HARDWARE = False

**Note:** When `USE_REAL_HARDWARE` is set to `False`, a classically simulated noisy backend is used instead of a real quantum computer.

(examples/cirq-ibmq-backends/setup-defining-a-circuit)=
## Setup: Defining a circuit in Cirq

+++
Expand Down Expand Up @@ -70,7 +69,7 @@ the expectation value to mitigate. This function will:
2. Run the circuit.
3. Convert from raw measurement statistics (or a different output format) to an expectation value.

For information on how to define more advanced executors, see the {ref}`Executors <guide/executors/executors>` section of the Mitiq user guide.
For information on how to define more advanced executors, see the {doc}`../guide/executors` section of the Mitiq user guide.
Copy link
Member

Choose a reason for hiding this comment

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

What is the main difference between {ref} and {doc} ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Great question! I had to figure that out too.

  • The {ref} role is an all-purpose link-creating-tool for creating references to documents and labeled sections of documents (e.g. an anchor within a specific page).
  • The {doc} role is specifically made for referencing local documents only (no external documents, and no anchors/sections/equations/images/etc). One thing to note here with {doc}, is that if we do not pass text in for the link, it uses the title of the page we are linking to.
  • It's worth mentioning that both of these can be achieved with markdown links [text](link) as well, so why bother with either of these roles? When using {ref} and {doc}, we are providing sphinx with more information than it would get otherwise, and is able to some magic and make our lives easier. I'm not totally clear on what, but I think it makes refactoring easier as sphinx will know that specific references are broken using this syntax.

As for why sphinx has both {doc} and {ref}, I'm not sure. It does seem a bit redundant to me. Why not just have the more powerful one? That said, I always like the idea of using the simplest solution to a problem, and that includes using the simplest available tool.


We define the executor function in the following code block. Because we are using IBMQ backends, we first load our account.

Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/ddd_tutorial.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/ggi_summer_school_solved.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ orphan: true

jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.12.0
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/ggi_summer_school_unsolved.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.12.0
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/hamiltonians.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.4
Expand Down
3 changes: 1 addition & 2 deletions docs/source/examples/ibmq-backends.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down Expand Up @@ -43,7 +43,6 @@ from mitiq.interface.mitiq_qiskit.qiskit_utils import initialized_depolarizing_n
USE_REAL_HARDWARE = False
```

(examples/ibmq-backends/setup-defining-a-circuit)=
## Setup: Defining a circuit

+++
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/learning-depolarizing-noise.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/maxcut-demo.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.4
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/molecular_hydrogen.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/pec_tutorial.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.12.0
Expand Down
4 changes: 1 addition & 3 deletions docs/source/examples/pennylane-ibmq-backends.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand All @@ -23,8 +23,6 @@ In this tutorial we will cover how to use Mitiq in conjunction with [PennyLane](

+++

(examples/ibmq-backends-pennylane/setup-defining-a-circuit)=

## Setup: Defining a circuit

+++
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/rshadows_tutorial.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/shadows_tutorial.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/simple-landscape-cirq.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.4
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/simple-landscape-pennylane.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
jupytext:
formats: md:myst,ipynb
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.23.4
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/simple-landscape-qiskit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
jupytext:
formats: md:myst,ipynb
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/examples/zne-braket-ionq.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/cdr-1-intro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/cdr-2-use-case.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/cdr-3-options.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/cdr-4-low-level.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/cdr-5-theory.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/ddd-1-intro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/ddd-2-use-case.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.10.3
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/ddd-3-options.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/ddd-4-low-level.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/ddd-5-theory.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
3 changes: 1 addition & 2 deletions docs/source/guide/executors.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.1
Expand All @@ -11,7 +11,6 @@ kernelspec:
name: python3
---

(guide/executors/executors)=
# Executors

+++
Expand Down
30 changes: 16 additions & 14 deletions docs/source/guide/frontends-backends.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.4
Expand All @@ -11,12 +11,14 @@ kernelspec:
name: python3
---


# Frontends and Backends

In short, a frontend is the tool used to write a quantum program, and a backend is the tool that executes said program.
What follows is more detailed information as to how these concepts are handled in Mitiq.
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

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

Good!


## Mitiq-specific types

There are a number of types that are specific to Mitiq, the most important being `mitiq.QPROGRAM` and {class}`.QuantumResult`.
There are a number of types that are specific to Mitiq, the most important being `mitiq.QPROGRAM` and `mitiq.QuantumResult`.
These types are both unions of a number of other types that make it easier to annotate other functions in Mitiq, independent of the user choice of frameworks.
The Mitiq-defined type `mitiq.QPROGRAM` uses any of the program types from the supported platforms that are installed on the system.
For example, if you haven't installed PyQuil, then even though Mitiq supports it, you will not be able to use PyQuil programs in Mitiq until it is installed.
Expand All @@ -25,9 +27,9 @@ For example, if you haven't installed PyQuil, then even though Mitiq supports it
Mitiq only supports non-adaptive quantum programs without classical control flow or mid-circuit measurements. This class of programs is more commonly known as _circuits_ by many other tools and frameworks in quantum computing.
```

The Mitiq-defined type {class}`.QuantumResult` is a union of the types defined in `mitiq.typing` that are used to represent the results of running a quantum program.
The Mitiq-defined type `mitiq.QuantumResult` is a union of the types defined in `mitiq.typing` that are used to represent the results of running a quantum program.
For example, for hardware, the result can be a list of bitstrings (representing raw measurements) or an expectation value expressed as a real number.
For simulators, more information can be made available like the resulting density matrix, which is a valid object of the {class}`.QuantumResult` type.
For simulators, more information can be made available like the resulting density matrix, which is a valid object of the `mitiq.QuantumResult` type.

## Frontends

Expand All @@ -44,16 +46,16 @@ mitiq.SUPPORTED_PROGRAM_TYPES.keys()
with Cirq being used for the internal implementations of the mitigation methods.
There is also frontend support for any circuit description that complies with the OpenQASM 2.0 standard.

With any of these frontends (with the exception of Cirq), the circuit representation will be converted internally to a Cirq circuit object with the relevant conversion methods in {py:mod}`mitiq.interface` for each frontend.
With any of these frontends (with the exception of Cirq), the circuit representation will be converted internally to a Cirq circuit object with the relevant conversion methods in `mitiq.interface` for each frontend.
For example, you can use {func}`mitiq.interface.mitiq_braket.conversions.from_braket()` to convert a Braket circuit to a Cirq circuit.

Examples for using each of the frameworks to represent the input to a mitigation method are linked below.

- {ref}`Cirq <examples/cirq-ibmq-backends/setup-defining-a-circuit>`
- {ref}`Qiskit <examples/ibmq-backends/setup-defining-a-circuit>`
- {ref}`PyQuil <examples/pyquil_demo>`
- {ref}`PennyLane <examples/ibmq-backends-pennylane/setup-defining-a-circuit>`
- {ref}`Braket <examples/braket_mirror_circuit/define-the-circuit>`
- {doc}`Cirq <../examples/cirq-ibmq-backends>`
- {doc}`Qiskit <../examples/ibmq-backends>`
- {doc}`PyQuil <../examples/pyquil_demo>`
- {doc}`PennyLane <../examples/pennylane-ibmq-backends>`
- {doc}`Braket <../examples/braket_mirror_circuit>`

## Backends

Expand All @@ -64,12 +66,12 @@ Backends are used by Mitiq in the {class}`.Executor` class to run the mitigated
## Executing programs

Once you have selected a frontend and backend combination that are compatible, the next step is to set up the execution of a quantum program.
The {class}`.Executor` class is used to execute quantum programs, and is constructed by providing a function with the following signature: `mitiq.QPROGRAM` -> {class}`.QuantumResult`.
For more information on executors, see the {doc}`Executors <executors>` section of this guide.
The {class}`.Executor` class is used to execute quantum programs, and is constructed by providing a function with the following signature: `mitiq.QPROGRAM -> mitiq.QuantumResult`.
For more information on executors, see the {doc}`executors` section of this guide.

### Batch execution of programs

You can also use the {class}`.Executor` class to execute a batch of quantum programs all in one go.
To perform batched execution, you can use the same mitiq.Executor class constructor and pass a function with the following signature: `T[mitiq.QPROGRAM] -> T[{class}".QuantumResult"]` where T is `Sequence`, `List`, `Tuple`, or `Iterable`.

For more information on batched executors and example code, see the {doc}`Executors <executors>` section of this guide.
For more information on batched executors and example code, see the {doc}`executors` section of this guide.
2 changes: 1 addition & 1 deletion docs/source/guide/glossary.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/observables.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guide/pec-1-intro.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
jupytext:
text_representation:
extension: .myst
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.11.1
Expand Down
Loading
Loading