A no-nonsense, comprehensive guide for physicists and programmers to get started with Q#. A succinct, yet thorough approach that covers both mastering the basics and accessing libraries for more specialist applications.
This helpful and practical guide will increase creativity and productivity in your day-to-day quantum computing.
Q# Pocket Guide
by Mariia Mykhailova
Copyright 2022 Mariia Mykhailova. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Acquisitions Editor: Suzanne McQuade
- Development Editor: Sarah Grey
- Production Editor: Elizabeth Faerm
- Copyeditor: Piper Editorial Consulting, LLC
- Proofreader: Arthur Johnson
- Indexer: Ellen Troutman-Zaig
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Kate Dullea
Revision History for the First Edition
- 2022-06-14: First Release
See https://oreil.ly/qpgERR for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Q# Pocket Guide, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the author, and do not represent the publishers views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-098-10886-1
[LSI]
Foreword
When I first learned in the late 90s of a different model of computation, I was instantly inspired and intrigued. How could there be another way for a computer to compute? How would that machine perform operations? What would it mean to program such a machine? My fascination led to my two-decade exploration of answers to such questions, an exploration that now is witness to a growing community of quantum developers, engineers, researchers, and enthusiasts, and an industry working to realize quantum advantage, the demonstration of an algorithm running on a quantum computer that gives a solution more powerful or faster than the best-known classical solution.
But the real impact comes when quantum advantage is practicalwhen we have solutions for practical problems of real-world interest, and those solutions have practical runtimes of less than a few weeks.
Practical is essential. As a computer scientist, I see the magic of quantum computers through the lens of a language, and through the ability to program, form a recipe, and efficiently express what we need the machine to do. The underlying instructions, operations, and programming model of a quantum computer are just different, and we need a different way to program ita practical way that artfully captures the interplay between the highly hybrid nature of quantum algorithms and their quantum and classical needs.
And practicality is what comes to mind in reading Mariias new book. Over the last five years, Mariia, along with a broader team of quantum software engineers and researchers, has been building out a new way to express programs for a quantum computer, and working to make it easier to bring quantum mechanical properties to life through simple, expressive language and examples.
We know that improvements in hardware performance can drive changes in whats possible, and so too can changes in algorithms. An entire industry is working to scale up quantum machines, with a focus on improving the quantum chip and devices. But to achieve quantum advantage, and to chip away at even more advances and areas in which quantum computers will make a difference, we need more algorithms, and we need more practical algorithms.
With the introduction of Fortran, algorithm designers became more efficientby using a more practical language for their needs, they were able to express algorithms and programs faster. They were able to bring their intuition to their code. They were readily able to explore the vast set of opportunities for a classical machine.
We need a similar capability in quantum computing. The Q# programming language has been designed to enable algorithm development, not just low-level instruction programs, and aims to empower the programmer to think about the algorithm design rather than the details of the physics.
With this pocket guide, Mariia brings to life her own experience in quantum development with Q#, weaving her expert perspectives and insights into simple, easy-to-use definitions, examples, and debugging tools. Mariia showcases the nuances of quantum programming, the unique features of Q# that enable more extensive algorithm development, and how to use advanced features of the language to bring your program to quantum life.
I hope this guide enables you to join the exploration for more quantum applications and helps seed a generation of quantum developers and algorithm designers. Developing practical quantum advantage requires our collective intelligence and a growing community of quantum programmers. Quantum programming must be practical for the scale of development needed to happen. And this guide is your next step toward quantum practicality. You never knowyou may just invent the next groundbreaking quantum application.
Dr. Krysta M. Svore
Distinguished Engineer, VP
Quantum Software, Microsoft
May 2022
Preface
Quantum computing is a fascinating computing paradigm, and reasoning about it requires different languages than for classical computing.One of the ways to think about quantum computing is quantum programming, which takes familiar software engineering tools and adapts them to express quantum concepts and implement and evaluate algorithms. Quantum programming is a much younger discipline than either quantum computing or classical programming, yet multiple quantum programming languages and software toolkits have already emerged to help software engineers and researchers.
Q# is a domain-specific quantum programming language created to express quantum algorithms.It is part of the Microsoft Quantum Development Kit (QDK), a set of tools to support quantum software engineering.Both Q# and the QDK are designed for working with high-level algorithms rather than low-level ones (circuits) and include a variety of language features, libraries, and developer tools to support that goal.
This book offers all the information youll need to start developing and running Q# applications, including complete code examples and discussions of the tools available for every step of the quantum software development cycle.