openqasm

OpenQASM 2

OpenQASM is an open-source quantum assembly language that has been designed specifically for programming quantum computers. The language has been developed by IBM and is used to write quantum circuits that can be executed on IBM's quantum computing hardware.
OpenQASM allows users to define quantum circuits using a set of standard quantum gates, such as the Pauli-X gate, the Hadamard gate, and the CNOT gate. Users can also define their own custom gates using a combination of these standard gates.
The language is designed to be easy to read and write, with a syntax that is similar to classical computing languages such as C or Python. This means that users who are familiar with these languages can quickly learn to write quantum circuits using OpenQASM.
OpenQASM is also designed to be extensible, with support for user-defined macros and functions. This means that users can define their own reusable code blocks that can be used in multiple circuits.
One of the key features of OpenQASM is its ability to interface with classical computing languages such as Python. This allows users to write classical programs that can interact with quantum circuits, making it possible to build hybrid classical-quantum applications.
In summary, OpenQASM is an open-source quantum assembly language that provides a powerful and flexible way to program quantum computers. Its user-friendly syntax, extensibility, and ability to interface with classical computing languages make it a popular choice for quantum computing researchers and developers.
OpenQASM是一种开源的量子汇编语言,专门用于编程量子计算机。该语言由IBM开发,用于编写可以在IBM量子计算硬件上执行的量子电路。
OpenQASM允许用户使用一组标准量子门(例如Pauli-X门、Hadamard门和CNOT门)来定义量子电路。用户还可以使用这些标准门的组合来定义自己的自定义门。
该语言的设计旨在易于阅读和编写,语法类似于传统的计算机语言,如C或Python。这意味着熟悉这些语言的用户可以快速学习使用OpenQASM编写量子电路。
OpenQASM还设计为可扩展,支持用户定义的宏和函数。这意味着用户可以定义自己的可重用代码块,可用于多个电路中。
OpenQASM的关键功能之一是其与Python等传统计算机语言的接口能力。这使用户能够编写可以与量子电路交互的传统程序,从而可以构建混合的经典-量子应用程序。
总之,OpenQASM是一种开源的量子汇编语言,提供了一种强大而灵活的编程量子计算机的方式。其用户友好的语法、可扩展性和与传统计算机语言的接口能力使其成为量子计算研究人员和开发人员的热门选择。
 
One way to think about general quantum programs is to identify their distinct phases of execution . Fig. 1 shows a high-level diagram of the processes and abstractions involved in specifying a quantum algorithm, transforming the algorithm into executable form, running an experiment or simulation, and analyzing the results. A key idea throughout these processes is the use of intermediate representations. An intermediate representation (IR) of a computation is neither its source language description, nor the target machine instructions, but something in between. Compilers may use several IRs during the process of translating and optimizing a program.
一种思考一般量子程序的方法是识别其执行的不同阶段。图1显示了指定量子算法、将算法转换为可执行形式、运行实验或模拟以及分析结果所涉及的流程和抽象的高级图。在这些过程中的一个关键思想是使用中间表示。计算的中间表示(IR)既不是其源语言描述,也不是目标机器指令,而是介于两者之间的东西。编译器在翻译和优化程序的过程中可能使用多个IR。
 
notion image
 
i.e.
"i.e." 在拉丁语中是 "id est" 的缩写,意思是 "that is" 或 "in other words"。在英语中,它通常用于进一步解释先前提到的事物或提供更多的细节或澄清。
The human-readable form of our quantum circuit IR is based on “quantum assembly language” or QASM (pronounced kazm).
QASM is a simple text language that describes generic quantum circuits. QASM can represent a completely unrolled quantum program whose parameters have all been specified. Most QASM variants assume a discrete set of quantum gates, but our IR is designed to control a physical system with a parameterized gate set. While we use the term “quantum assembly language”, this is merely an analogy and should not be taken too far.
QASM是一种简单的文本语言,用于描述通用量子电路。QASM可以表示所有参数已指定的完全展开的量子程序。大多数QASM变体假定一组有限离散的量子门,但我们的IR设计用于控制具有参数化门集合的物理系统。尽管我们使用“量子汇编语言”这个术语,但这仅仅是一个类比,不应该被过分解读。
 
The syntax of the human-readable form of Open QASM has elements of C and assembly languages. The first (non-comment) line of an Open QASM program must be OPENQASM M.m; indicating a major version M and minor version m. Version 2.0 is described in this document. The version keyword cannot occur multiple times in a file. Statements are separated by semicolons. Whitespace is ignored. The language is case sensitive. Comments begin with a pair of forward slashes and end with a new line. The statement include "filename"; continues parsing filename as if the contents of the file were pasted at the location of the include statement. The path is specified relative to the current working directory.
Open QASM 可读形式的语法具有 C 和汇编语言的元素。Open QASM 程序的第一行(非注释行)必须是 OPENQASM M.m,表示主版本 M 和次版本 m。本文档描述了版本 2.0。版本关键字不能在文件中多次出现。语句由分号分隔。忽略空格。该语言区分大小写。注释以双斜杠开头,以换行符结束。语句 include "filename"; 将继续解析 filename,就好像文件的内容已经粘贴在 include 语句的位置。路径相对于当前工作目录指定。
 
Features include scientific notation; real arithmetic; logarithmic, trigonometic, and exponential functions; square roots; and the built-in constant π. The Quantum Experience uses a double precision floating point type for real numbers.
特点包括科学计数法;实数算术;对数、三角和指数函数;平方根;以及内置常量π。Quantum Experience使用双精度浮点类型处理实数。
 
Only built-in gate statements, calls to previously defined gates, and barrier statements can appear in body. The statements in the body can only refer to the symbols given in the parameter or argument list, and these symbols are scoped only to the subroutine body. An empty body corresponds to the identity gate. Subroutines must be declared before use and cannot call themselves. The statement name(params) qargs; applies the subroutine, and the variable parameters params are given as parameter expressions. The gate can be applied to any combination of qubits and quantum registers of the same size as shown in the following example.
只有内置门语句、对先前定义的门的调用和障碍语句可以出现在函数体中。函数体中的语句只能引用参数或参数列表中给定的符号,并且这些符号仅在子程序体中作用域空函数体对应于恒等门。子程序必须在使用之前声明,不能调用自身。语句名(params) qargs; 应用子程序,并且变量参数params作为参数表达式给出。该门可以应用于任何相同大小的量子位和量子寄存器组合,如下例所示。
has a second-to-last line that means
倒数第二行的意思是
 
To support gates whose physical implementation may be possible, but whose definition is unspecified, we provide an “opaque” gate declaration. This may be used in practice in several instances. For example, the system may evolve under some fixed but uncharacterized drift Hamiltonian for some fixed amount of time. The system might be subject to an n-qubit operator whose parameters are computationally challenging to estimate. The syntax for an opaque gate declaration is the same as a gate declaration but without a body.
为了支持可能可以进行物理实现但其定义未指定的门,我们提供了“不透明”门声明。这在实践中可用于几种情况。例如,系统可能在固定但未经特征化的漂移哈密顿下演化一段固定的时间。该系统可能受到一个参数难以估计的n量子比特算子的影响。不透明门声明的语法与门声明相同,但没有门体。
 
 

measure statement

The measure qubit|qreg -> bit|creg statement measures the qubit(s) in the Z-basis and records the measurement outcome(s) by overwriting the bit(s).
If both arguments are register-type and have the same size, the statement measure a -> b; means apply measure a[j] -> b[j]; for each index j into register a.
 
Reset Statement
The reset qubit|qreg; statement resets a qubit or quantum register to the state . This corresponds to a partial trace over those qubits (i.e. discarding them) before replacing them with
 
The barrier instruction prevents optimizations from reordering gates across its source line. For example,
will prevent an attempt to combine the CNOT gates but will allow the pair of h s[0]; gates to cancel.
 
Open QASM Grammar
The Open Quantum Assembly Language (Open QASM) is an intermediate representation for quantum instructions. The language is a key part of quantum programming and is often used in IBM's quantum computing SDK, Qiskit. The language is designed to represent quantum circuits in a hardware-agnostic text format. Here is the simplified Open QASM grammar presented in Backus-Naur Form (BNF) as you've written:
(Open QASM)是量子指令的中间表示。该语言是量子编程的关键部分,经常在IBM的量子计算SDK Qiskit中使用。该语言旨在以硬件无关的文本格式表示量子电路。这是你编写的简化Open QASM语法的Backus-Naur形式(BNF):
This grammar is used to define how to write valid Open QASM programs. The <id>, <real>, and <nninteger> notations are regular expressions that describe the syntax for identifiers, real numbers, and non-negative integers, respectively. The remaining notations describe various components of Open QASM, such as statements, declarations, gate declarations, operations, expressions, and more.
这个语法用于定义如何编写有效的Open QASM程序。 <id>、<real>和<nninteger> 符号是描述标识符、实数和非负整数语法的正则表达式。其余符号描述了Open QASM的各种组成部分,例如语句、声明、门声明、操作、表达式等等。
 
Backus-Naur Form (BNF)
Backus-Naur Form (BNF) is a notation technique that's commonly used in computer science to describe the syntax of programming languages and communication protocols. Invented by John Backus and Peter Naur, BNF provides a formal way of describing the grammar of a language. It is a powerful tool for precisely specifying the structure of valid inputs.
BNF syntax consists of a set of derivation rules, each taking the form:
Backus-Naur Form(BNF)是一种常用于计算机科学中描述编程语言和通信协议语法的符号技术。由John Backus和Peter Naur发明,BNF提供了一种形式化的描述语言语法的方式。它是一种精确规定有效输入结构的强大工具。
BNF语法由一组推导规则组成,每个规则有如下形式:
Here, <symbol> is a nonterminal, meaning a symbol that can be replaced or derived into a sequence of other symbols. The ::= operator can be read as "can be replaced by". The __expression__ on the right-hand side consists of terminals and/or nonterminals. Terminals are the basic symbols from which strings are formed.
For example, a simple grammar for an arithmetic expression might look like this:
在这里,<symbol>是一个非终端符,意思是一个可以被替换或派生成一系列其他符号的符号。::= 运算符可以读作“可以被替换为”。右侧的 __expression__ 由终端符和/或非终端符组成。终端符是构成字符串的基本符号。
例如,算术表达式的简单语法可以是这样的:
In this example, <expression>, <term>, <factor>, and <number> are nonterminals, and the numbers 0 through 9 are terminals. The rules define how expressions, terms, and factors can be constructed from numbers and the operators +, *, and parentheses.
So if you're reading a BNF grammar, think of it like a recipe for how to construct (or parse) valid sentences in the language being described. Each rule gives you one piece of the recipe, describing how a higher-level structure (the nonterminal on the left-hand side) can be built out of lower-level structures (the terminals and nonterminals on the right-hand side).
在这个例子中,<expression><term><factor><number> 是非终结符号,0 到 9 的数字是终结符号。规则定义了如何从数字和运算符 +* 和括号中构建表达式、项和因子。
因此,如果你正在阅读一个 BNF 语法,可以将其视为一种构建(或解析)所描述语言中有效句子的配方。每个规则都给出了配方的一部分,描述了一个高级结构(左侧的非终结符号)如何从低级结构(右侧的终结符号和非终结符号)组成。
 
解释:
they are in the format of regular expressions. These are patterns used to match and manipulate strings based on specific conditions. Let's break them down:
  1. <id> ::= [a-z][A-Za-z0-9_]*
    1. This regular expression defines what constitutes a valid identifier (<id>). It starts with a lowercase letter (a-z), followed by zero or more alphanumeric characters (A-Z, a-z, 0-9) or underscores (_).
  1. <real> ::= ([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?
    1. This regular expression defines a real number (<real>). It can have one or more digits before the decimal point and zero or more digits after it ([0-9]+\.[0-9]*) or zero or more digits before the decimal point and one or more digits after it ([0-9]*\.[0-9]+). Additionally, it may be followed by an optional exponent part that begins with an 'e' or 'E', optionally followed by a '+' or '-' sign, and ends with one or more digits ([eE][-+]?[0-9]+). The question mark at the end makes the entire exponent part optional.
  1. <nninteger> ::= [1-9]+[0-9]*|0
    1. This regular expression defines a non-negative integer (<nninteger>). It may be a single digit number 0 or any number not starting with 0, consisting of one or more digits in the range 1-9 followed by zero or more digits in the range 0-9.
In all these definitions, the * operator signifies "zero or more repetitions of", and the + operator signifies "one or more repetitions of". The square brackets [...] indicate a range or set of characters. The | operator is used for alternation, meaning "either the expression before or the expression after". The parentheses (...) are used for grouping. The ? signifies that the preceding item is optional.
它们是正则表达式的格式。这些是基于特定条件匹配和操作字符串的模式。让我们分解它们:
  1. <id> ::= [a-z][A-Za-z0-9_]*
    1. 这个正则表达式定义了什么是一个有效的标识符(<id>)。它以小写字母(a-z)开头,后跟零个或多个字母数字字符(A-Z,a-z,0-9)或下划线(_)。
  1. <real> ::= ([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?
    1. 此正则表达式定义了一个实数(<real>)。它可以在小数点之前有一个或多个数字,小数点之后有零个或多个数字([0-9]+\.[0-9]*)或在小数点之前有零个或多个数字,小数点之后有一个或多个数字([0-9]*\.[0-9]+)。此外,它可以跟随一个可选的指数部分,该部分以 'e' 或 'E' 开头,可选地跟随一个 '+' 或 '-' 符号,并以一个或多个数字结尾([eE][-+]?[0-9]+)。问号表示整个指数部分是可选的。
  1. <nninteger> ::= [1-9]+[0-9]*|0
    1. 此正则表达式定义了一个非负整数(<nninteger>)。它可以是单个数字 0 或任何不以 0 开头的数字,由数字 1-9 中的一个或多个数字后跟数字 0-9 中的零个或多个数字组成。
在所有这些定义中,* 运算符表示 "零个或多个重复",+ 运算符表示 "一个或多个重复"。方括号 [...] 表示一组字符或字符集。| 运算符用于可选择的,表示 "之前的表达式或之后的表达式"。括号 (...) 用于分组。? 表示前面的项是可选的。
 
notion image
 

OpenQASM 3

Quantum assembly languages are machine-independent languages that traditionally describe quantum computation in the circuit model. Open quantum assembly language (OpenQASM 2) was proposed as an imperative programming language for quantum circuits based on earlier QASM dialects. In principle, any quantum computation could be described using OpenQASM 2, but there is a need to describe a broader set of circuits beyond the language of qubits and gates. By examining interactive use cases, we recognize two different timescales of quantum-classical interactions: real-time classical computations that must be performed within the coherence times of the qubits, and near-time computations with less stringent timing. Since the near-time domain is adequately described by existing programming frameworks, we choose in OpenQASM 3 to focus on the real-time domain, which must be more tightly coupled to the execution of quantum operations. We add support for arbitrary control flow as well as calling external classical functions. In addition, we recognize the need to describe circuits at multiple levels of specificity, and therefore we extend the language to include timing, pulse control, and gate modifiers. These new language features create a multi-level intermediate representation for circuit development and optimization, as well as control sequence implementation for calibration, characterization, and error mitigation.
量子汇编语言是一种与机器无关的语言,传统上描述电路模型中的量子计算。开放量子汇编语言(OpenQASM 2)作为一种基于早期QASM方言的命令式编程语言,用于量子电路。原则上,可以使用OpenQASM 2描述任何量子计算,但需要描述更广泛的电路集合,超出量子比特和门的语言范围。通过研究交互式使用案例,我们认识到量子-经典交互的两个不同时间尺度:必须在量子比特的相干时间内执行的实时经典计算和具有较少严格时间要求的近时间计算。由于近时间域已经足够描述现有的编程框架,我们在OpenQASM 3中选择专注于实时域,这必须与量子操作的执行更紧密地耦合。我们添加对任意控制流的支持,以及调用外部经典函数。此外,我们认识到需要在多个具体级别上描述电路,因此我们扩展了语言,包括时间、脉冲控制和门修改器。这些新的语言特性为电路开发和优化创建了多级中间表示,以及用于校准、表征和错误缓解的控制序列实现。
 
Recognizing that OpenQASM is also a resource for describing circuits that characterize, validate, and debug quantum systems, we also introduce instruction semantics that allow control of gate scheduling in the time domain, and that provide the ability to describe the microcoded implementations of gates in a way that is extensible to future developments in quantum control and is platform agnostic.
认识到OpenQASM也是描述量子系统特征、验证和调试电路的资源,我们还引入了指令语义,允许控制门调度在时间域内,并提供了一种描述门的微码实现的方法,这种方法可以扩展到未来量子控制的发展,并且与平台无关。
The extension considered here is intended to be backwards compatible with OpenQASM 2, except in some uncommonly used cases where breaking changes were necessary.
这里考虑的扩展旨在与OpenQASM 2向后兼容,除了在一些罕见的情况下,需要进行破坏性更改。
 
As quantum applications are developing where substantial classical processing may be used along with the extended quantum circuits, we allow for a richer family of computation that incorporates interactive use of a quantum processor (QPU). We refer to this abstraction as a quantum program. For example, the variational quantum eigensolver depends on classical computation to calculate an energy or cost function and uses classical optimization to tune circuit parameters. By examining the broader family of interactive use cases, we recognize two different timescales of quantum-classical interactions: real-time classical computations that must be performed within the coherence times of the qubits, and near-time computations with less stringent timing. The realtime computations are critical for error correction and circuits that take advantage of feedback or feedforward. However, the demands of the real-time, low-latency domain might impose considerable restrictions on the available compute resources in that environment. For example, real-time computations might be constrained by limited memory or reduced clock speeds. Whereas in the near-time domain, we assume more generic compute resources, including access to a broad set of libraries and runtimes. Since the near-time domain is already adequately described by existing programming tools and frameworks, we choose in OpenQASM 3 to focus on the real-time domain, which must be more tightly coupled to the execution of gates and measurement on qubits.
随着量子应用程序的发展,其中可以使用大量的经典处理和扩展的量子电路,我们允许一种更丰富的计算形式,这种形式包含对量子处理器(QPU)的交互使用。我们称这种抽象为量子程序。例如,变分量子本征求解器依赖于经典计算来计算能量或成本函数,并使用经典优化来调整电路参数。通过研究更广泛的交互使用案例,我们认识到量子-经典交互有两个不同的时间尺度:必须在量子比特的相干时间内执行的实时经典计算和具有较松时序的近时计算。实时计算对于纠错和利用反馈或前馈的电路至关重要。然而,实时、低延迟领域的需求可能会对该环境中可用的计算资源施加相当大的限制。例如,实时计算可能受到有限的内存或降低的时钟速度的限制。而在近时领域,我们假设有更通用的计算资源,包括对广泛的库和运行时的访问。由于现有的编程工具和框架已经足以描述近时领域,因此我们选择在OpenQASM 3中专注于实时领域,这需要与量子比特上的门和测量的执行更加紧密地耦合。
 
并发(Concurrency)和并行(Parallelism)是计算机科学中两个重要的概念,它们通常被用于描述多任务处理和多核处理器上的操作。
并发是指在同一时间段内,多个任务在交替地执行,但在任意时刻只有一个任务在执行。这是通过操作系统的任务调度器来实现的,任务调度器为每个任务分配时间片,让它们轮流使用 CPU,从而实现并发。
并行是指在同一时间段内,多个任务同时执行。这需要多个 CPU 或多个核心,并且每个任务都有自己的 CPU 或核心来处理。并行可以显著提高程序的执行速度,但需要更多的硬件资源。
因此,可以将并发视为一种软件层次上的并行,它通过单个 CPU 或核心轮流执行多个任务来实现。而并行是一种更底层的硬件层次上的并行,它使用多个 CPU 或核心来同时执行多个任务。
 
Our extended OpenQASM language expresses a quantum circuit, or any equivalent representation of it, as a collection of (quantum) basic blocks and flow control instructions. This differs from the role of a high-level language. High-level languages may include mechanisms for quantum memory management and garbage collection, quantum data types with non-trivial semantics, or features to specify classical reversible programs to synthesize into quantum oracle implementations. Optimization passes at this high level work with families of quantum operations whose specific parameters might not be known yet. These passes could be applied once at this level and benefit every program instance we execute later. High-level intermediate representations may differ from OpenQASM until the point in the workflow where a specific circuit is generated as an instance from the family.
我们扩展的OpenQASM语言将量子电路或其等效表示表达为(量子)基本块和流控指令的集合。这与高级语言的角色不同。高级语言可能包括量子内存管理和垃圾回收机制,具有非平凡语义的量子数据类型,或者具有指定经典可逆程序合成为量子预言机实现的特性。在这个高级别上进行优化传递,可以使用具有尚未知晓的特定参数的量子操作族。这些传递可以在这个级别上应用一次,并在之后执行每个程序实例时受益。高级中间表示可能与OpenQASM不同,直到从族中生成特定电路实例的工作流程。
 
 
On the other hand, while quantum assembly languages are considered low-level programming languages, they are not often directly consumed by quantum control hardware. Rather, they sit at multiple levels in the middle of the stack where they might be hand-written, generated by scripts (meta-programming), or targeted by higher level software tools and then are further compiled to lower-level instructions that operate at the level of analog signals for controlling quantum systems.
另一方面,虽然量子汇编语言被视为低级编程语言,但它们通常不直接被量子控制硬件所使用。相反,它们位于堆栈的多个中间级别,可以手动编写、由脚本(元编程)生成,或者被更高级别的软件工具所定位,然后进一步编译为更低级别的指令,以操作控制量子系统的模拟信号级别。
 
 
In December of 2020, the Qiskit team announced OpenQASM3, the next version of the OpenQASM language that allows for the expressing a broader family of quantum circuits. In particular, OpenQASM allows for dynamic circuits that blend quantum operations with classical computations. In April of 2021, we followed up with a preprint manuscript that explained many of the design decisions that went into crafting the OpenQASM3 specification. Today, we take the next major step. In collaboration with Amazon Web Services (AWS), Microsoft, and the University of Innsbruck we are forming a technical steering committee (TSC) to guide future evolution and encourage adoption of the OpenQASM language.
We are still in the early days of OpenQASM and quantum computing as a whole. We expect the language to continue to evolve as we learn about the best ways to control and program quantum computers to extract the promised utility of these machines. There will be many opportunities to contribute ideas through pull requests or joining working groups that propose changes to the language.
Forming the technical steering committee will provide transparent and lightweight processes for the inclusion of contributions to OpenQASM that are centered around consensual solutions. These processes ensure that the broad community can shape the future of OpenQASM, giving individuals and organizations confidence that their contributions will be valued and considered.
2020年12月,Qiskit团队宣布了OpenQASM3,这是OpenQASM语言的下一个版本,可以表达更广泛的量子电路系列。特别是,OpenQASM允许混合量子操作和经典计算的动态电路。2021年4月,我们发表了一篇预印本手稿,解释了制定OpenQASM3规范的许多设计决策。今天,我们迈出了下一个重要步骤。与亚马逊网络服务(AWS)、微软和因斯布鲁克大学合作,我们正在组建一个技术指导委员会(TSC),以指导未来的发展,并鼓励采用OpenQASM语言。
我们仍处于OpenQASM和量子计算整体的早期阶段。随着我们了解控制和编程量子计算机以提取这些机器承诺的效用的最佳方式,我们预计该语言将继续发展。有许多机会通过拉取请求或加入工作组提出对语言的更改来贡献想法。
组建技术指导委员会将提供透明且轻量级的过程,以包括围绕共识解决方案的OpenQASM贡献。这些过程确保广泛社区可以塑造OpenQASM的未来,使个人和组织有信心他们的贡献将被重视和考虑。
notion image
We believe that a language can have a broader impact than a specific python toolkit. Consequently, the TSC will also be a point of contact for other frameworks and libraries to integrate OpenQASM into their projects. Adopting OpenQASM will allow for interoperability between projects in the growing quantum software open source community. This serves a similar purpose as some other recent projects in non-quantum problem domains, like how the MLIR (Multi-Level Intermediate Representation) project aims to unify different kinds of heterogenous compute within the LLVM compiler project, and ONNX (Open Neural Network Exchange) aims to unify the plethora of machine learning model expressions. We hope to do something similar in the domain of quantum circuit expression, providing a common layer to allow the community to focus on the main innovations, e.g. in hardware, compilers, algorithms, and for the combined efforts to add together.
我们相信,一种语言可以比特定的Python工具包产生更广泛的影响。因此,TSC也将成为其他框架和库将OpenQASM集成到其项目中的联系点。采用OpenQASM将允许在不断增长的量子软件开源社区中的项目之间实现互操作性。这与非量子问题领域的一些其他最近的项目具有类似的目的,例如MLIR(多级中间表示)项目旨在统一LLVM编译器项目中不同类型的异构计算,而ONNX(开放式神经网络交换)旨在统一众多的机器学习模型表达。我们希望在量子电路表达领域做类似的事情,提供一个公共层,使社区能够专注于主要创新,例如硬件、编译器、算法,以及综合努力的加和。
 
Chief among them are arbitrary classical control flow, gate modifiers (e.g., control and inverse), timing, and microcoded pulse implementations.
其中最重要的是任意的经典控制流、门控制器(例如控制和反转)、时间和微编码脉冲实现。
While these extensions are not strictly necessary from a theoretical point of view, any quantum computation could in principle be described using OpenQASM 2—in practice they greatly expand the expressivity of the language.
尽管从理论上讲这些扩展并非必需品,但任何量子计算原则上都可以使用OpenQASM 2进行描述。实际上,这些扩展大大扩展了语言的表达能力。
some applications require pre-processing of problem data, such as choosing a co-prime in Shor’s algorithm [71], postprocessing to compute expectation values of Pauli operators, or further generation of circuits like in the outer loop of many variational algorithms [66]. However, these classical computations do not have tight deadlines requiring execution within the coherence time of the quantum hardware. Consequently, we think of their execution in a near-time context, which is more conveniently expressed in existing classical programming frameworks.
一些应用程序需要对问题数据进行预处理,例如在Shor算法[71]中选择互质数、后处理以计算 Pauli 算符的期望值,或者在许多变分算法[66]的外部循环中进一步生成电路。然而,这些经典计算没有严格的截止时间要求在量子硬件的相干时间内执行。因此,我们认为它们在近时间上下文中执行,这更方便地在现有的经典编程框架中表达。
 
Our classical computation extensions in OpenQASM 3 instead focus on the real-time domain, which must be tightly coupled to quantum hardware. Even in the real-time context, we enable re-use of existing tooling by allowing references to externally specified real-time functions defined outside of OpenQASM itself.
我们在OpenQASM 3中的经典计算扩展侧重于实时领域,这必须紧密耦合到量子硬件。即使在实时环境中,我们也通过允许引用在OpenQASM之外定义的外部指定实时函数来实现现有工具的重用。
The realtime computations are critical for error correction and circuits that take advantage of feedback or feedforward.
实时计算对于错误校正和利用反馈或前馈的电路至关重要。
 
We wish to use the same tools for circuit development and for lower-level control sequences needed for calibration, characterization, and error mitigation. Hence, we need the ability to control timing and to connect quantum instructions with their pulse-level implementations for various qubit modalities. For instance, dynamical decoupling [78] or characterizations of decoherence and crosstalk [39] are all sensitive to timing, and can be programmed using the new timing features. Pulse-level calibration of gates can be fully described in OpenQASM 3.
我们希望在电路开发和校准、表征和误差缓解所需的较低级别控制序列中使用相同的工具。因此,我们需要控制时间和连接量子指令与其各种量子比特模态的脉冲级实现的能力。例如,动态解耦[78]或退相干和串扰特性[39]都对时间敏感,并可以使用新的时间特性进行编程。门的脉冲级校准可以在OpenQASM 3中完全描述。
 
 
Execution Model
执行模型
 
The compilation and execution model of a quantum program, and OpenQASM’s place in the flow. An application is written in terms of a quantum program. Certain regions of a quantum program are purely classical and can be written in classical programming languages for execution in a near-time context. The quantum program emits payloads for execution on a QPU. This payload consists of extended quantum circuits and external real-time classical functions. OpenQASM is the language to describe the quantum circuits, which includes interface calls to the external classical functions. There may be higher-order aspects of the circuit payload, which are optimized before OpenQASM is generated. An OpenQASM compiler can transform and optimize all aspects of the circuits described with the IR, including basis gates used, qubit mapping, timing, pulses, and control flow. The final physical circuit plus extern functions are passed to a target code generator, which produces binaries for the QPU.
量子程序的编译和执行模型,以及OpenQASM在其中所处的位置。应用程序是以量子程序的形式编写的。量子程序的某些区域是纯经典的,可以使用经典编程语言编写,以在近实时的上下文中执行。量子程序发出负载以在QPU上执行。该负载包括扩展的量子电路和外部实时经典函数。OpenQASM是描述量子电路的语言,其中包括对外部经典函数的接口调用。电路负载可能具有高阶方面,在生成OpenQASM之前进行优化。OpenQASM编译器可以转换和优化IR描述的电路的所有方面,包括使用的基本门、量子比特映射、时间、脉冲和控制流。最终的物理电路加上外部函数会传递给目标代码生成器,生成QPU的二进制文件。
notion image
An application might be composed of several quantum programs including near-time calculations and quantum circuits. The quantum program interacts with quantum hardware by emitting OpenQASM3 circuits and external real-time functions. Initial generation of these circuits and extern functions require a deep compilation stack to transform the circuits and extern into a form that is executable on the QPU. We represent these multiple stages by logical OpenQASM and physical OpenQASM. The logical OpenQASM represents the intent of the extended quantum circuit, whereas the physical OpenQASM is the lowest level where the circuit is mapped and scheduled on specific qubits. A quantum program might work with even higher level circuit representations than those expressible with OpenQASM 3, but in this flow, manipulations of these higher order objects would be contained within the quantum program. A quantum program is not constrained to produce only logical OpenQASM. Sometimes it might emit physical OpenQASM, or later stages of a program might take advantage of lower-cost ways to produce binaries executable by the QPU. For instance, a program describing the optimization loop of a variational algorithm might directly manipulate a data section in the binaries to describe circuits with updated circuit parameters . We generically expect quantum programs to be able to enter the compilation toolchain at varying levels of abstraction as appropriate for different phases of program execution. Our language model further assumes that the QPU has a global controller that orchestrates execution of the circuit. This global controller centralizes control flow decisions and has the ability to execute extern computations emitted by the quantum program. Some QPUs may also have a collection of local controllers that interact with a subset of qubits. Such segmentation of the QPU could enable concurrent execution of independent code segments.
一个应用程序可能由几个量子程序组成,包括近实时计算和量子电路。量子程序通过发出OpenQASM3电路和外部实时函数与量子硬件交互。这些电路和外部函数的初始生成需要一个深层编译堆栈,将电路和外部函数转换为可在QPU上执行的形式。我们通过逻辑OpenQASM和物理OpenQASM表示这些多个阶段。逻辑OpenQASM表示扩展量子电路的意图,而物理OpenQASM是电路映射和调度到特定量子位的最低级别。量子程序可能使用比OpenQASM 3可表示的更高级别的电路表示,但在此流程中,对这些高阶对象的操作将包含在量子程序中。量子程序不受限于仅产生逻辑OpenQASM。有时它可能会发出物理OpenQASM,或者程序的后续阶段可能会利用更低成本的方式生成可由QPU执行的二进制文件。例如,描述变分算法优化循环的程序可能直接操作二进制文件中的数据部分,以描述具有更新电路参数的电路。我们普遍希望量子程序能够以不同的抽象级别进入编译工具链,以适应程序执行的不同阶段。我们的语言模型进一步假定QPU具有全局控制器,该控制器编排电路的执行。这个全局控制器集中控制流决策,并具有执行量子程序发出的外部计算的能力。一些QPUs可能还具有一组与一部分量子位交互的本地控制器。这种QPU的分割可以实现独立代码段的并发执行。
 
The qreg and creg keywords may not be supported in future versions of OpenQASM.
未来版本的OpenQASM可能不支持qregcreg关键字。
 
 
Quantum and Classical Registers. In OpenQASM 2, the only storage types available are qubits, which are allocated as part of a qreg declaration, and classical bits, which are allocated as part of a creg declaration, for example:
This syntax is supported in OpenQASM 3, and is equivalent to the (preferred2)syntax,
OpenQASM 3 两种表达方式都可以,更常用第二种。第一种在后续的版本中会不再使用。
 
Names of Gates, Variables, and Constants.
In OpenQASM 2, the names of registers and gates must begin with a lower-case alphabetic ASCII character. This constraint is relaxed in OpenQASM 3: Identifiers may now begin with other characters, such as capital letters, underscores, and a range of unicode characters.
The identifier is reserved in OpenQASM 3 to represent the same constant as pi.
在OpenQASM 2中,寄存器和门的名称必须以小写字母ASCII字符开头。在OpenQASM 3中,此约束已得到放宽:标识符现在可以以其他字符开头,例如大写字母、下划线和一系列unicode字符。
在OpenQASM 3中,标识符被保留用于表示与pi相同的常量。
 
Basic Operations
  • The OpenQASM 3 specification for single-qubit unitaries, described in Equation (1), differs by a global phase from the specification in OpenQASM 2. This change has no effect on the results of an OpenQASM 2 circuits.
在OpenQASM 3规范中,单量子比特幺正门的公式(方程1)与OpenQASM 2中的规范存在全局相位差异。这种变化对OpenQASM 2电路的结果没有影响。
notion image
(1)式不够通用,缺全局相位。
  • Two-qubit controlled-NOT operations, using the keyword CX, acting on two single-qubit arguments. In OpenQASM 3, the CX instruction is no longer a basic instruction or a keyword, but may be defined from more primitive commands. To adapt an OpenQASM 2 circuits to be valid OpenQASM 3, one may add a single instruction to define CX using a “ctrl @”gate modifier:
使用关键字 CX 对两个单量子比特参数执行双量子比特控制非门操作。在 OpenQASM 3 中,CX 指令不再是基本指令或关键字,但可以从更原始的命令定义。要将 OpenQASM 2 电路适应为有效的 OpenQASM 3,可以添加一个单一指令来使用“ctrl @”门修饰符定义 CX:
  • Non-unitary reset and measure operations, acting on a single-qubit argument (and producing a single bit outcome in the case of measure). The statement reset q[j] operation has the effect of discarding the data stored in q[j], replacing it with the state . The statement measure q[j] -> c[k] has the effect of measuring q[j] in the standard basis, i.e., projecting the state into one of the eigenstates of the Pauli operator, and storing the corresponding bit-value in a classical bit c[k]. OpenQASM 3 supports these operations without changes, and also supports the alternative syntax c[k] = measure q[j] for measurements.
非幺正的 resetmeasure 操作,作用于一个量子比特参数(在 measure 的情况下产生一个单比特的结果)。语句 reset q[j] 的效果是丢弃存储在 q[j] 中的数据,并用状态 替换它。语句 measure q[j] -> c[k] 的效果是在标准基中测量 q[j],即将状态投影到 Pauli 算符的本征态之一,并将相应的比特值存储在经典比特 c[k] 中。OpenQASM 3 支持这些操作而不需要更改,并且还支持用于测量的替代语法 c[k] = measure q[j]
 
Gate Declarations
OpenQASM 2 supports gate declarations to specify user-defined gates. The definitions set out a fixed number of single-qubit arguments, and optionally some arguments, which are taken to be angular parameters. These declarations use syntax such as
门声明
OpenQASM 2支持门声明来指定用户定义的门。定义设置了固定数量的单量子比特参数,并且可以选择一些参数,这些参数被视为角度参数。这些声明使用的语法类似于
The specification of these gates, in the code-blocks enclosed by braces { ... }, are by sequences of unitary operations, whether basic unitary operations or ones defined by earlier gate declarations. OpenQASM 3 supports gate declarations with this syntax, and also admits only unitary operations as part of the gate definitions—but has greater versatility in how those unitary operations may be described (see Section 4.2), and also provides other ways to define subroutines (see Section 4.4).
这些门的规范,在由大括号 { ... } 包围的代码块中,是由一系列酉操作定义的,无论是基本的酉操作还是之前门声明定义的操作。OpenQASM 3支持这种语法的门声明,并且仅作为门定义的一部分支持酉操作,但在描述这些操作的方式上具有更大的灵活性(见第4.2节),并且还提供了其他定义子例程的方法(见第4.4节)。
 
Implicit Iteration
Operations on one or more qubits could be repeated across entire registers as well, using implicit iteration. For instance, for any operation “qop q[j]”, which acts on one qubit q[j], we can instead perform it independently on every qubit in q by omitting the index (as in “qop q”). For operations on two qubits of the form “qop q[j], r[k]”, one or both arguments could omit the index, in which case the instruction would be repeated either for j = 1, 2,... or k = 1, 2,... (if one index is omitted), or for j = k = 1, 2,... (if both indices are omitted). This functionality also extends to operations on three qubits or more. OpenQASM 3 supports this functionality unchanged, for gate subroutines. (OpenQASM 3 also supports other kinds of subroutine beyond gate definitions, and these other subroutines do not support implicit iteration in this way.)
对一个或多个量子比特的操作也可以通过隐式迭代在整个寄存器上重复执行。例如,对于任何作用于一个量子比特q[j]的操作“qop q[j]”,我们可以通过省略索引(如“qop q”)在q的每个量子比特上独立执行它。对于形式为“qop q[j],r[k]” 的两个量子比特的操作,一个或两个参数可以省略索引,此时指令将在j = 1、2、...或k = 1、2、...(如果省略一个索引)或在j = k = 1、2、...(如果省略两个索引)时重复执行。这种功能也适用于三个或更多量子比特的操作。OpenQASM 3支持这种功能不变的门子程序。(OpenQASM 3还支持除门定义之外的其他种类的子程序,这些其他子程序不支持这种隐式迭代。)
 
the value of a classical bit-register (interpreted as a little-endian representation of an integer) to an integer
小端表示(Little Endian)是一种存储多字节数据的方式,其中最低有效字节(即最不重要的字节)存储在最前面的地址,最高有效字节(即最重要的字节)存储在最后面的地址。
将经典比特寄存器的值(解释为整数的小端表示)转换为整数
notion image
 
Qiskit uses little-endian for both classical bit ordering and qubit ordering.
For classical bits:
A 3-bit classical register creg with value abc has creg[0]=ccreg[1]=bcreg[2]=a.
For qubits:
The ordering is with respect to the tensor-product structure of the state space. So a 3-qubit quantum register qreg with wave-function |𝜓⟩=|𝐴⊗𝐵⊗𝐶⟩=|𝐴𝐵𝐶⟩ has qreg[0]=|𝐶⟩, qreg[1]=|𝐵⟩, qreg[2]=|𝐴⟩.
Similarly for representing unitary matrices of a circuit. would have   acting on qreg[0]  acting on qreg[1] and  acting on qreg[2].
 
notion image
In this 6 qubit example, the bit string would read 0 except for the 6th qubit which has the X gate: q5 = 1. The ordering in the quantum state in little endian is
|𝑞5,𝑞4,𝑞3,𝑞2,𝑞1,𝑞0⟩, so the bit string is |100000⟩.
 
Control Flow.
The only control flow supported by OpenQASM 2 are if statements. These can be used to compare the value of a classical bit-register (interpreted as a little-endian representation of an integer) to an integer, and conditionally execute a single gate. An example of such a statement is
which would test whether a classical register c (of length three or more) stores a bit-string equal to , to determine whether to execute mygate q, r, s. Ifstatements (and classical register comparisons) of this kind are supported in OpenQASM 3, as is more general syntax for if statements and other forms of control-flow (see Section 4.4).
 
Barrier Instructions.
OpenQASM 2 provides a barrier instruction, which may be invoked with or without arguments. When invoked with arguments, either of individual qubits or whole quantum registers, it instructs the compiler not to perform any optimizations that involve moving or simplifying operations acting on those arguments, across the source line of the barrier statement; when invoked without arguments, it has the same effect as applying it to all of the quantum registers that have been defined. This operation is also supported in OpenQASM 3, with the same meaning.
OpenQASM 2提供了barrier指令,可以带或不带参数调用。当带参数调用时,可以是单个量子比特或整个量子寄存器,它指示编译器不要跨越barrier语句的源代码行去执行涉及移动或简化作用于那些参数的操作的任何优化;当不带参数调用时,它具有作用于定义的所有量子寄存器的相同效果。此操作在OpenQASM 3中也受支持,意义相同。
 
Opaque Definitions.
OpenQASM 2 supports opaque declarations, to declare gates whose physical implementation may be possible, but is not readily expressed in terms of unitary gates. OpenQASM 3 provides means of defining operations on a lower level than unitary gates (see Section 5.2); therefore, opaque definitions are not needed. OpenQASM 3 compilers will simply ignore any opaque declarations.
OpenQASM 2 支持不透明声明,用于声明其物理实现可能是可行的,但不易用单量子门表达的门。OpenQASM 3 提供了在低于单量子门的级别上定义操作的方法(参见第 5.2 节);因此,不需要不透明定义。OpenQASM 3 编译器将简单地忽略任何不透明声明。
 
Circuit Output.
The outputs of an OpenQASM 2 circuit are the values stored in any declared classical registers. OpenQASM 3 introduces a means of explicitly declaring, which variables are to be produced as output or taken as input (see Section 4.5). However, any OpenQASM 3 circuit, which does not specify either an output or input will, by default, also produce all of its classical stored variables (whether of type creg, or a different type) as output.
OpenQASM 2电路的输出是存储在任何声明的经典寄存器中的值。OpenQASM 3引入了一种明确声明哪些变量作为输出或作为输入的方法(请参见第4.5节)。然而,任何未指定输出或输入的OpenQASM 3电路也将默认生成其所有经典存储变量(无论是creg类型还是其他类型)作为输出。
 
 
 

THE LOGICAL LEVEL

 
 
notion image
Users should be aware that the definition in Equation (1) is scaled by a factor of ei(φ+λ)/2 when compared to the original definition in OpenQASM 2 [27]. This implies that the transformation described by U(a,b,c) has determinant ei(a+c), and is not in general an element of SU (2). This change in global phase has no observable consequence for OpenQASM 2 circuits. We also note that U is the only uppercase keyword in OpenQASM 3.
用户应该注意,与OpenQASM 2 [27]中的原始定义相比,方程(1)中的定义被一个ei(φ+λ)/2的因子缩放。这意味着由U(a,b,c)描述的转换具有determinant为ei(a+c),并且不是通用的SU(2)的元素。这种全局相位的变化对OpenQASM 2电路没有可观察到的影响。我们还注意到,U是OpenQASM 3中唯一的大写关键字。
 
Controlled gates can be constructed by attaching a control modifier to an existing gate. For example, the NOT gate (i.e., the Pauli X operator) is given by U(π , 0, π ) and the block
通过将控制修饰符附加到现有门上,可以构造控制门。例如,NOT门(即Pauli X算符)由U(π,0,π)给出,块
notion image
也就是
 
 
Remark. Throughout the document, we use a tensor order with higher index qubits on the left. This ordering labels states in a way that is consistent with how numbers are usually written with the most significant digit on the left. In this tensor order, CX q[0], q[1]; is represented by the matrix
备注。 在整个文档中,我们使用一个张量顺序,其中高索引量子位于左侧。这种顺序以一种与数字通常从左侧开始写最重要的数字相一致的方式标记状态。在这个张量顺序中,CX q[0],q[1]; 由矩阵表示。
notion image
这个矩阵就是
 
From a physical perspective, any unitary is indistinguishable from another unitary , which only differs by a global phase. When we attach a control to these gates, however, the global phase becomes a relative phase that is applied when the control qubit is one. To capture the programmer’s intent, a built-in global phase gate allows the inclusion of arbitrary global phases on circuits. The instruction gphase() adds a global phase of to the scope containing the instruction. For example,
从物理角度看,任何幺正 $U$ 都与另一个幺正 $e^{iγ}U$ 无法区分,后者只是在全局相位上有所不同。然而,当我们将控制附加到这些门时,全局相位变成了相对相位,当控制量子比特为 $1$ 时应用。为了捕捉编程人员的意图,内置的全局相位门允许在电路中包含任意全局相位。指令 gphase($γ$ ) 在包含该指令的范围内添加了一个全局相位 $e^{iγ}$。例如,
constructs the gate
 
notion image
and applies the controlled form of that phase rotation gate
 
notion image
 
In OpenQASM 2, gate subroutines are defined in terms of built-in gates U and CX.InOpenQASM 3, we can define controlled gates using the control modifier, so it is no longer necessary to include a built-in CX gate. For backwards compatibility, we include the gate CX in the standard gate library (described below), but it is no longer a keyword of the language.
Standard Gate Library. We define a standard library of OpenQASM 3 gates in a file, we call stdgates.inc. Any OpenQASM 3 circuit that includes the standard library can make use of these gates.
notion image
 
 
 

Gate Modifiers

We introduce a mechanism for modifying existing unitary gates g to define new ones. A modifier defines a new unitary gate from g, acting on a space of equal or greater dimension, that can be applied as an instruction. We add modifiers for inverting, exponentiating, and controlling gates. This can be useful for programming convenience and readability, but more importantly it allows the language to capture gate semantics at a higher level which aids in compilation. For example, optimization opportunities that exist by analysing controlled unitaries may be exceedingly hard to discover once the controls are decomposed.
我们引入了一种机制来修改现有的幺正门g以定义新的门。一个修饰符从g中定义了一个新的幺正门,作用于相等或更大维度的空间,可以作为指令应用。我们添加了反转、指数化和控制门的修饰符。这对于编程方便和可读性很有用,但更重要的是它允许语言在更高的层次上捕捉门的语义,有助于编译。例如,通过分析受控幺正门存在的优化机会,一旦这些控制被分解,可能非常难以发现。
 
有三种:
  • The Control Modifier.
  • The Inversion Modifier.
  • The Powering Modifier.
 
The Control Modifier.
In mathematics, is commonly used to denote the direct sum or exclusive or (XOR) operation.
The direct sum is a binary operation that takes two vector spaces and returns their direct sum, which is a new vector space consisting of all possible ordered pairs of vectors from the original spaces.
The exclusive or (XOR) operation is a binary logical operation that takes two operands and returns true if and only if the operands are different. It is often used in boolean algebra and digital circuitry.
Which operation the symbol represents depends on the context in which it is used.
here, we use the meaning which is direct sum.
notion image
The modifier ctrl @ g represents a controlled-g gate with one control qubit. This gate is defined on the tensor product of the control space and target space by the matrix ,whereI has the same dimensions as g. (We regard ctrl @ gphase(a) as a special case, which is defined to be the gate .) A compilation target may or may not be able to execute the controlled gate without further compilation. The user or compiler may rewrite the controlled gate to use additional ancillary qubits to reduce the size and depth of the resulting circuit.
By “compile-time constant”, we mean an expression, which is actually constant, or which depends only on (a) variables, which take fixed values, or (b) iterator variables in for loops, which can be unrolled by the compiler (i.e., which have initial and final iterator values, which are themselves compile-time constants).
通过“编译时常量”,我们指的是一个表达式,它实际上是常量,或仅依赖于(a)取固定值的变量,或(b)在for循环中可以被编译器展开的迭代变量(即具有初始和最终迭代值,这些值本身是编译时常量)。
 
The Inversion Modifier.
The modifier inv @ g represents the inverse of the gate g.Thiscan be easily computed from the definition of the gate g as follows:
— The inverse of any unitary operation can be defined recursively by reversing the order of the gates in its definition and replacing each of those with their inverse .
— The inverse of a controlled operation I ⊕U can be defined by reversing the operation, which is controlled, as for any unitary .Thatis,inv @ ctrl @ g is defined to have the same meaning as ctrl @ inv @ g (commuting the “inv @” modifier past the “ctrl @”modifier).
— The base case is given by replacing inv @ U(a, b, c) by U(-a, -c, -b), and replacing inv @ gphase(a) by gphase(-a).
 
The Powering Modifier.
The modifier pow(r) @ g represents the r th power gr of the gate g, where r is an integer or floating point number. Every unitary matrix U has a unique principal logarithm ,whereH has only real eigenvalues E, which satisfy −π < E ≤ π . For any real r , we define the r th power as .
In general, compiling pow(r) @ g involves solving a circuit synthesis or optimization problem, even in the integral case.
 

Non-unitary Operations

 
Measurement is “non-destructive”, in that it corresponds to a projection onto one of the eigenstates of Z ; the qubit remains available afterwards for further quantum computation.
测量是“非破坏性”的,因为它对应于在 Z 的本征态之一上的投影;量子比特在此之后仍可用于进一步的量子计算。
 
The statement reset q resets a qubit q to the state |0〉. With idealised quantum hardware, this is equivalent to measuring q in the standard basis, performing a Pauli X operation on the qubit if the outcome is “1”, and then discarding the measurement outcome. Mathematically, it corresponds to a partial trace over q (i.e., discarding it) before replacing it with a new qubit in the state .The reset statement also works with an array of qubits, resetting them to the state.
语句reset q将量子比特q重置为状态|0〉。在理想化的量子硬件中,这相当于在标准基础上测量q,并在结果为“1”时对量子比特执行Pauli X操作,然后丢弃测量结果。在数学上,它对应于对q进行偏迹(即舍弃)然后用处于状态$|0\rang$的新量子比特替换它。reset语句也适用于量子比特数组,将它们重置为状态$|0\rang⊗···⊗|0\rang$。
 

Real-time Classical Computing

OpenQASM 2 primarily described static circuits in which the only mechanism for control flow were if statements that controlled execution of a single gate. This constraint was largely imposed by corresponding limitations in control hardware. Dynamic circuits—with classical control flow and concurrent classical computation—represent a richer model of computation, which includes features that are necessary for eventual fault-tolerant quantum computers that must interact with real-time decoding logic. In the near term, these circuits also allow for experimentation with qubit re-use, teleportation, and iterative algorithms
OpenQASM 2主要描述静态电路,其中控制流的唯一机制是控制单个门执行的if语句。这种限制主要是由于控制硬件的相应限制所施加的。动态电路——具有经典控制流和并发经典计算——代表了一种更丰富的计算模型,包括必要的特性,这些特性对于最终需要与实时解码逻辑交互的容错量子计算机是必要的。在短期内,这些电路还允许使用量子比特重复利用、传送和迭代算法进行实验。
💡
Dynamic circuits—with classical control flow and concurrent classical computation—represent a richer model of computation, which includes features that are necessary for eventual fault-tolerant quantum computers that must interact with real-time decoding logic. In the near term, these circuits also allow for experimentation with qubit re-use, teleportation, and iterative algorithms
 
While our approach to selecting classical instructions was conservative, these extensions make OpenQASM Turing-complete for classical computations in principle, augmenting the prior capability to describe static circuits composed of unitary gates and measurement.
尽管我们选择经典指令的方法是保守的,但这些扩展原则上使OpenQASM对于经典计算具有图灵完备性,增强了先前描述由酉门和测量组成的静态电路的能力。
图灵完备意味着一种编程语言或计算机系统能够模拟图灵机,即能够计算所有可以被计算的问题。在编程语言中,图灵完备性通常是一项重要的特征,因为它意味着该语言具有足够的表达能力,可以编写任何可计算的程序。在OpenQASM中,图灵完备性用于说明该语言可以用于描述经典计算,扩展了先前仅描述由酉门和测量组成的静态电路的能力。
 
OpenQASM has a type system that meets two needs. It captures the programmer's intent in high-level circuits and is portable across different quantum computer controllers. In low-level circuits, it reflects the realities of a specific controller, such as limited memory and well-defined register lengths. Inspired by classical programming languages, OpenQASM's type system has unique features for dynamic quantum circuits.
OpenQASM具有满足两个需求的类型系统。它捕捉高级电路程序员的意图,并且在不同的量子计算机控制器之间具有可移植性。在低级电路中,它反映了特定控制器的现实,例如有限的内存和明确定义的寄存器长度。受经典编程语言的启发,OpenQASM的类型系统具有用于动态量子电路的独特功能。
 
For logical-level OpenQASM circuits, we introduce some common types, which will be familiar to most programmers: int for signed integers, uint for unsigned integers, float for floating point numbers, bool for boolean true or false values, and bit for individual bits. The precision of the integer and floating-point types is not specified within the OpenQASM language itself: rather the precision is presumed to be a feature of a particular controller.
对于逻辑级别的OpenQASM电路,我们引入了一些常见类型,这些类型对大多数程序员来说都很熟悉:int表示有符号整数,uint表示无符号整数,float表示浮点数,bool表示真值或假值,bit表示单个比特位。整数和浮点数类型的精度并未在OpenQASM语言本身中指定:相反,精度被认为是特定控制器的特征。
 
For low-level platform-specific OpenQASM circuits, we introduce syntax for defining arbitrary bit widths of classical types. In addition to the hardware-agnostic int type, OpenQASM 3 also allows programmers to specify an integer with exact precision int[n] for any positive integer n. For example,
对于低级平台特定的OpenQASM电路,我们引入了定义任意位宽经典类型的语法。除了硬件无关的int类型外,OpenQASM 3还允许程序员指定精确精度int [n]的整数,其中n是任何正整数。例如,
 
OpenQASM 3 introduces a fixed-point angle type to represent angles or phases, which can have a specific bit-width. Variables of type angle[n] can be interpreted as values in the range [0, 2π) with a fractional binary expansion, making it useful for quantum phase estimation and numerically-controlled oscillators. This type is particularly relevant to real-time control systems that need to track qubit frames at run-time, as it automatically constrains the phase representation to the domain [0, 2π), avoiding expensive floating-point modular arithmetic. OpenQASM 3 has first-class support for this type due to its relevance in controllers and quantum algorithms.
OpenQASM 3引入了一个固定点角度类型来表示角度或相位,可以具有特定的位宽。类型为angle[n]的变量可以被解释为范围为[0, 2π)的值,具有分数二进制扩展,这对于量子相位估计和数值控制振荡器非常有用。这种类型特别适用于需要在运行时跟踪量子比特框架的实时控制系统,因为它自动将相位表示限制在[0,2π)的域内,避免了昂贵的浮点模运算。由于其在控制器和量子算法中的相关性,OpenQASM 3对此类型具有一流的支持。
. (For example, with an angle[4],the binary representation of π would be ; the representation of π /2 would be ;
The angle types do not actually commit to the value of the angle being positive, and can also be interpreted as representing values in the range [−π, π ); the description above is provided for the sake of concreteness.
 
Classical Control Flow: OpenQASM 2 circuits were effectively limited to straight line code: any quantum algorithm with more involved constructs, such as loops, could only be specified through meta-programming in a more general tool such as Python. The resulting OpenQASM 2 circuits could end up being quite lengthy in some cases, and lost all the structure from their original synthesis. In OpenQASM 3, we introduce while loops and for loops. We also extend the if statement syntax to allow for multiple instructions within the body of the if , and to allow for an else block to accompany it.
经典控制流程:OpenQASM 2电路实际上仅限于直线代码:任何具有更复杂结构的量子算法,例如循环,只能通过在更通用的工具(如Python)中进行元编程来指定。在某些情况下,由此产生的OpenQASM 2电路可能会非常冗长,并且失去了其原始合成的所有结构。在OpenQASM 3中,我们引入了while循环和for循环。我们还扩展了if语句的语法,以允许在if体内有多个指令,并允许一个else块与之相伴。
 
Subroutines: Sufficiently simple functions (accompanied by sufficiently capable controllers) allow for classical subroutines to be fully implemented within the language itself. Consider a simple vote function, which takes the majority “vote” of three bit parameters. This could be implemented as follows:
子程序:足够简单的函数(配备足够强大的控制器)允许在语言本身中完全实现经典子程序。考虑一个简单的投票函数,它接受三个位参数的大多数“投票”。可以按照以下方式实现:
 
 
External Functions: Rather than bulk up the feature set of OpenQASM for classical computation further—which would require sophisticated classical compiler infrastructure to manage —we selected only those elements we thought likely to be used frequently. To provide access to more sophisticated classical computations, we instead introduce a extern mechanism to connect OpenQASM 3 circuits to arbitrary, opaque classical computations.
外部函数:我们选择仅选择那些我们认为经常使用的元素,而不是进一步扩展 OpenQASM 的经典计算功能集-这将需要复杂的经典编译器基础设施来管理。为了提供对更复杂的经典计算的访问,我们引入了一个“extern”机制,将 OpenQASM 3 电路连接到任意的不透明经典计算。
An extern is declared similarly to a function declaration in a C header file. That is, rather than define commonly used simple subroutines in OpenQASM, the programmer may provide a signature of the form:
一个 extern 的声明和 C 头文件中的函数声明类似。也就是说,程序员可以提供以下形式的签名,而不是在 OpenQASM 中定义常用的简单子程序:
and then use vote like a subroutine acting on classical bits. In order to connect to existing classical compiler infrastructure, the definition of an extern is not embedded within an OpenQASM circuit, but is expected to be provided to the compilation tool chain in some other language format such as Python, C, x86 assembly, or LLVM IR. This allows externs to be compiled with tools like GCC or LLVM with a minimal amount of additional structure to manage execution within the run-time requirements of a global controller. Importantly, this strategy of connecting to existing classical programming infrastructure implies that the programmer can use existing libraries without porting the underlying code into a new programming language.
然后像子例程一样使用投票来作用于经典位。为了连接到现有的经典编译器基础结构,extern的定义不嵌入在OpenQASM电路中,而是期望以Python、C、x86汇编或LLVM IR等其他语言格式提供给编译工具链。这允许在全局控制器的运行时要求下,使用GCC或LLVM等工具编译externs时,只需最小量的额外结构来管理执行。重要的是,这种连接到现有经典编程基础设施的策略意味着程序员可以使用现有库,而无需将底层代码移植到新的编程语言中。
解释:
这里讨论了如何通过使用子例程和外部程序将经典计算与量子计算结合起来。在量子计算中,可以使用经典位作为子例程,通过使用投票函数,该函数获取三个位参数的大多数“投票”。这个投票函数可以在OpenQASM中实现,但更复杂的经典计算需要不同的方法。
为了提供更复杂的经典计算访问,OpenQASM 3引入了一个“extern”机制,将电路连接到任意的、不透明的经典计算。Extern的声明类似于C头文件中的函数声明,但定义不嵌入在OpenQASM电路中。相反,它应该以另一种语言格式(如Python、C、x86汇编或LLVM IR)提供给编译工具链。这允许externs与像GCC或LLVM这样的工具一起编译,而只需要最少的附加结构来管理在全局控制器的运行时要求下的执行。
连接到现有的经典编程基础设施的策略允许程序员使用现有库,而无需将基础代码移植到新的编程语言中。这特别重要,因为它允许更有效和流畅的编程,而无需对现有代码进行大量重写。此外,这种方法允许量子计算利用现有的经典计算基础设施,这可以减少构建新的量子计算应用程序所需的开发时间和资源。
总之,OpenQASM中使用子例程和外部程序允许将经典计算与量子计算集成,提供更强大和灵活的计算平台。连接到现有的经典编程基础设施的能力使得编程更加高效和流畅,同时还减少了构建新的量子计算应用程序所需的开发时间和资源。
GCC和LLVM都是广泛使用的编译器工具,用于将高级编程语言源代码编译成可执行代码。GCC是GNU编译器套件的一部分,是一种成熟的编译器系统,具有强大的功能和广泛的支持。它支持多种编程语言,包括C、C++、Java、Fortran等,也是许多操作系统和软件的默认编译器。
LLVM是一个相对较新的编译器技术,也是一个可扩展的基础设施,具有强大的静态和动态程序分析、代码生成、代码优化和工具链等功能。与GCC相比,LLVM具有更加模块化和可重用的设计,使得它更加灵活和易于扩展。LLVM还支持多种编程语言,包括C、C++、Objective-C、Swift等。
总体来说,GCC和LLVM都是非常有用的编译器工具,它们有各自的优点和适用场合。开发人员可以根据自己的需求选择使用其中的一种或者结合使用。使用这些工具可以帮助开发人员更容易地将高级编程语言代码转换为可执行代码,从而简化了软件开发过程并提高了代码的效率和质量。
 
OpenQASM is different from other ways of interacting with classical computing. It doesn't have a specific way of synchronizing like the WAIT command in QUIL [3, 73]. When you call an external function, it doesn't create a synchronization boundary. A compiler can add synchronization commands specific to the target at the point where the results of the function are used. When you call an external function, it schedules a classical computation, but doesn't wait for it to finish. The extern semantics abstract away the particulars of a vendor-specific application binary interface (ABI)forhow data are moved to and from the classical function.
extern语义抽象了供应商特定的应用程序二进制接口(ABI)的细节,以确定如何将数据移动到和从经典函数中。
 
 

Input and Output Parameters

In addition to the real-time classical compute constructs of OpenQASM 3, we introduce features targeted to support near-time computation, in the form of OpenQASM programs with input and output parameters (described elsewhere as “parameterized circuits” [46]). This functionality is provided through keywords input and output, which act as modifiers on variable declarations, and allow OpenQASM 3 circuits to represent these variables as accepting input parameters and returning select output parameters.
除了OpenQASM 3的实时经典计算构造,我们还引入了一些功能来支持近实时计算,以OpenQASM程序的形式提供输入和输出参数(在其他地方描述为“参数化电路”[46])。这种功能是通过关键字input和output来提供的,它们作为变量声明的修饰符,允许OpenQASM 3电路将这些变量表示为接受输入参数并返回选择的输出参数。
 
The input modifier can be used to indicate that one or more variable declarations represent values, which will be provided at run-time, upon invocation. This allows the programmer to use the same compiled circuits, which only differ in the values of certain parameters. As OpenQASM 2 did not allow for input parameters or input declaration, for compatibility OpenQASM 3 does not require an input declaration to be provided: in this case it assumes that there are no input parameters. When an input declaration is provided, the compiler produces an executable that leaves these free parameters unspecified: A circuit run would take as input both the executable and some choice of the parameters.
输入修饰符可用于指示一个或多个变量声明表示将在运行时在调用时提供的值。这使得程序员可以使用相同的编译电路,只有某些参数的值不同。由于 OpenQASM 2 不允许输入参数或输入声明,为了兼容性,OpenQASM 3 不需要提供输入声明:在这种情况下,它假定没有输入参数。当提供输入声明时,编译器会生成一个可执行文件,其中这些自由参数未指定:电路运行将作为输入使用可执行文件和某些参数的选择。
 
The output modifier can be used to indicate that one or more variables are to be provided as an explicit output of the quantum procedure. Note that OpenQASM 2 did not allow the programmer to specify that only a subset of its variables should be returned as output, and so it would return all classical variables (which were all creg variables) as output. For compatibility, OpenQASM 3 does not require an output declaration to be provided: In this case it assumes that all of the declared variables are to be returned as output. If the programmer provides one or more output declarations, then only those variables described as outputs will be returned as an output of the quantum process. A variable may not be marked as both input and output.
output 修饰符可用于指示一个或多个变量作为量子程序的显式输出。请注意,OpenQASM 2 不允许程序员指定只返回其变量子集作为输出,因此它将返回所有经典变量(即所有 creg 变量)作为输出。为了保持兼容性,OpenQASM 3 不需要提供输出声明:在这种情况下,它假定所有已声明的变量都将作为输出返回。如果程序员提供一个或多个输出声明,则只有描述为输出的变量将作为量子进程的输出返回。一个变量不能同时被标记为输入和输出。
 
The input and output modifiers allow the programmer to more easily write variational quantum algorithms: A quantum algorithm with some free parameters, which may be run many times with different parameter values which are determined by a classical optimiser at near-time. Rather than write a circuit which generates a new sequence of operations for each run, OpenQASM 3 allows such circuits to be expressed as a single program with input parameters. This allows the programmer to communicate many different circuits with a single file, which only has to be compiled once, amortizing the cost of compilation across many runs.
inputoutput 修饰符允许程序员更轻松地编写变分量子算法:一种具有一些自由参数的量子算法,可以使用不同的参数值运行多次,这些参数值由经典优化器在近实时确定。OpenQASM 3 允许将这样的电路表示为具有输入参数的单个程序,而不是编写为每次运行生成新操作序列的电路。这使得程序员可以使用单个文件来通信许多不同的电路,只需要编译一次,将编译成本分摊到许多运行中。
 
Consider the Variable Quantum Eigensolver (VQE) algorithm [66]. In this algorithm, the same circuit is repeated many times using different sets of free parameters to minimize an expectation value. The following is an example, in which there is also more than one input variable:
考虑可变量子特征求解器(VQE)算法[66]。在此算法中,使用不同的自由参数集重复执行相同的电路以最小化期望值。以下是一个示例,其中还有多个输入变量:
When input and output parameters are not used, the program must be recompiled to account for every change of the input variable theta. Compilation is assumed to be expensive and slow so it will be the main bottleneck toward completion of the overall VQE algorithm.
当不使用输入和输出参数时,程序必须重新编译以考虑输入变量theta的每个更改。编译被认为是昂贵和缓慢的,因此它将成为完成整个VQE算法的主要瓶颈。
When input and output parameters circuits are used, we can hoist compilation out of the loop. The only part of the program that is changing is the value of θ . The entire program does not need to be re-compiled each time.
当使用输入和输出参数电路时,我们可以将编译提出循环。程序中唯一变化的部分是 θ 的值。每次都不需要重新编译整个程序。
 

THE PHYSICAL LEVEL

In addition to support for logical-level quantum computations, OpenQASM 3 has added support for quantum computing experiments and platform-dependent tuning of quantum instructions on the physical level. At the physical level, quantum operations are implemented by causing timevarying stimuli to be transmitted to the qubits, and capturing the time-dependent responses. For example, for superconducting transmon platforms this might take the form of shaped microwave pulses transmitted via a number of coaxial cables, and for trapped ions might take the form of modulated laser pulses. There are various tradeoffs involved in optimal selection of the mapping from logical quantum operations to specific pulse implementations. Therefore, there can be benefits in allowing a programmer who has knowledge of both the hardware limitations and the algorithm requirements to influence the physical implementation for key parts of the circuit. For example, choosing a gate implementation with shorter duration but less-accurate calibration might be a good choice for a variational ansatz where the specific unitary implemented is less important than minimizing decoherence. Another example could be choosing a specific ratio of delays for the idle periods of a qubit to implement spin-echo (and more generally, dynamical decoupling) sequences to cancel out errors caused by hardware parameters that are known to drift slowly compared to the timescale of circuit execution.
除了支持逻辑层量子计算外,OpenQASM 3还增加了对量子计算实验和平台相关量子指令调整的支持。在物理层面上,量子操作是通过向量子比特传输时间变化的刺激并捕获时间相关响应来实现的。例如,对于超导Transmon平台,这可能采用通过多个同轴电缆传输的形状微波脉冲,对于囚禁离子,则可能采用调制激光脉冲的形式。在逻辑量子操作到具体脉冲实现的映射选择上有各种权衡。因此,允许了解硬件限制和算法要求的程序员影响电路关键部分的物理实现可能会带来好处。例如,在变分ansatz中选择持续时间较短但校准不太准确的门实现可能是一个不错的选择,因为具体实现的酉矩阵比最小化去相干更不重要。另一个例子可能是选择特定的空闲期延迟比例来实现自旋回波(更普遍的是,动力学解耦)序列,以消除由硬件参数引起的错误,这些参数已知与电路执行的时间尺度相比变化缓慢。
 

Timing and Optimization

A key aspect of expressing code for quantum experiments is the ability to control the timing of gates and pulses. Examples include characterization of decoherence and crosstalk [39], dynamical decoupling [41, 61, 77], dynamically corrected gates [29, 49], and gate parallelism or scheduling [62]. We introduce such timing semantics in OpenQASM 3 to enable such circuits.
表达量子实验代码的关键方面是能够控制门和脉冲的时间。这些例子包括退相干和串扰的表征[39],动力学解耦[41、61、77],动态校正门[29、49]以及门并行或调度[62]。我们在OpenQASM 3中引入这样的时间语义,以实现这样的电路。
 
 
The design of OpenQASM 3 was naturally influenced by features present in other quantum programming languages, as well as constructions, which are standard concepts in the quantum computing literature and which were considered feasible to include. A number of other features or design choices were also considered. In some cases, these were set aside in the interests of some other design choice; in other cases, they were considered to be possibly worth pursuing but not a core functionality. In this section, we describe how some of the “new” features in OpenQASM 3 (i.e., which extend what existed in OpenQASM 2) relate to the features of other quantum programming languages, which choices were considered but not included in OpenQASM 3, and which choices are still under consideration for inclusion.
OpenQASM 3 的设计自然受到其他量子编程语言中存在的特性的影响,以及量子计算文献中的标准概念和可行性考虑。还考虑了许多其他特性或设计选择。在某些情况下,这些被搁置,以符合其他设计选择的利益;在其他情况下,它们被认为可能值得追求,但不是核心功能。在本节中,我们描述了 OpenQASM 3 中一些“新”的功能(即扩展了 OpenQASM 2 中存在的功能)如何与其他量子编程语言的功能相关,哪些选择被考虑但未包括在 OpenQASM 3 中,哪些选择仍在考虑中是否包括。
💡
THE PHYSICAL LEVEL 剩下的有待更新
 
 

Comparison to Other Quantum Programming Languages There has been significant prior work on quantum programming languages and intermediate representations, some of which have directly influenced OpenQASM. Many high-level quantum programming languages are embedded in classical languages. For example, Scaffold [42], QCL [64], and qcor [59] are embedded in C or C++, Quipper [11] in Haskell, ProjectQ [9] in Python, and QIR [5] in LLVM. On the other hand, languages such as OpenQASM and Quil [73]aredesignedto be standalone and portable intermediate representations. Classical control flow exists in many of the above languages. These are sometimes only used as a means of code compression (i.e., fully unrollable at compile time) [9, 42], and sometimes are intended to mix classical and quantum compute [10, 73]. In embedded languages, the host language provides direct access to classical types and control flow. OpenQASM 3 expands upon these by introducing new types such as angle, and allowing the semantic definition of purely classical extern functions in the context of real-time computation. Gate modifiers (at least for “control”), exist in most of the above programming languages. In OpenQASM 3, we utilize these modifiers for two reasons. First, they decouple semantics from implementation — many implementations could exist for a particular modified gate. Second, modifiers in conjunction with two simple language built-ins (U gate and gphase), generate the entire standard gate library. The use of timing and pulse-level control within quantum circuits has long been present in software and languages used for controlling experiments. Rigorous specifications for this were introduced for example in QGL [4], OpenPulse [60], eQASM [37], Artiq [19], Pulser [72], Jaqal [54], Qua [6], and Quil-t [7]. OpenQASM 3 takes this further by streamlining the incorporation of timing in the circuit model, by allowing timing constraints to be expressed at a level that is decoupled from actual pulse implementations (using stretch). This further motivated the inclusion of a scoping mechanism in OpenQASM 3 in the form of box, which allows references to specific blocks of code and to guide compiler optimizations. This has been addressed before in a more limited form using barriers [27] and pragmas [73].
与其他量子编程语言的比较
在量子编程语言和中间表示方面,已经有了大量的先前工作,其中一些直接影响了OpenQASM。许多高级量子编程语言嵌入在经典语言中。例如,Scaffold [42]、QCL [64]和qcor [59]嵌入在C或C++中,Quipper [11]嵌入在Haskell中,ProjectQ [9]嵌入在Python中,QIR [5]嵌入在LLVM中。另一方面,像OpenQASM和Quil [73]这样的语言被设计成独立的、可移植的中间表示。许多以上语言中存在经典控制流。有时这些只是用作代码压缩的手段(即,在编译时完全展开)[9,42],有时则旨在混合经典和量子计算[10,73]。在嵌入式语言中,宿主语言提供了对经典类型和控制流的直接访问。OpenQASM 3通过引入新的类型如angle,并允许在实时计算的上下文中纯经典extern函数的语义定义,扩展了这些功能。
大多数上述编程语言中都存在门修饰符(至少对于“控制”)。在OpenQASM 3中,我们利用这些修饰符有两个原因。首先,它们将语义与实现解耦——同一种修改后的门可以有许多实现。其次,修饰符与两个简单的语言内置(U门和gphase)结合使用,生成整个标准门库。在量子电路中使用时序和脉冲级控制早已存在于用于控制实验的软件和语言中。例如,QGL [4]、OpenPulse [60]、eQASM [37]、Artiq [19]、Pulser [72]、Jaqal [54]、Qua [6]和Quil-t [7]中引入了严格的规范。OpenQASM 3通过在电路模型中简化时序的整合,允许在与实际脉冲实现解耦的级别上表达时序约束(使用stretch)。这进一步促进了在OpenQASM 3中引入作用域机制的决策,以box的形式,它允许对特定代码块的引用,并指导编译器优化。这在以前使用barriers [27]和pragmas [73]的形式进行了更有限的处理。
 
In this article, we have presented the design decisions in OpenQASM 3 and the rationale behind them. In a similar vein, multiple other language features were contemplated but abandoned or left for future revisions of the language. In the following, we briefly touch upon these. Some languages such as Q# and ProjectQ support resource and memory management, in the form of mid-circuit allocation and de-allocation of qubits. Some languages such as Scaffold allow for the expression of classical code that will then be compiled to reversible quantum circuits (e.g.,oracles). In each of these cases, OpenQASM intentionally remains lower-level and more grounded in executable circuits, aim at keeping the compiler’s complexity more manageable. Conversely, some languages such as Quil have unstructured control flow in the form of explicit program labels and JUMP statements, which are in fact more in the style of a classical assembly language. In order to retain backwards compatibility with OpenQASM 2, we chose not to require any explicit entry points, preferring to allow the program to proceed from the first instruction in a global scope. OpenQASM 3 also adopted the use of for and while loops to express control flow, both to retain easier programmability by humans, and to allow for easier timing analysis by the compiler. These all motivated a design philosophy that it should not be necessary in OpenQASM 3 to manage the (classical) control flow, on a similarly low level to management of quantum operations and resources.
在本文中,我们介绍了OpenQASM 3的设计决策以及背后的原理。类似地,我们考虑了多种其他语言特性,但是放弃了或留给了语言的未来版本进行改进。接下来,我们简要介绍这些特性。一些语言(如Q#和ProjectQ)支持资源和内存管理,以中途分配和解除分配量子比特的形式管理。一些语言(如Scaffold)允许表达经典代码,然后编译为可逆量子电路(例如,oracle)。在这些情况下,OpenQASM有意保持更低级别和更接近可执行电路,旨在使编译器的复杂性更易于管理。相反,一些语言(如Quil)具有明确的程序标签和JUMP语句的非结构化控制流,实际上更符合经典汇编语言的风格。为了保持与OpenQASM 2的向后兼容性,我们选择不需要任何显式入口点,而是更喜欢允许程序从全局范围内的第一条指令继续进行。OpenQASM 3还采用了for和while循环来表达控制流,既为了保持更容易人类可编程性,也为了让编译器更容易进行时间分析。所有这些都激发了一种设计哲学,即在OpenQASM 3中不需要像管理量子操作和资源一样低级别地管理(经典)控制流。
 
The OpenQASM language will continue to evolve; however, within its governance model, and certain features may be added. An example of such a feature are unitary circuit families and generic subroutines, corresponding roughly to templated function definitions, which may be defined entirely in OpenQASM 3. (While such subroutines could be written in a separate host language, writing them in OpenQASM 3 allows for greater portability.) Another language feature, which is at an advanced stage of consideration at the time of writing it the inclusion of classical arrays as a container type; A third feature, which has been set aside, but has been re-proposed for consideration is a fixed-point real number type. The usefulness of such features, the way that they interoperate or conflict with other features, and how they may be incorporated into the language and supported as features is the subject of discussion in working groups established for this purpose. In this way, OpenQASM 3 will continue to evolve, incorporating features, which are sufficiently important and consistent with the other functionality which it provides, through input from the community.
OpenQASM语言将继续发展;然而,在其治理模型内,可能会添加某些功能。这些功能的一个示例是幺正电路族和通用子程序,大致对应于模板函数定义,可以完全在OpenQASM 3中定义。(虽然这样的子程序可以在单独的宿主语言中编写,但在OpenQASM 3中编写可以更具可移植性。)另一个语言特性,在写作时已经处于高级阶段的考虑是将经典数组作为容器类型包含;第三个特性已经被搁置,但已经重新提出以供考虑,那就是固定点实数类型。这些特性的有用性,它们与其他特性的相互作用或冲突方式,以及如何将它们作为特性合并到语言中并支持它们,是为此目的而设立的工作组讨论的主题。通过社区的输入,OpenQASM 3将继续发展,包括足够重要且与其提供的其他功能一致的特性。
 
OpenQASM 3 has introduced language features that both expand and deepen the scope quantum circuits that can be described with particular focus on their physical implementation and the interactions between classical and quantum computing. We have endeavored throughout to give a consistent “look and feel” to these features so that regardless of abstraction level, OpenQASM 3 still feels like one language. This manuscript has illustrated the primary new features introduced in OpenQASM 3 and put those features in context with examples. In particular, we have shown features and representations appropriate to a variety of abstraction levels and use cases, from highlevel gate modifiers to low-level microcoded gate implementations. Language design is an open-ended problem and we expect that as we attempt to use OpenQASM 3 to program circuits on our primitive quantum computers we will discover many awkward constructions, missing features, or incomplete specifications in the language. We fully expect the language to continue to evolve over time driven by real-world usage and hardware development. In particular, there are already proposals under consideration to modify implicit type conversions or enable code re-use through generic functions. Consequently, the formal language specification is posted as a live document [2] within the Qiskit project. We will be forming a formal process for reviewing proposed changes so that OpenQASM might continue to adapt to the needs of its users.
OpenQASM 3引入了语言特性,扩展和深化了可以用特定重点描述的量子电路的范围,特别关注其物理实现和经典与量子计算之间的交互。我们一直努力为这些特性提供一致的“外观和感觉”,使得无论抽象级别如何,OpenQASM 3仍然感觉像一种语言。本文介绍了OpenQASM 3中引入的主要新特性,并将这些特性与示例放在上下文中。特别是,我们展示了适用于各种抽象级别和用例的特性和表示形式,从高级门修改器到低级微码门实现。语言设计是一个开放式的问题,我们希望随着我们尝试使用OpenQASM 3在原始量子计算机上编程电路,我们将发现语言中许多尴尬的构造,缺失的特性或不完整的规范。我们完全希望这种语言能够随着真实世界的使用和硬件开发的推动而不断发展。特别是,已经有提议考虑通过通用函数修改隐式类型转换或启用代码重用。因此,正式的语言规范发布为Qiskit项目中的实时文档[2]。我们将形成一个正式的过程,审查建议的更改,以便于OpenQASM能够继续适应其用户的需求。
 
 
头脑风暴:
  • Develop a tutorial on how to program a simple quantum circuit using OpenQASM 2
  • Write an article comparing OpenQASM and other quantum programming languages
  • Discuss the benefits and drawbacks of using OpenQASM for quantum computing research and development
  • Explore the use of OpenQASM in building hybrid classical-quantum applications
  • Investigate the extensibility of OpenQASM and its support for user-defined macros and functions
  • Analyze the role of intermediate representations in quantum programming and how OpenQASM uses them
  • Compare the syntax of OpenQASM to other programming languages, such as C and assembly
  • Showcase real-world applications of OpenQASM in quantum computing research
  • Discuss the challenges of implementing opaque gates in OpenQASM and propose solutions
  • Write a beginner's guide to quantum computing with OpenQASM as the programming language of choice.
  • 制作一个使用OpenQASM 2编写简单量子电路的教程
  • 撰写一篇比较OpenQASM和其他量子编程语言的文章
  • 探讨使用OpenQASM进行量子计算研究和开发的优缺点
  • 探索在构建混合经典量子应用程序中使用OpenQASM的方法
  • 调查OpenQASM的可扩展性及其对用户定义的宏和函数的支持
  • 分析中间表示在量子编程中的作用以及OpenQASM如何使用它们
  • 比较OpenQASM的语法与其他编程语言,如C和汇编语言
  • 展示OpenQASM在量子计算研究中的实际应用
  • 讨论在OpenQASM中实现不透明门的挑战并提出解决方案
  • 写一篇以OpenQASM作为编程语言选择的量子计算入门指南。
What’s in the latest OpenQASM specification? | by Qiskit | Qiskit | Medium
  • Giscus
quantum
literature base
video notes