Blog

Home / Blog

Microsoft taps LLVM for Quantum Computing

William Tsu
Data Analyst
Experienced data analyst working with data visualization, cloud computing and ETL solutions.
October 22, 2020


LLVM: The power behind Swift & other similar languages!

The compiler framework helps with programmatically generating machine-native codes. The compiler framework has also made it easier to combine & roll new languages that aid in an increased output while enhancing the existing ones. As part of technology updation, new languages along with existing ones are getting compiled throughout a development landscape.

For example, Apple's Swift, Mozilla's Rust, and many other languages provide developers a new range of options that include speed, safety, convenience, power, and portability. This compilation is made possible by several compilers; the chief of which is LLVM: an open-source project.

• Low-Level Virtual Machine (LLVM) aids in creating new languages as well as enhancing the existing ones.

• Tools are provided by LLVM for automating many demanding parts of language creation.

The tasks that get fulfilled include: compiler creation, porting an outputted code to multiple platforms & architectures, generating architecture-specific optimizations that include vectorization, and writing codes for handling common language metaphors.

LLVM is essentially a library for programmatically creating machine native-codes. Usually, a developer makes use of Application Programming Interfaces (APIs) to generate instructions in a format referred to as an Intermediate Representation (IR). LLVM compiles the IR into a standalone binary or it performs a Just-in-Time (JIT) compilation on the codes for running in context to another program. LLVM is equipped with several functions & global variables that form the standard elements in IR. The implementations of LLVM helps in focusing on the parts of your language that needs attention.

LLVM: Designed to aid portability

LLVM's IR is designed for being a portable assembly. The portability gets accomplished by offering primitives independent of any particular machine architecture. The architectural design of LLVM makes it easier for supporting all kinds of hardware, which makes it ideal for portability. The most common use of LLVM is an ahead-of-time (AOT) compiler for languages.

Certain features of LLVM, which makes it the best compiler used by developers:

• Just-in-Time Compiling with LLVM: - Situations arise wherein codes need to be generated on the fly during runtime, rather than getting compiled! LLVM makes it happen with its feature referred to as Just-in-Time!

• Automatic Code Optimization: - Apart from compiling the IR to native machine codes, LLVM helps with the optimization of codes with a high degree of granularity, all the way through the granularity. These optimizations are quite aggressive and comprise of in-lining functions, and elimination of dead codes, as well as unrolling of loops.

• Dominic specific languages with LLVM: - LLVM aids in producing compilers for many general-purpose languages. Specific languages also get generated using LLVM, which is related to a problematic domain. An LLVM IR Code gets converted into JavaScript, which showcases its flexibility. Adding domain-specific extensions to an existing language gets done by LLVM. LLVM is itself compiled using the C++ language. The Application Programming Interfaces (APIs) of LLVM is available in both C and C++.

• LLVM compiler infrastructure maps various high-level classical programming languages, which include C, C++, Objective-C, and FORTRAN to a common intermediate representation (IR). This IR is used to perform hardware analysis as well as optimizations for generating efficient hardware-specific executable code. Standard IR for quantum computation enables a wide-ranging of programming through domain-specific algorithms in a manner that best suits the research & application.

The things LLVM doesn't do are as follows:

Managing software packages in installation, installing the computer's binaries, and upgrading of tool-chain; all gets done by the developers.

Quantum Computing

Quantum computing deals with harnessing & exploiting the laws of quantum mechanics for processing valuable information. A quantum computer works with quantum bits (qubits), which encode the binary digits of zero & one into two distinguishable quantum states. A Quantum system can be in multiple states at the same time; a phenomenon referred to as superposition. Entanglement, an extremely powerful & strong correlation that exists between the quantum particles, is a unique feature exhibited by the qubits. They seem to be perfectly connected in unison, even if separated by great distances!

The quantum computer processes a vast number of calculations simultaneously, which enable perfect execution of certain difficult tasks that are impossible to be performed with classic computers. Quantum computers are adept in factoring large numbers for starters! Quantum mechanics create ultra-secret keys that are used in encrypting many confidential details.

The quantum key distribution (QKD) relies on an interesting property of quantum mechanics: a quantum system gets disturbed on any attempt for observing or measuring it. The proper harnessing of the quantum world breaks & make codes, which can be beneficial in several sectors. Simulation of quantum system helps with studying the interactions between atom & molecules in great detail. For instance, this helps in creating innovations that help with solving many conundrums! A quantum computer is inherently faster than a normal, classic computer.

LLVM

For quantum computing, qubits are required. These qubits are tricky to manipulate by avoiding decoherence. Quantum error correction does stave off this phenomenon in which a disturbance can knock-out the intricate balance needed by qubits. New creative ways are being discovered every day for the effective use of qubits & quantum computing.

Quantum technology & computing is commercially available with many discoveries being made in the area of quantum computing. The quantum sensors as well as actuators help scientists navigate a nano-scale world with utmost precision & sensitivity.

Microsoft taps LLVM for Quantum Computing!

Microsoft created a common interface that connects various programming languages with target quantum computers. Intermediate Representation (IR) got introduced by Microsoft for the quantum programs: Quantum Intermediate Representation (QIR). The QIR serves as a common interface, as mentioned before, for the Gate-Based Quantum Computing as well as the Target Computing platforms.

Quantum Intermediate Representation (QIR)

QIR got launched on September 23 by Microsoft and is based on the LLVM intermediate language. The QIR specifies certain rules for representing quantum constructs in LLVM. There is no necessity for any extensions or modifications to LLVM. Quantum Intermediate Representation supports Microsoft's open source Q# language for developing quantum algorithms. With this process, any language for Gate-Based Quantum Computing get represented.

LLVM based C-Lang (Clang) Compiler

One important application enabled by QIR involves using the LLVM based Clang compiler. This Clang compiler helps in compiling QIR into executable machine codes providing a path to build a simulator in C or C++. Implementing quantum instruction set functions makes it happen. Microsoft announced that the QIR specifications will be made available in the new Q# language repository of GitHub. A compiler extension, which generates QIR from Q# is made available as well and found in the feature or QIR branch of the Q# compiler repository with proper extension-usage directions posted.

The Integration!

According to Microsoft, as quantum computing capabilities mature, majority of the large scale quantum applications take advantage of both classical as well as quantum resources working as a team! LLVM do offer the QIR capabilities for describing this connection between classical, and quantum resources integrated with quantum computing. LLVM support the integration with many languages and tools, which is supported by the LLVM tool chain.

Intermediate Representation (IR)

Compliers showcase a common pattern by compiling the source language into an intermediate representation (IR). IR gets designed for allowing different source languages to be represented. The code gets optimized & transformed due to this IR. The actual target execution platform is found out and IR gets compiled to an executable code. Many source languages share a common set of optimizers as well as executable generators. With IR, it becomes easier for compiling a single source language for many different targets. The IR provide a common platform to be shared across various sources along with targets. It also allows a re-use in the compiler machinery.

Forecasts!

Microsoft anticipates & forecasts more advances on the ways by which the classical as well as quantum computations interact at the hardware level. With QIR, the goal provides a single representation, which get used for both current restricted capabilities as well as more powerful systems of future. Microsoft estimates that the communities develop more optimizations, and code transformations.

Conclusion

Microsoft taps LLVM for quantum computing as it allows a lot of features to be fulfilled. Quantum computing is still at a progressive stage with lot of discoveries happening in the field pretty frequently. A good integration between classical computers as well as their quantum counterparts is necessary for an effective process of getting more out of quantum computers. The QIR, and IR of LLVM makes this possible and this forms the major reason behind Microsoft tapping LLVM for quantum computing. Evolution & innovation of quantum computing gets underway in the proper way with the help of LLVM.