Quantum computing in my book Dancing with Python

My new book, Dancing with Python: Learn Python software development from scratch and get started with quantum computing, is now available from Amazon and other sources, and I recently posted the full table of contents. Though it is an introduction to Python, albeit with discussions of several advanced modules, it provides a unified approach with quantum computing.

My approach is described in the Preface:

How do you learn to code in this new world that involves both classical and quantum hardware?

One way to do it is to learn classical computing by itself. This is the traditional way of doing it, using a language such as C, C++, JavaScript, Java, Go, or Python. Along the way, you would learn how to use extra functionality in libraries of code along with the programming tools or from a third-party provider. Examples of these are the C++ Standard Library; the Java Platform, Enterprise Edition; the Python Standard Library; or the thousands of Python packages listed in the Python Package Index.

Once you have the philosophy, syntax, structure, and idioms of the classical programming language understood, you then learn quantum computing on top of that. For example, you could use the Qiskit open source quantum computing software development kit (SDK) along with Python. These mesh together and operate exceptionally well. Thousands of people are already Qiskit coders. If you know Python, this is a great approach.

But what if you are learning to code or have only a small amount of experience? What if I could offer you the chance to learn classical and quantum computing in a unified manner? Would it be useful if I could help you understand the concepts of both so that you don’t see them as different disciplines? That’s what I do in this book.

Teaching approach in Dancing with Python

I talk about aspects of quantum computing throughout the book and in many places I provide pointers to sections in my quantum computing book Dancing with Qubits. That book is not a prerequisite for Dancing with Python, but the referenced sections will help you learn more about the topics if you wish to go deeper.

I first talk about qubits, “quantum bits”, in section 1.11. The main chapters that discuss quantum computing are 9 and 11:


9 Understanding Gates and Circuits

Classical computers use logical gates to manipulate bits. Using them, we assemble circuits to implement more complicated processes like addition and multiplication. Eventually, we get all the software that runs on computers everywhere.

Quantum computers use qubits to significantly extend the power of bits, as we saw in section 1.11. We assemble these into quantum circuits to implement algorithms.

There is a strong connection between classical and quantum computing, and a quantum computing system is a classical computing system extended with one or more quantum devices. These devices are the physical implementations of qubits and the software and hardware that control them.

This chapter examines bits and qubits, gates that operate upon them, and how we assemble them into circuits.

9.1 The software stack
9.2 Boolean operations and bit logic gates
9.3 Logic circuits
9.4 Simplifying bit expressions
9.5 Universality for bit gates
9.6 Quantum gates and operations
9.7 Quantum circuits
9.8 Universality for quantum gates
9.9 Summary


11 Searching for the Quantum Improvement

By considering new approaches and getting clever, we can develop classical algorithms that are faster than you might have expected. Using quantum techniques, we can go a step further: perform some operations faster than seems possible.

This chapter compares classical and quantum search techniques to see how extending our basic information unit from the bit to the qubit can show remarkable improvements. Note that I only discuss mainstream “universal” quantum computing and not limited-purpose systems that perform operations like simulated annealing.

11.1 Classical searching
11.2 Quantum searching via Grover
11.3 Oracles
11.4 Inversion about the mean
11.5 Amplitude amplification
11.6 Searching over two qubits
11.7 Summary


If you wish to learn more about quantum computing after reading this book, I suggest you look at

Dancing with Qubits: Quantum Computing and Finance update

In section 1.5 of my quantum computing book Dancing with Qubits, I discuss potential applications of the technology to financial services. An excellent survey article by my IBM Quantum colleagues is now on arXiv that updates and goes into much greater detail than what I covered.

“Quantum computing for Finance: state of the art and future prospects” by Daniel J. Egger, Claudio Gambella, Jakub Marecek, Scott McFaddin, Martin Mevissen, Rudy Raymond, Andrea Simonetto, Stefan Woerner, and Elena Yndurain has this abstract:

This paper outlines our point of view regarding the applicability, state of the art, and potential of quantum computing for problems in finance. We provide an introduction to quantum computing as well as a survey on problem classes in finance that are computationally challenging classically and for which quantum computing algorithms are promising. In the main part, we describe in detail quantum algorithms for specific applications arising in financial services, such as those involving simulation, optimization, and machine learning problems. In addition, we include demonstrations of quantum algorithms on IBM Quantum back-ends and discuss the potential benefits of quantum algorithms for problems in financial services. We conclude with a summary of technical challenges and future prospects.

I highly recommend it.

How to listen to my Packt podcast about quantum computing on your phone

The Packt podcast with me talking about my quantum computing and my book Dancing with Qubits is now available. Here is how you can listen to it on your iPhone. I presume the directions for Android are similar.

Podcasts screenshotOpen the Podcasts app on your phone. Click the magnifying glass and type Packt into the search field. Press Search. Press the packt podcast in the search results.
Podcasts screenshotPress The Packt Podcast under the listing of Shows. The logo is white text that says Packt on an orange background.
Podcasts screenshotUnder Episodes, look for Quantum computing, explained!. You may need to scroll down. It appeared on February 10, 2020.

SoundCloud Packt podcast with me about Dancing with Qubits and #QuantumComputing

Please join Stacy Munro, Richard Gall, and me for a podcast discussion about my new book about quantum computing, Dancing with Qubits.

https://soundcloud.com/packt-podcasts/quantum-computing-explained-ibms-robert-sutor-talks-about-the-new-paradigm-on-the-horizon

The Amazon Kindle version of Dancing with Qubits is now available!

Page from Kindle version of Dancing with QubitsI’m pleased to announce that the Amazon Kindle version of my quantum computing book Dancing with Qubits is now available!

This book provides a comfortable and conversational introduction to quantum computing. I take you through the mathematics you need at a pace that allows you to understand not just “what” but also “why.” When we get to quantum computing, concepts like superposition and entanglement are shown to be natural ideas building on what we’ve already seen, and then illustrated via gates, circuits, and algorithms.

Throughout the book, I highlight important results, provide questions to answer, and give links to references where you can learn more. This allows the book to be used for self-study or as a textbook.

Important ideas like Quantum Volume are explained to give you a head start for reading more advanced texts and research papers. I provide many references to related content in math, physics, quantum computing, AI, and financial services. Dancing with Qubits concludes with questions for you to think about and ask experts so that you can gauge progress in the field over the next few years.

Features of the Kindle edition

Page from the book Dancing with Qubits

  • The text will get larger or smaller as you wish and you can change to a font that is comfortable for you to read.
  • There are links throughout the book to other sections and the references in each chapter.
  • Many of the references have links to external sources, such as arxiv or Nature for research papers.
  • The content is in color, if your Kindle device supports it.
  • You can search for terms throughout the book.
  • I’ve maximized the number of mathematical expressions that are expressed textually (see below) to improve the reading experience.

The print version of Dancing with Qubits still has the full, rich mathematical formatting, albeit in black and white. In essence, whether you choose the print or Kindle version, the content is consistent and the formatting is the best I know how to produce for each medium.

Technical Notes

Here are a few comments about the production of the Kindle version, in case you are interested.

Page from the book Dancing with Qubits

  • The original content for Dancing with Qubits is in LaTeX. From that I can produce the black and white print version, a color PDF eBook, and an epub3 file from which the Amazon Kindle and several other MOBI eBook versions are created.
  • I used make4ht and tex4ht to go from the LaTeX source files to HTML. While very powerful, the documentation is scarce and I spent many hours trying to figure how to make things work and then writing sed and Python scripts to fix things that were not quite right.
  • I wrote Python scripts to create the various files needed for epub3, such as opf and navigation, and to break the 30,000+ line HTML file into smaller XHTML files. I used tidy several times to format the HTML and XHTML.
  • The epub3 validators in several free epub3 editing apps either skipped problems entirely or gave false negatives. I found pagina EPUB-Checker to be the best software for validation.
  • I wanted to maximize the amount of HTML formatting I could use and MathML is not available in a practical sense for all eBook formats. tex4ht produced very inconsistent results. So while I could express $x_2$ as x2 in the text without extra fonts, more two-dimensional objects like matrices had to be represented using images. I created macros to produce the right format based on what kind of document I was trying to produce.
  • I used tikz/pgf and quantikz for the figures, especially the quantum circuit diagrams. I externalized the figures as JPEG images. It took quite a bit to figure out how to get them to be the right size for the Kindle version.
  • Some math expressions in the book and chapter tables of contents have weird spacing if they involve subscripts or superscripts. This is an artifact of the Kindle software. This did not happen, for example, when I viewed the book in the Apple Books app.

Some practical things you can do to learn about quantum computing

People often ask me “Where should I get started in order to learn about quantum computing?”. Here are several steps you can take. I work for IBM, so things I link to will often be to the IBM Quantum program. Also, I acknowledge that several of the links and videos toward the beginning involve me, but we’ll get through those quickly.

Watch some introductory videos

If you only watch one video, watch this one from WIRED with Talia Gershon:

This one with me is from early 2019 and discussed the IBM Q System One:

Finally, this video from CNBC with Professor Scott Aaronson of the University of Texas Austin, Martin Reynolds of Gartner, and me brings things up to date in January, 2020. Note that I personally do not support many of the statements about “Quantum Supremacy” (horrible label, supercomputers do have massive amounts of storage, off-by-15-million-percent math error):

Get a book

If you are really just getting started and want to systematically work through the required math at an easy and conversational pace, my book Dancing with Qubits should prepare you for more advanced material and give you a start to reading research papers. (Shameless self-plug.)

If you are a hard core physics and/or computer science person, you want to have Quantum Computation and Quantum Information: 10th Anniversary Edition 10th Anniversary ed. Edition by Michael A. Nielsen and Issac L. Chuang in your library. It’s a little old by now, but if you want to end up doing quantum computing research, you will likely have to become very familiar and comfortable with the contents. Other books to consider are Quantum Computing: A Gentle Introduction (good on algorithms, “gentle” is subjective!) and Quantum Computing for Computer Scientists (a bit dated and make sure you get a copy of the errata).

Play a game

Hello Quantum is available for Apple iOS and Android and will teach you the basics of how quantum gates and circuits work.

Hello Quantum screen shots

Build and run circuits with a real quantum computer

Quantum simulators have their place for basic education, experimentation, and debugging. Note, though, that a quantum simulator is to real quantum computer hardware as a TV console flight simulator is to a real plane. If you want a job as a pilot, I would prefer you knew how to fly an actual airplane.

The easiest way to get started without writing code is with the IBM Quantum Composer within the IBM Quantum Experience.

The IBM Quantum Experience has over 200,000 registered users, so you’ll be joining a very large community of beginner, intermediate, and advanced users.

IBM Quantum Composer

Learn Python

If you are going to write quantum computing code, learn Python. As I write this, the latest version is 3.8. You want Python 3, not Python 2.

Learn Jupyter Notebooks

This is the modern way of developing full documents with interactive code, executions, graphics, videos, and visualizations. It’s used within the IBM Quantum Experience but also many other computational and AI applications. You are mainly interested in how to use it through a browser, not how to run and maintain the console.

Website (introductory): Introduction to Jupyter Notebooks

Write quantum computing code in Qiskit

Qiskit is the leading open source platform for developing quantum computing code and applications. It’s available on Github and available under the Apache 2,0 license. It’s had over 300,000 downloads but I’m recommending you use it through your browser on the IBM Cloud. As with the Composer, it is available through the IBM Quantum Experience.

Whether you want to download Qiskit or use it online, the easiest way to get get started is to watch the series of videos by Abe Asfaw.

From there, you can watch the other videos and also learn about the Qiskit Community.

At this point you are ready to work your way through the online open source Learn Quantum Computing through Qiskit.Open source Qiskit textbook

Dancing With Qubits, First Edition: What about the eBook?

Cover of the book Dancing with QubitsYesterday was very exciting because I received my first printed copy of the book. There’s just something about holding a physical, printed book that you’ve labored over for many months. Others are starting to get their copies too, and I hope that within a couple of weeks everyone who pre-ordered the print version will have copies in hand.

What if you ordered the eBook? Wasn’t that an option on Amazon? Why isn’t it listed there now? Why was your Kindle eBook order canceled?

The original plan was to provide the eBook in a PDF-like, print replica format that was in color and had active links within and beyond the book. You can still purchase this eBook at the Packt Publishing website.

As for Amazon, let’s just say that they ultimately wanted a reflowable version of the book rather than a fixed format version. As I’ve mentioned before, this presents many challenges to producing beautiful math. The reflowable format allows you to change the font and font size you use on your Kindle or in the Kindle app. It makes it easier to read on small devices. I understand the value.

Hence, I’m now working to create a reflowable version with one guiding principle: as much as possible, I must have a single source for the book that will produce future versions of the printed, fixed-format PDF, and reflowable formats

Here’s the strategy:

  • Use tools like make4ht to translate the original LaTeX into HTML. Convert the HTML into MOBI and EPUB3 formats with a minimal amount of hand editing.
  • Use standard HTML entities and CSS for as much of the in-sentence math as possible.
  • Avoid using extra fonts within the HTML.
  • Use automatically-generated PNG files for any other math.
  • Use automatically-generated SVG and PNG files for figures coming from LaTeX tikz environments. (This is not working at all right now.)
  • Use new macros for the math to produce either LaTeX or HTML versions.
  • Use a small Python program I wrote to convert simple math to new markup using the new macros.

Screen shot of the VSCode editor

There is much work to do but things are looking promising. I can’t now give you any estimated time of arrival for the Kindle reflowable version or any guarantee that it will arrive eventually, but it’s my strong intention to make it happen. There are unknown unknowns yet to be discovered.

In the meanwhile, as I mentioned above, you can get a PDF-like digital version of the book from Packt.

A final point: despite several people staring at the text, a few errors crept in. These are mostly typos or omitted words. I’m keeping track of these on the corrections and clarifications page for the book. I incorporate these fixes into the text as they are discovered and I hope that future versions of the book, printed and digital, include them.


Previous: What’s in the book

In December, 2019, Packt Publishing published my book Dancing with Qubits: How quantum computing works and how it can change the world. Through a series of blog entries, I talk about the writing and publishing process, and then about the content.

Dancing With Qubits, First Edition: What’s in the book

Cover of the book Dancing with Qubits

This morning I awoke to a very nice email from Tom Jacob, the Project Editor for my book at Packt Publishing. He said, in part,

We were able to successfully ship the book to our printers. …
Congratulations on achieving this milestone!

As I’ve mentioned before, my book was prepared using LaTeX and not Microsoft Word. I gave the publishers what was essentially the “camera-ready” PDF file from which to print. Hence the part about being able to “successfully ship” the book. In fact, I sent them the final PDF last night. I thought I was done on Friday, but yesterday I noticed an out-of-place citation in the section on the Bloch sphere and did a quick fix.

Now that the book is in production and there is absolutely nothing else I can do to fiddle with it, I’m going to show you the table of contents. I tried to have fun with some of the chapter and section titles. Once the book is published, I’ll be happy to discuss why I included this content or that.


Dancing with Qubits
How quantum computing works and
how it can change the world

Preface ix

1  Why Quantum Computing? 1

1.1 The mysterious quantum bit 2

1.2 I’m awake! 4

1.3 Why quantum computing is different 7

1.4 Applications to artificial intelligence 9

1.5 Applications to financial services 15

1.6 What about cryptography? 18

1.7 Summary 21

I  Foundations 23

2  They’re Not Old, They’re Classics 25

2.1 What’s inside a computer? 26

2.2 The power of two 32

2.3 True or false? 33

2.4 Logic circuits 36

2.5 Addition, logically 39

2.6 Algorithmically speaking 42

2.7 Growth, exponential and otherwise 42

2.8 How hard can that be? 44

2.9 Summary 55

3  More Numbers than You Can Imagine 57

3.1 Natural numbers 58

3.2 Whole numbers 60

3.3 Integers 62

3.4 Rational numbers 66

3.5 Real numbers 73

3.6 Structure 88

3.7 Modular arithmetic 94

3.8 Doubling down 96

3.9 Complex numbers, algebraically 97

3.10 Summary 103

4  Planes and Circles and Spheres, Oh My 107

4.1 Functions 108

4.2 The real plane 111

4.3 Trigonometry 122

4.4 From Cartesian to polar coordinates 129

4.5 The complex “plane†129

4.6 Real three dimensions 133

4.7 Summary 134

5  Dimensions 137

5.1 R2 and C1 139

5.2 Vector spaces 144

5.3 Linear maps 146

5.4 Matrices 154

5.5 Matrix algebra 166

5.6 Cartesian products 176

5.7 Length and preserving it 177

5.8 Change of basis 189

5.9 Eigenvectors and eigenvalues 192

5.10 Direct sums 198

5.11 Homomorphisms 200

5.12 Summary 204

6  What Do You Mean “Probably� 205

6.1 Being discrete 206

6.2 More formally 208

6.3 Wrong again? 209

6.4 Probability and error detection 210

6.5 Randomness 212

6.6 Expectation 215

6.7 Markov and Chebyshev go to the casino 217

6.8 Summary 221

II  Quantum Computing 223

7  One Qubit 225

7.1 Introducing quantum bits 226

7.2 Bras and kets 229

7.3 The complex math and physics of a single qubit 234

7.4 A non-linear projection 241

7.5 The Bloch sphere 248

7.6 Professor Hadamard, meet Professor Pauli 253

7.7 Gates and unitary matrices 265

7.8 Summary 266

8  Two Qubits, Three 269

8.1 Tensor products 270

8.2 Entanglement 275

8.3 Multi-qubit gates 283

8.4 Summary 295

9  Wiring Up the Circuits 297

9.1 So many gates 298

9.2 From gates to circuits 299

9.3 Building blocks and universality 305

9.4 Arithmetic 315

9.5 Welcome to Delphi 322

9.6 Amplitude amplification 324

9.7 Searching 330

9.8 The Deutsch-Jozsa algorithm 338

9.9 Simon’s algorithm 346

9.10 Summary 354

10  From Circuits to Algorithms 357

10.1 Quantum Fourier Transform 358

10.2 Factoring 369

10.3 How hard can that be, again 379

10.4 Phase estimation 382

10.5 Order and period finding 388

10.6 Shor’s algorithm 396

10.7 Summary 397

11  Getting Physical 401

11.1 That’s not logical 402

11.2 What does it take to be a qubit? 403

11.3 Light and photons 406

11.4 Decoherence 415

11.5 Error correction 423

11.6 Quantum Volume 429

11.7 The software stack and access 432

11.8 Simulation 434

11.9 The cat 439

11.10 Summary 441

12  Questions about the Future 445

12.1 Ecosystem and community 446

12.2 Applications and strategy 447

12.3 Access 448

12.4 Software 449

12.5 Hardware 450

12.6 Education 451

12.7 Resources 452

12.8 Summary 453

Afterword 455

Appendices 458

A  Quick Reference 459

A.1 Common kets 459

A.2 Quantum gates and operations 460

B  Symbols 463

B.1 Greek letters 463

B.2 Mathematical notation and operations 464

C  Notices 467

C.1 Creative Commons Attribution 3.0 Unported (CC BY 3.0) 467

C.2 Creative Commons Attribution-NoDerivs 2.0 Generic (CC BY-ND 2.0) 468

C.3 Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) 468

C.4 Los Alamos National Laboratory 469

C.5 Trademarks 469

D  Production Notes 471

Other Books You May Enjoy 473

Index 477


Changes, clarifications, and errata


Previous: Drawing quantum circuits
Next: What about the eBook?

In December, 2019, Packt Publishing published my book Dancing with Qubits: How quantum computing works and how it can change the world. Through a series of blog entries, I talk about the writing and publishing process, and then about the content.

Dancing With Qubits, First Edition: Drawing quantum circuits

This entry is for people who use the LaTeX document preparation system, as I did in the book. It’s not a tutorial on LaTeX in general, but shows some techniques for drawing quantum circuits. To be direct, it’s pretty geeky for LaTeX people.

An early decision I had to make was how to draw quantum circuit diagrams in the book. Here’s an example of one:

A quantum circuit

This includes three Hadamard H gates, two S gates, a T gate, and a swap gate. Would I need to write my own drawing routines?

I really didn’t want to do that because of my time constraints but I also hoped that I could find something better. It didn’t take me long to do so: Alastair Kay’s excellent quantikx package on the CTAN Comprehensive TeX Archive Network. The documentation there is very good, but in this blog entry I’m going to show you how to evolve a simple circuit to have stylistic customizations that you might want to modify and use.

Below are five displayed versions of the same circuit. They are numbered on the left side.Five example circuits

The first is the default formatting from quantikz. It is perfectly fine and you can see similarly formatted circuits in research articles about quantum computing.

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw       & \gate{H} & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \gate{X}  & \gate{H} & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

The markup \ket{0} produces the |0> at the beginning of each wire, which is a horizontal line. \qw creates a segment of a quantum wire. \gate is the basic command for drawing a labeled gate with a rectangle. \meter is the quantum measurement operator. \ctrl{1} and \targ{} are the two parts of a CNOT two-qubit gate. \ctrl{1} is on the wire for the control qubit and extends a line down one wire. There the line meets the \targ{} (target) qubit and is drawn as a circle around a “+” sign.

In the second example, I’ve changed the font in the H and X gates.

\newcommand*{\gateStyle}[1]{{\textsf{\bfseries #1}}}
\newcommand*{\hGate}{\gateStyle{H}}
\newcommand*{\xGate}{\gateStyle{X}}

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \gate{\hGate} & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \gate{\xGate}  & \gate{\hGate} & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

I added three LaTeX macros to encapsulate the new function and make it easier to reuse.

  1. \gatestyle puts its text in a bold sans serif font.
  2. \hGate draws the Hadamard H using \gatestyle.
  3. \xGate draws the X using \gatestyle.

While it is now easier to use \hGate and \xGate for text, it’s still wordy to use them as gates in a circuit. The third example defines two more macros, \circuitH and \circuitX, and shows how to set the background and font colors. For a printed book, you might want to have gates with backgrounds in different shades of gray. Alternatively, you could use the same background color for all the Clifford gates.

\newcommand*{\circuitH}{\gate[style={fill=black},label style=white]{\textnormal{\hGate{}}}}
\newcommand*{\circuitX}{\gate[style={fill=teal},label style=white]{\textnormal{\xGate}}}

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

Now let’s set the color for the circle in \targ.

\newcommand*{\circuitTarget}[1]{\targ[style={fill=yellow}]{#1}}

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}         & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \circuitTarget{} & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

I think you get the idea. You can also set the background color for \meter, which I leave to you as an exercise. Note that in the April, 2019, version of quantikx, you could not change the color of the line inside the \meter graphic. You need to copy and redefine the macro (or create a new macro) to do that.

Finally, let me explain what that [scale=1.0] is doing after the \node. This allows you to scale the entire drawing and make it larger or smaller. However, it does not change the text size. The fifth example shows the fourth example drawn 20% larger.

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.2] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}         & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \circuitTarget{} & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

Here is the complete LaTeX file I used to generate the examples:


\usetikzlibrary{quantikz}

\mainmatter


\begin{center}
    \begin{tikzpicture}
        \node at (-5,0) {(1)};
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw       & \gate{H} & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \gate{X}  & \gate{H} & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}


\newcommand*{\gateStyle}[1]{{\textsf{\bfseries #1}}}
\newcommand*{\hGate}{\gateStyle{H}}
\newcommand*{\xGate}{\gateStyle{X}}

\begin{center}
    \begin{tikzpicture}
        \node at (-5,0) {(2)};
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \gate{\hGate} & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \gate{\xGate}  & \gate{\hGate} & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}


\newcommand*{\circuitH}{\gate[style={fill=black},label style=white]{\textnormal{\hGate{}}}}
\newcommand*{\circuitX}{\gate[style={fill=teal},label style=white]{\textnormal{\xGate}}}

\begin{center}
    \begin{tikzpicture}
        \node at (-5,0) {(3)};
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}


\newcommand*{\circuitTarget}[1]{\targ[style={fill=yellow}]{#1}}

\begin{center}
    \begin{tikzpicture}
        \node at (-5,0) {(4)};
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}         & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \circuitTarget{} & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}


\begin{center}
    \begin{tikzpicture}
        \node at (-4.4,0) {(5)};
        \node[scale=1.2] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}         & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \circuitTarget{} & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}



Previous: My five rules for making revisions from editorial comments
Next: What’s in the book

In December, 2019, Packt Publishing published my book Dancing with Qubits: How quantum computing works and how it can change the world. Through a series of blog entries, I talk about the writing and publishing process, and then about the content.

Dancing With Qubits, First Edition: My five rules for making revisions from editorial comments

Cover of the book Dancing with QubitsToday I finished making revisions to the book based on comments from the proofreader. All told, there have been five people providing feedback and comments for how I should modify, fix, and improve the content:

  • me
  • the technical reviewer
  • the project editor
  • the development editor
  • the proof reader

My editing started as soon as I started writing, but it has been an iterative process. The technical reviewer made sure what I said was correct, and occasionally caught typos. The project editor, Tom Jacob, focused on the workflow of the overall process and contributed comments about the physical structure of the book and what publisher content should be included.

The development editor, Dr. Ian Hough, has been my constant online companion for the last few months. It is his responsibility to sign off on the final content. He provided suggestions and ideas, and checked that I made good revisions. Sometimes he corrected the revised text when I made mistakes (hey, it was late!). The proofreader did the nitty-gritty editing for punctuation and clarity. Ian filtered those suggestions and passed them along to me. He then checked, again, that I had done the correct revisions.

LaTeX markup showing change bars

Some “suggestions” were really just that. They were optional, but I incorporated almost all of them.

Here are five things I’ve kept in mind or learned through this editing and revision process:

  1. This is not about my ego, it’s about producing the best content.
  2. The mathematics and science must be correct. (I knew this!)
  3. If anyone thinks something is unclear, then I rewrite it.
  4. I need to use many more commas.
  5. It’s important to correctly use the right word in standard pairs such as “that/which” and “already/all ready.”

My bonus rule is to eliminate superfluous words.


Previous: The writing process – what format?
Next: Drawing quantum circuits

In December, 2019, Packt Publishing published my book Dancing with Qubits: How quantum computing works and how it can change the world. Through a series of blog entries, I talk about the writing and publishing process, and then about the content.

Dancing With Qubits, First Edition: The writing process – what format?

Cover of the book Dancing with QubitsBefore I discuss what and I how I wrote, let me talk about the markup of the book. By “markup” I mean the underlying format of the content that determines its structure such as the title page, table of contents, parts, chapters, sections, paragraphs, bibliography, and the index, along with font styles and sizes.

In my experience, most publishers, both traditional and online, prefer you to use Microsoft Word to create the book, and it has its own underlying markup language that you typically never see. In a more-or-less what-you-see-is-what-you-get way, you can write and style the book.The publishing workflow is often based on this choice.

My requirements for the book creation process included:

  • beautiful math rendering, both in sentences and displayed multi-part formulas,
  • built-in support for generating diagrams,
  • easy methods to change formatting throughout the book quickly, and
  • good support for working quickly on a large text.

Regarding the size of the book, in early 2019 I thought the book would come in around 300 pages and I would have a complete draft on September 1. I ended up writing a book with slightly more than 500 pages with the first full draft delivered on October 9. I had full drafts of various chapters before then, but that was the first time there were no sections with TODO markers.

ebook on iPadWord has come a long way on many of these requirements, especially the math, though it can be very laborious to create a book with hundreds or thousands of formulas. Here’s the real problem though: eBooks with math in them often look terrible if you put them in a reflowable format. That is, if you let, say, your Amazon Kindle change the fonts and the line widths, the math just doesn’t look right.

People argue about this forever, but there is an excellent chance that you will end up with fuzzy, misaligned expressions that are the wrong size compared to the surrounding text. So, I early on made the decision that the eBook would not be reflowable. Since that was the case, there was no reason for me to stick with Word. I decided to markup the book in LaTeX. Luckily, Andrew Waldron at Packt Publishing agreed. [Though see this later development regarding the eBook.]

With LaTeX, you have complete and arbitrary control over all parts of the formatting. There are thousands of packages that make your life easier by providing significant functionality that you would not want to write yourself.

LaTeX has

  • the best math formatting facilities of any system,
  • packages like pgf/tikz for creating diagrams,
  • a full macro programming language for formatting control and calculations, and
  • easy ways to break a document into sections so you can work on one part at a time.

If you get into macro programming, things can get complicated. I’ve been doing it for 30 years, so it doesn’t faze me. Here are two good books on LaTeX to get you started:


Previous: Last minute tweaks to my quantum computing book cover
Next: My five rules for making revisions from editorial comments

In December, 2019, Packt Publishing published my book Dancing with Qubits: How quantum computing works and how it can change the world. Through a series of blog entries, I talk about the writing and publishing process, and then about the content.
Verified by MonsterInsights