量子开发技术Quantum Development Techniques

文档的此部分详细介绍了用于在 Q# 中创建量子程序的核心概念,以及如何通过经典应用程序与这些程序交互。This section of our documentation details the core concepts used to create quantum programs in Q#, and to interact with those programs from classical applications. 我们假设你对量子计算概念有一些 了解,如量子计算概念中所述,但你不需要是量子计算方面的专家即可充分掌握这些部分的内容。We assume some knowledge of quantum computing concepts, like those described in Quantum computing concepts, but you need not be an expert in quantum computing to get a lot from these sections.

其内容如下所示。Their contents are as follows.

  • Q# 程序概述概述了 Q# 编程语言的用途和功能。Q# program overview provides an overview of the purpose and functionality of the Q# programming language. 具体说来,它阐明了 Q# 不是一种仅用于模拟量子机制(虽然我们的完整状态模拟器理所当然地会提供此功能)的语言,In particular, it clarifies how Q# is not a language for merely simulating quantum mechanics---though that functionality is of course provided by our full state simulator. 而是一种针对未来设计的语言,其程序描述经典控制计算机如何 与量子位交互。Rather, Q# was designed with an eye on the future, and its programs describe how a classical control computer interacts with qubits.

  • 操作和函数详述了 Q# 语言的两种可调用类型:一种是操作,其中包括在量子位和量子系统上进行的操作;另一种是函数,仅限于经典信息的处理。Operations and functions details the two callable types of the Q# language: operations, which include action on qubits and quantum systems; and functions, which strictly work with classical information. 如果经典信息和量子信息不能配合使用,则量子计算也就无从谈起。Without both classical and quantum information working in tandem, quantum computing would remain out of reach. 此部分介绍如何在 Q# 程序的控制流中定义和使用这两种可调用类型。This section describes how to define and use these callables within the control flow of a Q# program.

  • 局部变量介绍变量在 Q# 程序中的角色以及如何有效地利用它们。Local variables describes the role of variables within Q# programs and how to leverage them effectively. 具体说来,它介绍不可变/可变变量之间的差异以及如何分配/重新分配它们。In particular, you will learn the difference between immutable/mutable variables and how to assign/re-assign them.

  • 使用量子位介绍可用于处理单个量子位和量子位系统的 Q# 功能。Working with qubits describes the features of Q# that you can use to address individual qubits and systems of qubits. 具体说来,这需要进行分配,在其上执行操作,并最终进行度量。Specifically, that entails their allocation, performing operations on them, and ultimately their measurement. 另外还介绍一些有用的控制流技术。Additionally, you will learn some useful control flow techniques.

  • 汇总中,我们将利用上述部分的技术创建一个执行量子隐形传送的程序:使用两个经典位将一个量子位的完整状态“传送”到另一个量子位。In Putting it all together, you will leverage the techniques from the sections above to create a program which performs quantum teleportation: using two classical bits to "teleport" the full state of one qubit onto another.

  • 深入探索引入了高级技术,这些技术在你转向更复杂的量子编程时很有用。Going further introduces advanced techniques that can prove helpful as you move toward more complex quantum programming. 具体说来,我们将讨论如何使用 Q# 中的类型参数化 操作和函数来实现高阶控制流:不需了解其输入/输出的具体类型,并且可以借用 量子位。In particular, we discuss the use of type-parameterized operations and functions in Q#, which enable higher-order control flow by remaining agnostic to the specific types of their input/output, as well as borrowing qubits. 后者不同于基本的量子位分配,因为 Q# 操作可以使用“脏”量子位(不一定初始化为已知状态的量子位)来协助计算。The latter differs from basic qubit allocation in that a Q# operation may use "dirty" qubits---qubits not necessarily initialized to a known state---to assist computations.

  • 测试和调试详述了一些用于确保代码正常运行的技术。Testing and debugging details some techniques for making sure your code is doing what it is supposed to do. 由于量子信息通常不透明,因此调试量子程序可能需要专门的技术。Due to the general opacity of quantum information, debugging a quantum program can require specialized techniques. 幸运的是,Q# 支持程序员习惯使用的许多经典调试技术,以及特定于量子的调试技术。Fortunately, Q# supports many of the classical debugging techniques programmers are used to, as well as those that are quantum-specific. 其中包括在 Q# 中创建/运行单元测试、在代码中嵌入对值和概率的断言 ,以及用于输出目标计算机状态的 Dump 函数。These include creating/running unit tests in Q#, embedding assertions on values and probabilities in your code, and the Dump functions which output the state of target machine. 后者可与完整状态模拟器一起使用,通过规避某些量子限制(例如,非克隆定理)来调试计算的某些部分。The latter can be used alongside our full state simulator to debug certain parts of computations by skirting some quantum limitations (e.g. the no-cloning theorem).

量子