Skip to content

TeamGraphix/graphix-qasm-parser

Repository files navigation

Graphix OpenQASM Parser

graphix-qasm-parser is a plugin for the Graphix library that parses OpenQASM circuit specifications into graphix.transpiler.Circuit objects, which can then be transpiled into MBQC patterns.

It is distributed as a separate plugin because it depends on openqasm-parser.

Installation

pip install https://github.com/thierry-martinez/graphix-qasm-parser.git

Usage

Parsing a string:

from graphix_qasm_parser import OpenQASMParser

s = """
    include "qelib1.inc";
    qubit q;
    rz(5*pi/4) q;
"""
parser = OpenQASMParser()
circuit = parser.parse_str(s)
pattern = circuit.transpile().pattern
print(pattern)

Parsing a file:

circuit = parser.parse_file("my_circuit.qasm")

Supported Specification

  • Single-qubit registers: qubit q, or the old syntax qreg q.

  • Qubit register arrays: qubit[n] q, or the old syntax qreg q[n].

Supported Gates

OpenQASM gate Graphix instruction
ccx CCX
crz RZZ
cx CX
swap SWAP
h H
s S
x X
y Y
z Z
rx RX
ry RY
rz RZ

Expressions

Expressions with arithmetic operators (+, -, *, /, %) are supported. The constant pi (or π) is defined.

Compile-time constants can be defined and used in expressions.

About

A Graphix plugin for parsing OpenQASM circuit specifications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages