Source-linked AI summary

ProjectQ: An Open Source Software Framework for Quantum Computing

Damian S. Steiger, Thomas Häner, Matthias Troyer

arXiv:1612.08091v2quant-phcs.ETcs.PL

TL;DR

Quantum computing needs software that scales beyond gate-level programming as hardware test beds grow. ProjectQ provides an open-source, modular framework with high-level Python programming, compilation, simulation, emulation, and hardware back-ends; it reports efficient algorithm compilation, high-performance simulation, and IBM Quantum Experience access. Its scope remains bounded by unfinished noise-model and very-large-circuit resource-estimation support.

  • Problem

    Growing quantum hardware requires a full software stack that accelerates development and raises programming from individual gates to higher-level algorithms.

  • Method

    ProjectQ combines a Python-embedded high-level language, modular compiler, simulation and emulation back-ends, resource tools, and interfaces to quantum hardware.

  • Results

    ProjectQ compiles high-level algorithms to low-level back-ends, supports efficient simulation and emulation, and enables execution through an IBM Quantum Experience back-end.

  • Takeaways & Limitations

    ProjectQ provides reusable extension points for compiler components, hardware back-ends, and quantum-algorithm development across simulation and hardware workflows.

  • Takeaways & Limitations

    Resource estimates for very large circuits require caching at every intermediate layer, a feature planned for future work.

Abstract

from arXiv · show

We introduce ProjectQ, an open source software effort for quantum computing. The first release features a compiler framework capable of targeting various types of hardware, a high-performance simulator with emulation capabilities, and compiler plug-ins for circuit drawing and resource estimation. We introduce our Python-embedded domain-specific language, present the features, and provide example implementations for quantum algorithms. The framework allows testing of quantum algorithms through simulation and enables running them on actual quantum hardware using a back-end connecting to the IBM Quantum Experience cloud service. Through extension mechanisms, users can provide back-ends to further quantum hardware, and scientists working on quantum compilation can provide plug-ins for additional compilation, optimization, gate synthesis, and layout strategies.

1 Introduction

ProjectQ addresses the need for a full quantum-computing software stack by combining high-level programming, modular compilation, simulation, emulation, and hardware access.

  • Motivation: The framework is intended to accelerate quantum software and hardware development as test devices scale toward larger numbers of qubits.It aims to support higher-level algorithm descriptions rather than programming individual quantum gates.
  • High-level programming: ProjectQ uses a Python-embedded domain-specific language to express quantum algorithms at a higher level than individual gates.The device-independent language is automatically compiled to hardware instructions and other back-ends.
  • Compilation: Its modular compiler transforms high-level programs into optimized instructions for different hardware platforms, simulators, emulators, and resource estimators.Compiler components and intermediate representations can be adapted as hardware specifications change.
  • Simulation and back-ends: ProjectQ integrates a quantum emulator that uses classical shortcuts for speedups of several orders of magnitude and a simulator that outperforms its predecessor.The framework also supports circuit drawing and resource estimation through compiler back-ends and plug-ins.
  • Hardware access: A hardware back-end has been tested with actual hardware and enables running quantum algorithms through the IBM Quantum Experience.Users can change the back-end to target available hardware or software systems.

2 The ProjectQ Framework

ProjectQ is an open-source, extensible quantum-computing framework organized around accessible interfaces, modular components, and reusable development infrastructure.

  • Framework principles: ProjectQ provides clean interfaces for extending and improving its compiler and back-end components.Its four stated principles are open and free, a simple learning curve, easy extensibility, and high code quality.
  • Open and free: The framework is released under the Apache 2 license, allowing free commercial use.The license is presented as a means of encouraging wide use.
  • Simple learning curve: Python provides the implementation language and learning interface, while selected computational kernels use high-performance C++ behind that interface.The paper identifies Python’s use in the quantum community and its simpler learning curve as motivations.
  • Easily extensible: Modular compiler and back-end implementations let users adapt ProjectQ to new gates or entirely different gate sets.This extensibility supports changes to compilation and hardware interfaces.
  • High code quality: Mandatory code reviews, continuous integration, unit and functional tests, and extensive documentation support the stated code-quality standard.The current unit-test coverage is reported as 99% of lines.
  • Community development: The initial release welcomes contributions of quantum algorithms, compiler engines, and interfaces to quantum-hardware back-ends.The framework is intended to gain new features over time.

3 Quantum Programs and Compilation

ProjectQ demonstrates high-level quantum programming and compilation through Shor’s algorithm and Fourier-space addition, where intermediate representations enable effective local optimization and hardware adaptation.

  • Quantum programs: Shor’s factoring algorithm is implemented in a high-level language to motivate ProjectQ’s programming and compilation methodology.The example uses modular exponentiation built from controlled modular adders.
  • Fourier-space addition: Draper’s Fourier-space constant adder applies a QFT, phase shifts determined by the constant, and an inverse QFT.This representation is selected because sequential additions offer substantial optimization opportunities.
  • Circuit optimization: Sequential controlled additions can cancel adjacent inverse and forward QFT operations and merge some controlled phase-shift gates.The phase-shift merging depends on the constants being added.
  • Intermediate representations: ProjectQ performs optimization across several intermediate gate sets because low-level decomposition can make cancellations expensive or impossible after approximation.Local optimization at intermediate levels preserves higher-level structure for longer.
  • Compiler architecture: The modular compiler combines compiler engines and can replace hardware-specific components, including mappers, to target different architectures.Custom intermediate gate sets can improve optimization for particular algorithmic primitives.

4 Features

ProjectQ provides a Python-embedded quantum language with qubit and register abstractions, quantum operations, custom gates, and meta-instructions for concise, optimizable programs.

  • High-level language: ProjectQ programs use a Python-embedded domain-specific language centered on MainEngine, which contains compiler engines and a simulator back-end by default.The minimal example imports MainEngine, H, and Measure, then allocates, operates on, measures, and prints a qubit.
  • Quantum types: Qubits are allocated dynamically through MainEngine, while quantum registers are represented as lists of qubits and support higher-level types such as quint, qufixed, and qufloat.allocate_qubit() creates a one-qubit register, whereas allocate_qureg(n) creates an n-qubit register.
  • Resource management: ProjectQ handles qubit deallocation through Python garbage collection, enabling qubit reuse and automatic parallelization, while requiring qubits to be measured or uncomputed before deallocation.The simulator detects invalid deallocation by throwing an exception when a qubit remains in superposition.
  • Quantum operations: Quantum operations can be Python functions or custom ProjectQ gates; gate-based implementations preserve high-level optimization and permit specialized decompositions selected for a target back-end.Custom gates can be merged, decomposed according to user-defined costs, or executed natively when supported by a back-end or emulator.
  • Meta-instructions: Meta-instructions express control, compute/uncompute, inversion, and looping over code blocks, enabling compiler optimizations while keeping user code concise.Compute, Uncompute, and CustomUncompute annotate compute/action/uncompute sections; Dagger implements unitary inversion, and Loop supports repeated execution.

4.2 Compiler and compiler engines

ProjectQ uses a customizable chain of compiler engines that translates quantum operations through intermediate gate sets to hardware-native instructions. Its local compilation strategy limits stored circuit information and supports optimization, hardware adaptation, reuse, and parallelization.

  • Compiler architecture: The compiler is a customizable chain of engines, with each engine performing one task and the final back-end defining the lowest-level gate set.A minimal compiler uses AutoReplacer to decompose circuits into the back-end’s native gates; richer chains add translators, optimizers, and filters.
  • Intermediate representations: Intermediate gate sets allow optimization at multiple abstraction levels, including cancellation of inverse QFT operations around consecutive controlled additions.AutoReplacer engines decompose instructions into the gate set accepted by the next compiler engine.
  • Reusable configurations: Compiler engines and decomposition rules can be saved as reusable setups for a specific back-end.This supports repeated use of an established compilation configuration.
  • Local compilation: ProjectQ avoids storing the entire circuit: AutoReplacer processes one gate at a time, while LocalOptimizer stores only a short gate sequence before optimization.This locality of compilation addresses memory requirements for algorithms containing vast numbers of logical gates and allows parallelization.

4.3 Back-ends

ProjectQ provides modular back-ends for hardware execution, gate-level simulation, high-level emulation, resource estimation, and circuit drawing. These back-ends support testing, benchmarking, compilation to IBM hardware, and publication-ready circuit visualization.

  • ProjectQ back-ends can run circuits on quantum hardware, simulate individual gates, emulate circuits using high-level shortcuts, estimate resources, and draw circuits.
  • The IBM Quantum Experience back-end compiles high-level entanglement into gates, remaps CNOTs for hardware connectivity, optimizes the circuit, and maps it to physical qubits.
  • ProjectQ’s gate-level simulator supports user-specified gate sets, AVX instructions, and OpenMP threads, and is substantially faster than its predecessor.
  • High-level emulation uses shortcuts such as direct arithmetic evaluation, avoiding decomposition and extra ancilla-qubit simulation to achieve execution speedups of orders of magnitude.
  • Emulation supports numerical studies of high-level parameters using the same code as resource estimation, while changing only one line of code.
  • ResourceCounter tracks encountered gates and maximal circuit width, while CircuitDrawer produces TikZ-LATEX code and can draw circuits at multiple abstraction levels.

5 Road map

ProjectQ’s roadmap extends its libraries, classical simulation, compiler capabilities, and hardware connectivity to support broader quantum-computing development.

  • ProjectQ plans regular extensions with libraries, compiler engines, and additional hardware back-ends.
  • Libraries: The project is developing fermilib for fermionic quantum simulation and integration with open-source electronic-structure packages.
  • Libraries: ProjectQ will expand its math library with high-performance quantum implementations needed for resource estimation and execution on hardware.
  • Back-ends: Further hardware back-ends are being developed, including a planned interface to J. Home’s ion-trap devices.
  • Classical back-ends: A distributed massively parallel simulator is being added to support simulations of up to 45 qubits.
  • Compiler engines: New compiler engines will support advanced layouting for error correction and resource analysis before large-scale hardware exists.

A Examples

This section introduces complete ProjectQ examples that are included with the framework’s source code.

  • Complete examples are discussed and included with the ProjectQ sources.

A.1 Quantum Teleportation

The teleportation example constructs a Bell pair, entangles an input state with it, measures Alice’s qubits, and conditionally applies corrections to Bob’s qubit.

  • The example allocates two qubits and entangles them into a Bell pair using Hadamard and controlled-not gates.
  • A third qubit is prepared in the state to be teleported and entangled with Alice’s first Bell-pair qubit.
  • Alice measures the relevant qubits, including one measurement in the Hadamard basis, and sends the resulting classical bits to Bob.
  • Bob conditionally applies X and Z operations to his qubit according to Alice’s measurement message.
  • Using the CircuitDrawer back-end generates the quantum teleportation circuit shown in Fig. 8.

A.2 Grover search

The Grover example implements the two oracle operations iteratively: one marks the target state, while the other reflects across the uniform superposition.

  • Grover’s algorithm searches for an element e using a quadratic speedup.
  • The first oracle U_f marks the target element by adding a phase of −1 to its quantum state.
  • The second oracle reflects the state across the uniform superposition.
  • The two operators are applied iteratively approximately π√N/4 times, where N is the number of possible function inputs.
  • The supplied implementation uses ProjectQ’s Loop, Compute, and Uncompute constructs to perform repeated oracle and reflection steps.
  • The Loop instruction can avoid unrolling when hardware or compiler engines support executing or optimizing loops.

A.3 Shor’s algorithm for factoring

ProjectQ uses its Python-embedded DSL and quantum math library to express modular arithmetic and Shor’s factoring algorithm compactly. The implementation combines iterative modular multiplication with a semi-classical inverse QFT, measurement, and qubit reuse.

  • Modular arithmetic: ProjectQ’s eDSL implements Beauregard’s modular adder with code efficiency comparable to a hand-optimized implementation.The example uses meta-instructions to express the modular adder.
  • Modular arithmetic: The modular-adder routine validates 0 <= c < N, allocates an ancilla, applies controlled addition and subtraction, then custom-uncomputes the ancilla.Compute and CustomUncompute organize the ancilla operations and cleanup.
  • Shor’s algorithm: A complete Shor implementation is provided, with modular multiplication and shifting used for modular exponentiation of a by a 2n-bit quantum number.The implementation is described as taking only a few lines using ProjectQ’s quantum math library.
  • Shor’s algorithm: The algorithm processes the bits of x separately using a semi-classical inverse QFT, iterating over all 2n bits and shifting the multiplier for each iteration.The code allocates a control qubit and computes the current multiplier as a power of a.
  • Shor’s algorithm: Each inverse-QFT iteration prepares the control qubit, applies controlled modular multiplication, performs conditioned rotations, then applies a final Hadamard before measurement.The measurement result is stored, and the qubit is reset for reuse in the next iteration.
Loading 1612.08091v2…