Skip to content

Commit 0b3f347

Browse files
authored
Some tutorial fixes
1 parent 546d16a commit 0b3f347

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

docs/tutorial.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ given ansatz state by
8383
1. Prepare the ansatz state.
8484
2. Make a measurement which samples from some terms in H.
8585
3. Goto 1.
86+
8687
Note that one cannot always measure H directly (without
8788
the use of quantum phase estimation), so one often relies
8889
on the linearity of expectation values to measure parts of
@@ -148,8 +149,8 @@ have a row and column, indicating their position on a grid.
148149

149150
Now that we have some qubits, let us construct a `Circuit` on these qubits.
150151
For example, suppose we want to apply the Hadamard gate `H` to
151-
every qubit whose row index plus column index is even and `X` to
152-
every qubit whose row index plus column index is odd. To
152+
every qubit whose row index plus column index is even and an `X`
153+
gate to every qubit whose row index plus column index is odd. To
153154
do this we write
154155
```python
155156
circuit = cirq.Circuit()
@@ -234,9 +235,9 @@ over to act at the earliest `Moment` they can.
234235
### Creating the Ansatz
235236

236237
If you look closely at the circuit creation code above you will see that
237-
we applied the `append` method to both a `tuple` and a `list` (recall that
238-
in python one can use generator comprehensions in method calls).
239-
Inspecting the [code](/cirq/circuits/circuit.py) for append on sees that in
238+
we applied the `append` method to both a `generator` and a `list` (recall that
239+
in python one can use generator comprehensions in method calls).
240+
Inspecting the [code](/cirq/circuits/circuit.py) for append one sees that
240241
the append method generally takes an `OP_TREE` (or a `Moment`). What is
241242
an `OP_TREE`? It is not a class but a contract. Roughly an `OP_TREE`
242243
is anything that can be flattened, perhaps recursively, into a list
@@ -246,6 +247,7 @@ of operations, or into a single operation. Examples of an `OP_TREE` are
246247
* A tuple of `Operation`s.
247248
* A list of a list of `Operations`s.
248249
* A generator yielding `Operations`.
250+
249251
This last case yields a nice pattern for defining sub-circuits / layers,
250252
define a function that takes in the relevant parameters and then
251253
yields the operations for the sub circuit and then this can be appended
@@ -291,7 +293,7 @@ import random
291293
def rand2d(rows, cols):
292294
return [[random.choice([+1, -1]) for _ in range(rows)] for _ in range(cols)]
293295

294-
def fields(length):
296+
def random_instance(length):
295297
# transverse field terms
296298
h = rand2d(length, length)
297299
# links within a row
@@ -300,12 +302,12 @@ def fields(length):
300302
jc = rand2d(length - 1, length)
301303
return (h, jr, jc)
302304

303-
h, jr, jc = fields(3)
304-
print('transfer field: {}'.format(h))
305+
h, jr, jc = random_instance(3)
306+
print('transverse fields: {}'.format(h))
305307
print('row j fields: {}'.format(jr))
306308
print('column j fields: {}'.format(jc))
307309
# prints something like
308-
# transfer field: [[-1, 1, -1], [1, -1, -1], [-1, 1, -1]]
310+
# transverse fields: [[-1, 1, -1], [1, -1, -1], [-1, 1, -1]]
309311
# row j fields: [[1, 1, -1], [1, -1, 1]]
310312
# column j fields: [[1, -1], [-1, 1], [-1, 1]]
311313
```
@@ -366,7 +368,7 @@ def one_step(h, jr, jc, x_half_turns, h_half_turns, j_half_turns):
366368
yield rot_z_layer(h, h_half_turns)
367369
yield rot_11_layer(jr, jc, j_half_turns)
368370

369-
h, jr, jc = fields(3)
371+
h, jr, jc = random_instance(3)
370372

371373
circuit = cirq.Circuit()
372374
circuit.append(one_step(h, jr, jc, 0.1, 0.2, 0.3))
@@ -410,9 +412,10 @@ Currently Cirq ships with a simulator tied strongly to the gate
410412
set of the Google xmon architecture. However, for convenience,
411413
the simulator attempts to automatically convert unknown
412414
operations into XmonGates (as long as the operation specifies
413-
a matrix or decomposition). This can in principle simulate
414-
any circuit that has gates that implement one and two qubit
415-
`KnownMatrix` gates. Future release will expand these simulators.
415+
a matrix or a decomposition into XmonGates). This can in
416+
principle allows us to simulate any circuit that has gates
417+
that implement one and two qubit `KnownMatrix` gates.
418+
Future releases of Cirq will expand these simulators.
416419

417420
Because the simulator is tied to the xmon gate set, the simulator
418421
lives, in contrast to core Cirq, in the `cirq.google` module.
@@ -433,8 +436,8 @@ Note that we have run the simulation 100 times and produced a
433436
histogram of the counts of the measurement results. What are the
434437
keys in the histogram counter? Note that we have passed in
435438
the order of the qubits. This ordering is then used to translate
436-
the order of the measurement results to a register using big
437-
endian representation.
439+
the order of the measurement results to a register using a
440+
[big endian](https://en.wikipedia.org/wiki/Endianness) representation.
438441

439442
For our optimization problem we will want to calculate the
440443
value of the objective function for a given result run. One

0 commit comments

Comments
 (0)