Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove underscores from qiskit.qasm #2080

Merged
merged 3 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qiskit/circuit/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import sympy
import numpy

from qiskit.qasm._node import _node
from qiskit.qasm.node import node
from qiskit.exceptions import QiskitError
from qiskit.circuit.classicalregister import ClassicalRegister

Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(self, name, num_qubits, num_clbits, params):
if isinstance(single_param, sympy.Basic):
self.params.append(single_param)
# example: OpenQASM parsed instruction
elif isinstance(single_param, _node.Node):
elif isinstance(single_param, node.Node):
self.params.append(single_param.sym())
# example: u3(0.1, 0.2, 0.3)
elif isinstance(single_param, (int, float)):
Expand Down
11 changes: 5 additions & 6 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""
Quantum circuit object.
"""
"""Quantum circuit object."""

from copy import deepcopy
import itertools
import sys
import multiprocessing as mp

from qiskit.qasm import _qasm
from qiskit.qasm.qasm import Qasm
from qiskit.exceptions import QiskitError
from .quantumregister import QuantumRegister
from .classicalregister import ClassicalRegister
Expand Down Expand Up @@ -465,7 +464,7 @@ def from_qasm_file(path):
Return:
QuantumCircuit: The QuantumCircuit object for the input QASM
"""
qasm = _qasm.Qasm(filename=path)
qasm = Qasm(filename=path)
return _circuit_from_qasm(qasm)

@staticmethod
Expand All @@ -477,7 +476,7 @@ def from_qasm_str(qasm_str):
Return:
QuantumCircuit: The QuantumCircuit object for the input QASM
"""
qasm = _qasm.Qasm(data=qasm_str)
qasm = Qasm(data=qasm_str)
return _circuit_from_qasm(qasm)


Expand Down
2 changes: 1 addition & 1 deletion qiskit/qasm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

from sympy import pi

from ._qasm import Qasm
from .qasm import Qasm
from .exceptions import QasmError
35 changes: 0 additions & 35 deletions qiskit/qasm/_node/__init__.py

This file was deleted.

36 changes: 36 additions & 0 deletions qiskit/qasm/node/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-

# Copyright 2017, IBM.
#
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""QASM nodes."""

from .barrier import Barrier
from .binaryop import BinaryOp
from .binaryoperator import BinaryOperator
from .cnot import Cnot
from .creg import Creg
from .customunitary import CustomUnitary
from .expressionlist import ExpressionList
from .external import External
from .gate import Gate
from .gatebody import GateBody
from .id import Id
from .idlist import IdList
from .if_ import If
from .indexedid import IndexedId
from .intnode import Int
from .format import Format
from .measure import Measure
from .opaque import Opaque
from .prefix import Prefix
from .primarylist import PrimaryList
from .program import Program
from .qreg import Qreg
from .real import Real
from .reset import Reset
from .unaryoperator import UnaryOperator
from .universalunitary import UniversalUnitary
from .nodeexception import NodeException
9 changes: 4 additions & 5 deletions qiskit/qasm/_node/_barrier.py → qiskit/qasm/node/barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""
Node for an OPENQASM barrier statement.
"""
from ._node import Node
"""Node for an OPENQASM barrier statement."""

from .node import Node


class Barrier(Node):
Expand All @@ -19,7 +18,7 @@ class Barrier(Node):

def __init__(self, children):
"""Create the barrier node."""
Node.__init__(self, 'barrier', children, None)
super().__init__('barrier', children, None)

def qasm(self, prec=15):
"""Return the corresponding OPENQASM string."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""
Node for an OPENQASM binary operation expression.
"""
"""Node for an OPENQASM binary operation expression."""

import sympy

from ._node import Node
from .node import Node


class BinaryOp(Node):
Expand All @@ -23,7 +22,7 @@ class BinaryOp(Node):

def __init__(self, children):
"""Create the binaryop node."""
Node.__init__(self, 'binop', children, None)
super().__init__('binop', children, None)

def qasm(self, prec=15):
"""Return the corresponding OPENQASM string."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""
Node for an OPENQASM binary operator.
"""
"""Node for an OPENQASM binary operator."""

import operator

from ._node import Node
from ._nodeexception import NodeException
from .node import Node
from .nodeexception import NodeException


VALID_OPERATORS = {
Expand All @@ -30,7 +29,7 @@ class BinaryOperator(Node):
"""
def __init__(self, operation):
"""Create the operator node."""
Node.__init__(self, 'operator', None, None)
super().__init__('operator', None, None)
self.value = operation

def operation(self):
Expand Down
9 changes: 4 additions & 5 deletions qiskit/qasm/_node/_cnot.py → qiskit/qasm/node/cnot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""
Node for an OPENQASM CNOT statement.
"""
from ._node import Node
"""Node for an OPENQASM CNOT statement."""

from .node import Node


class Cnot(Node):
Expand All @@ -20,7 +19,7 @@ class Cnot(Node):

def __init__(self, children):
"""Create the cnot node."""
Node.__init__(self, 'cnot', children, None)
super().__init__('cnot', children, None)

def qasm(self, prec=15):
"""Return the corresponding OPENQASM string."""
Expand Down
9 changes: 4 additions & 5 deletions qiskit/qasm/_node/_creg.py → qiskit/qasm/node/creg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

# pylint: disable=invalid-name

"""
Node for an OPENQASM creg statement.
"""
from ._node import Node
"""Node for an OPENQASM creg statement."""

from .node import Node


class Creg(Node):
Expand All @@ -21,7 +20,7 @@ class Creg(Node):

def __init__(self, children):
"""Create the creg node."""
Node.__init__(self, 'creg', children, None)
super().__init__('creg', children, None)
# This is the indexed id, the full "id[n]" object
self.id = children[0]
# Name of the creg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

# pylint: disable=invalid-name

"""
Node for an OPENQASM custom gate statement.
"""
from ._node import Node
"""Node for an OPENQASM custom gate statement."""

from .node import Node


class CustomUnitary(Node):
Expand All @@ -29,7 +28,7 @@ class CustomUnitary(Node):

def __init__(self, children):
"""Create the custom gate node."""
Node.__init__(self, 'custom_unitary', children, None)
super().__init__('custom_unitary', children, None)
self.id = children[0]
self.name = self.id.name
if len(children) == 3:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""
Node for an OPENQASM expression list.
"""
from ._node import Node
"""Node for an OPENQASM expression list."""

from .node import Node


class ExpressionList(Node):
Expand All @@ -19,7 +18,7 @@ class ExpressionList(Node):

def __init__(self, children):
"""Create the expression list node."""
Node.__init__(self, 'expression_list', children, None)
super().__init__('expression_list', children, None)

def size(self):
"""Return the number of expressions."""
Expand Down
11 changes: 5 additions & 6 deletions qiskit/qasm/_node/_external.py → qiskit/qasm/node/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

# pylint: disable=invalid-name

"""
Node for an OPENQASM external function.
"""
"""Node for an OPENQASM external function."""

import sympy
from ._node import Node
from ._nodeexception import NodeException
from .node import Node
from .nodeexception import NodeException


class External(Node):
Expand All @@ -24,7 +23,7 @@ class External(Node):

def __init__(self, children):
"""Create the external node."""
Node.__init__(self, 'external', children, None)
super().__init__('external', children, None)

def qasm(self, prec=15):
"""Return the corresponding OPENQASM string."""
Expand Down
12 changes: 5 additions & 7 deletions qiskit/qasm/_node/_format.py → qiskit/qasm/node/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
# This source code is licensed under the Apache License, Version 2.0 found in
# the LICENSE.txt file in the root directory of this source tree.

"""
Node for an OPENQASM file identifier/version statement.
"""
"""Node for an OPENQASM file identifier/version statement."""

import re

from ._node import Node
from .node import Node


class Format(Node):
"""Node for an OPENQASM file identifier/version statement.
"""
"""Node for an OPENQASM file identifier/version statement."""

def __init__(self, value):
"""Create the version node."""
Node.__init__(self, "format", None, None)
super().__init__("format", None, None)
parts = re.match(r'(\w+)\s+(\d+)\.(\d+)', value)
self.language = parts.group(1)
self.majorversion = parts.group(2)
Expand Down
9 changes: 4 additions & 5 deletions qiskit/qasm/_node/_gate.py → qiskit/qasm/node/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

# pylint: disable=invalid-name

"""
Node for an OPENQASM gate definition.
"""
from ._node import Node
"""Node for an OPENQASM gate definition."""

from .node import Node


class Gate(Node):
Expand All @@ -25,7 +24,7 @@ class Gate(Node):

def __init__(self, children):
"""Create the gate node."""
Node.__init__(self, 'gate', children, None)
super().__init__('gate', children, None)
self.id = children[0]
# The next three fields are required by the symbtab
self.name = self.id.name
Expand Down
Loading