Skip to content

Commit 5331c34

Browse files
Apply suggestions from code review
Co-authored-by: Joel Pasvolsky <[email protected]>
1 parent 5e181a6 commit 5331c34

File tree

4 files changed

+65
-47
lines changed

4 files changed

+65
-47
lines changed

docs/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ OUTFOLDER = demos/out
1616
ADD_DOWNLOAD_BUTTONS ="$\
1717
\$$a$\
1818
:download:\`Download Python source code \<$$(basename $$1 .rst).py\>\`\n\n$\
19-
:download:\`Download as Jupyter notebook \<$$(basename $$1 .rst).ipynb\>\`\n"
19+
:download:\`Download as Jupyter Notebook \<$$(basename $$1 .rst).ipynb\>\`\n"
2020
2121
# Put it first so that "make" without argument is like "make help".
2222
help:
@@ -33,7 +33,7 @@ demos:
3333
cp -a $(DEMOFOLDER)/. $(OUTFOLDER)
3434
3535
find $(DEMOFOLDER) -name '*.py' -exec sh -c '$(JUPYTEXT) --to ipynb $$1 --output "$(OUTFOLDER)/$$(basename $$1 .py).ipynb"' sh {} \;
36-
find $(OUTFOLDER) -name '*.ipynb' -exec $(NBCONVERT) {} --to rst --output-dir=$(OUTFOLDER) --execute \;
36+
find $(OUTFOLDER) -name '*.ipynb' -exec $(NBCONVERT) {} --to rst --output-dir=$(OUTFOLDER) --execute --RegexRemovePreprocessor.patterns="^%" \;
3737
find $(OUTFOLDER) -name '*.rst' -exec sh -c 'sed -i "1s/^/.. _$$(basename $$1 .rst):\n\n/" $$1' sh {} \;
3838
3939
find $(OUTFOLDER) -name '*.rst' -exec sh -c 'sed -i -e $(ADD_DOWNLOAD_BUTTONS) $$1' sh {} \;

docs/demos/demos/intro_demo.py

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,39 @@
1313
# ---
1414

1515
"""
16-
# Beginner's guide to `dwave-gate`
16+
# Beginner's Guide to `dwave-gate`
1717
18-
With `dwave-gate` you can easily contruct and simulate quantum circuits. This tutorial will guide
19-
you through how to use the `dwave-gate` library to inspect different quantum gates, construct
20-
circuits out of them, and then simulate them using our performant state-vector simulator.
18+
`dwave-gate` lets you easily construct and simulate quantum circuits.
2119
22-
We begin by importing the necessary modules.
20+
This tutorial guides you through using the `dwave-gate` library to inspect,
21+
construct circuits from, and simulate quantum gates using a performant
22+
state-vector simulator.
23+
## Circuits and Operations
24+
Begin by importing the necessary modules.
25+
26+
* `Circuit` objects contain the full quantum circuit, with all the operations,
27+
measurements, qubits and bits.
28+
* Operations, or gates, are objects that contain information related to a
29+
particular operation, including its matrix representation, potential
30+
decompositions, and how to apply it to a circuit.
2331
"""
2432

2533
from dwave.gate.circuit import Circuit
2634
import dwave.gate.operations as ops
2735

2836
###############################################################################
29-
# The `Circuit` object contains the full quantum circuit, with all the operations, measurements,
30-
# qubits and bits. Operations, or gates, are objects that contain information related to that
31-
# specific operation, including its matrix representation, potential decompositions, and how to
32-
# apply it to a circuit. Via the `operations` module, here shortened to `ops`, a variety of quantum
33-
# gates can be accessed.
37+
# You can use the `operations` module (shortened above to `ops`) to access a
38+
# variety of quantum gates; for example, a Pauli X operator.
3439

3540
ops.X()
3641

3742
###############################################################################
38-
# As we can see, any operation can be instantiated without declaring which qubits it should be
39-
# applied to. We can also call the matrix property on either the gate class itself or on an instance
40-
# (i.e., an instantiated operation, which can contain additional parameters and/or qubit
41-
# information).
43+
# Notice above that an operation can be instantiated without declaring which qubits
44+
# it should be applied to.
45+
#
46+
# You can also call the matrix property on either the gate class itself or on an
47+
# instance (i.e., an instantiated operation, which can contain additional
48+
# parameters and qubit information).
4249

4350
ops.X.matrix
4451

@@ -50,36 +57,44 @@
5057
ops.RZ(4.2).matrix
5158

5259
###############################################################################
53-
# Operations are applied when either the class, or an instance of the class, is called within a
54-
# circuit's context. They can be applied to the circuit in several different ways, as detailed
55-
# below. Both qubits and parameters can be passed either as single values (if supported by the gate)
56-
# or as sequences. Note that different types of gates accept slightly different argument, although
57-
# the qubits can _always_ be passed as sequences via the keyword argument `qubits`.
58-
#
59-
# When instantiated within a circuit context, operations must always be applied to specific qubits
60-
# which in turn must be part of the circuits qubit register. The qubit register can be accessed via
61-
# the named tuple returned by the context manager as `q`, indexing into it to retrieve the
62-
# corresponding qubit.
60+
# ## Circuit Context
61+
# You apply operations by calling, within the context of a circuit, either a
62+
# class or an instance of a class.
63+
#
64+
# You can apply operations to a circuit in several different ways, as demonstrated
65+
# below. You can pass both qubits and parameters as either single values (when
66+
# supported by the gate) or sequences. Note that different types of gates accept
67+
# slightly different arguments, although you can _always_ pass the qubits as
68+
# sequences via the keyword argument `qubits`.
6369
#
64-
# Let's start by creating a circuit object with 2 qubits in its register, and apply a single X-gate
65-
# to the first qubit.
70+
# Always apply any operations you instantiate within a circuit context to
71+
# specific qubits in the circuit's qubit register. You can access the qubit
72+
# register via the named tuple returned by the context manager as `q`, indexing
73+
# into it to retrieve the corresponding qubit.
74+
# ## Registers
75+
# This example starts by creating a circuit object with two qubits in its
76+
# register and applying a single X gate to the first qubit.
6677

6778
circuit = Circuit(2)
6879

6980
with circuit.context as reg:
7081
ops.X(reg.q[0])
7182

7283
###############################################################################
73-
# We can access the qubit register via the `Circuit.qregisters` attribute, which currently should
74-
# contain a single qubit register with 2 qubits in it, but could contain any number of qubit
75-
# registers. If we'd want to, we could add another register with the `Circuit.add_qregister(n)`
76-
# method, where `n` would be the number of qubits in the new register, or add a qubit with
77-
# `Circuit.add_qubit()`, optinally passing a qubit object and/or a register to which to add it.
84+
# You can access the qubit register via the `Circuit.qregisters` attribute.
85+
#
86+
# In the current example, this attribute contains a single qubit register with
87+
# two qubits; it could contain any number of qubit registers. You can
7888
#
79-
# The registers tuple can also be unwrapped directly into a qubit register `q` (and a classical
80-
# register `c`, but we'll get into that later).
89+
# * add another register with the `Circuit.add_qregister(n)` method, where `n`
90+
# is the number of qubits in the new register
91+
# * add a qubit with `Circuit.add_qubit()`, optionally passing a qubit object
92+
# and/or a register to which to add it.
8193
#
82-
# Below follows a few examples for how to apply different gates to the circuit.
94+
# You can also unwrap the registers tuple into a qubit register `q` (and a classical
95+
# register `c`).
96+
#
97+
# ## Example: Applying Various gates to a Circuit
8398

8499

85100
circuit = Circuit(3)
@@ -109,24 +124,23 @@
109124
ops.Toffoli(q)
110125

111126
###############################################################################
112-
# Printing the above circuit gives us some general information about the circuit: the type of
113-
# circuit, the number of qubits/bits and the number of operations.
127+
# You can print a circuit to see general information about it: type of circuit,
128+
# number of qubits/bits, and number of operations.
114129

115130
print(circuit)
116131

117132
###############################################################################
118-
# We can also access the operations in the circuit via the `Circuit.circuit` attribute. This will
119-
# return a list of all operations which we can iterate over and print in the console.
133+
# You can also access operations in a circuit using the `Circuit.circuit`
134+
# attribute. The code below iterates over the returned list of all operations.
120135

121136

122137
for op in circuit.circuit:
123138
print(op)
124139

125140
###############################################################################
126-
# Note that e.g., CNOT and CX apply the exact same gate. CNOT is only an alias for CX (so they both
127-
# are labelled as CX in the circuit). There are also other aliases which you can spot either in the
128-
# source code for the operations module or read more about in the documentation.
129-
#
141+
# Note that the CNOT alias for the controlled NOT gate is labelled CX in the
142+
# circuit. You can find all operation aliases in the source code and documentation
143+
# for the operations module.
130144

131145
###############################################################################
132146
# ## Simulating a circuit

docs/demos/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Demos and examples
1+
Demos and Examples
22
==================
33

44
``dwave-gate`` demonstrations and examples.
@@ -7,7 +7,7 @@ Demos and examples
77
Tutorials
88
---------
99

10-
.. card:: Beginner's guide to ``dwave-gate``
10+
.. card:: Beginner's Guide to ``dwave-gate``
1111
:link: intro_demo
1212
:link-type: ref
1313

docs/requirements.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@ docutils==0.17.1
22
sphinx==5.3.0
33
sphinx-rtd-theme==1.1.1
44
sphinx_autodoc_typehints==1.19.5
5+
sphinx-design==0.4.1
6+
ipykernel==6.23.1
7+
matplotlib==3.71
58
nbconvert==7.4.0
6-
jupytext==1.14.5
9+
jupytext==1.14.5
10+
reno[sphinx]==3.5.0

0 commit comments

Comments
 (0)