@@ -83,6 +83,7 @@ given ansatz state by
83831 . Prepare the ansatz state.
84842 . Make a measurement which samples from some terms in H.
85853 . Goto 1.
86+
8687Note that one cannot always measure H directly (without
8788the use of quantum phase estimation), so one often relies
8889on 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
149150Now that we have some qubits, let us construct a ` Circuit ` on these qubits.
150151For 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
153154do this we write
154155``` python
155156circuit = cirq.Circuit()
@@ -234,9 +235,9 @@ over to act at the earliest `Moment` they can.
234235### Creating the Ansatz
235236
236237If 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
240241the append method generally takes an ` OP_TREE ` (or a ` Moment ` ). What is
241242an ` OP_TREE ` ? It is not a class but a contract. Roughly an ` OP_TREE `
242243is 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+
249251This last case yields a nice pattern for defining sub-circuits / layers,
250252define a function that takes in the relevant parameters and then
251253yields the operations for the sub circuit and then this can be appended
@@ -291,7 +293,7 @@ import random
291293def 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))
305307print (' row j fields: {} ' .format(jr))
306308print (' 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
371373circuit = cirq.Circuit()
372374circuit.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
410412set of the Google xmon architecture. However, for convenience,
411413the simulator attempts to automatically convert unknown
412414operations 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
417420Because the simulator is tied to the xmon gate set, the simulator
418421lives, 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
433436histogram of the counts of the measurement results. What are the
434437keys in the histogram counter? Note that we have passed in
435438the 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
439442For our optimization problem we will want to calculate the
440443value of the objective function for a given result run. One
0 commit comments