-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
+72
−79
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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} ?
There was a problem hiding this comment.
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.
{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).{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.[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.