diff --git a/qiskit/circuit/instruction.py b/qiskit/circuit/instruction.py index 4268b68225e9..d73d23d712dc 100644 --- a/qiskit/circuit/instruction.py +++ b/qiskit/circuit/instruction.py @@ -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 @@ -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)): diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index 06eebc0c0db7..126c99717bb8 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -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 @@ -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 @@ -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) diff --git a/qiskit/qasm/__init__.py b/qiskit/qasm/__init__.py index d79e3a33760a..58d43f551a8f 100644 --- a/qiskit/qasm/__init__.py +++ b/qiskit/qasm/__init__.py @@ -12,5 +12,5 @@ from sympy import pi -from ._qasm import Qasm +from .qasm import Qasm from .exceptions import QasmError diff --git a/qiskit/qasm/_node/__init__.py b/qiskit/qasm/_node/__init__.py deleted file mode 100644 index 01ee90cddbbe..000000000000 --- a/qiskit/qasm/_node/__init__.py +++ /dev/null @@ -1,35 +0,0 @@ -# -*- 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 diff --git a/qiskit/qasm/node/__init__.py b/qiskit/qasm/node/__init__.py new file mode 100644 index 000000000000..1c7f265e2498 --- /dev/null +++ b/qiskit/qasm/node/__init__.py @@ -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 diff --git a/qiskit/qasm/_node/_barrier.py b/qiskit/qasm/node/barrier.py similarity index 80% rename from qiskit/qasm/_node/_barrier.py rename to qiskit/qasm/node/barrier.py index 95aae110fccf..076b6023d20d 100644 --- a/qiskit/qasm/_node/_barrier.py +++ b/qiskit/qasm/node/barrier.py @@ -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): @@ -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.""" diff --git a/qiskit/qasm/_node/_binaryop.py b/qiskit/qasm/node/binaryop.py similarity index 91% rename from qiskit/qasm/_node/_binaryop.py rename to qiskit/qasm/node/binaryop.py index 5fb258b81e38..52f67a199d50 100644 --- a/qiskit/qasm/_node/_binaryop.py +++ b/qiskit/qasm/node/binaryop.py @@ -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): @@ -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.""" diff --git a/qiskit/qasm/_node/_binaryoperator.py b/qiskit/qasm/node/binaryoperator.py similarity index 86% rename from qiskit/qasm/_node/_binaryoperator.py rename to qiskit/qasm/node/binaryoperator.py index 31e4115355c1..c661b9db2cf9 100644 --- a/qiskit/qasm/_node/_binaryoperator.py +++ b/qiskit/qasm/node/binaryoperator.py @@ -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 = { @@ -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): diff --git a/qiskit/qasm/_node/_cnot.py b/qiskit/qasm/node/cnot.py similarity index 84% rename from qiskit/qasm/_node/_cnot.py rename to qiskit/qasm/node/cnot.py index c8cfe9c292a9..504d9c3bfc47 100644 --- a/qiskit/qasm/_node/_cnot.py +++ b/qiskit/qasm/node/cnot.py @@ -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): @@ -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.""" diff --git a/qiskit/qasm/_node/_creg.py b/qiskit/qasm/node/creg.py similarity index 89% rename from qiskit/qasm/_node/_creg.py rename to qiskit/qasm/node/creg.py index b777baab62a9..57367f9259c0 100644 --- a/qiskit/qasm/_node/_creg.py +++ b/qiskit/qasm/node/creg.py @@ -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): @@ -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 diff --git a/qiskit/qasm/_node/_customunitary.py b/qiskit/qasm/node/customunitary.py similarity index 89% rename from qiskit/qasm/_node/_customunitary.py rename to qiskit/qasm/node/customunitary.py index f5518cf59af9..169810fe35af 100644 --- a/qiskit/qasm/_node/_customunitary.py +++ b/qiskit/qasm/node/customunitary.py @@ -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): @@ -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: diff --git a/qiskit/qasm/_node/_expressionlist.py b/qiskit/qasm/node/expressionlist.py similarity index 83% rename from qiskit/qasm/_node/_expressionlist.py rename to qiskit/qasm/node/expressionlist.py index 8f3c41efe7a6..1c1ef22d1789 100644 --- a/qiskit/qasm/_node/_expressionlist.py +++ b/qiskit/qasm/node/expressionlist.py @@ -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): @@ -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.""" diff --git a/qiskit/qasm/_node/_external.py b/qiskit/qasm/node/external.py similarity index 92% rename from qiskit/qasm/_node/_external.py rename to qiskit/qasm/node/external.py index 3968db05e0f9..ef181e2bafef 100644 --- a/qiskit/qasm/_node/_external.py +++ b/qiskit/qasm/node/external.py @@ -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): @@ -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.""" diff --git a/qiskit/qasm/_node/_format.py b/qiskit/qasm/node/format.py similarity index 79% rename from qiskit/qasm/_node/_format.py rename to qiskit/qasm/node/format.py index 922a746e12ce..d8fa0b17f033 100644 --- a/qiskit/qasm/_node/_format.py +++ b/qiskit/qasm/node/format.py @@ -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) diff --git a/qiskit/qasm/_node/_gate.py b/qiskit/qasm/node/gate.py similarity index 93% rename from qiskit/qasm/_node/_gate.py rename to qiskit/qasm/node/gate.py index 826017b0ca36..40d89a6db4c6 100644 --- a/qiskit/qasm/_node/_gate.py +++ b/qiskit/qasm/node/gate.py @@ -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): @@ -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 diff --git a/qiskit/qasm/_node/_gatebody.py b/qiskit/qasm/node/gatebody.py similarity index 87% rename from qiskit/qasm/_node/_gatebody.py rename to qiskit/qasm/node/gatebody.py index 9bf5cbae5782..707451bcf44a 100644 --- a/qiskit/qasm/_node/_gatebody.py +++ b/qiskit/qasm/node/gatebody.py @@ -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 custom gate body. -""" -from ._node import Node +"""Node for an OPENQASM custom gate body.""" + +from .node import Node class GateBody(Node): @@ -20,7 +19,7 @@ class GateBody(Node): def __init__(self, children): """Create the gatebody node.""" - Node.__init__(self, 'gate_body', children, None) + super().__init__('gate_body', children, None) def qasm(self, prec=15): """Return the corresponding OPENQASM string.""" diff --git a/qiskit/qasm/_node/_id.py b/qiskit/qasm/node/id.py similarity index 94% rename from qiskit/qasm/_node/_id.py rename to qiskit/qasm/node/id.py index 5b3b7c263b97..e7033c231b0b 100644 --- a/qiskit/qasm/_node/_id.py +++ b/qiskit/qasm/node/id.py @@ -5,11 +5,10 @@ # 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 id. -""" -from ._node import Node -from ._nodeexception import NodeException +"""Node for an OPENQASM id.""" + +from .node import Node +from .nodeexception import NodeException class Id(Node): @@ -22,7 +21,7 @@ class Id(Node): def __init__(self, id, line, file): """Create the id node.""" # pylint: disable=redefined-builtin - Node.__init__(self, "id", None, None) + super().__init__("id", None, None) self.name = id self.line = line self.file = file diff --git a/qiskit/qasm/_node/_idlist.py b/qiskit/qasm/node/idlist.py similarity index 85% rename from qiskit/qasm/_node/_idlist.py rename to qiskit/qasm/node/idlist.py index ddebd0588181..435b302e7811 100644 --- a/qiskit/qasm/_node/_idlist.py +++ b/qiskit/qasm/node/idlist.py @@ -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 idlist. -""" -from ._node import Node +"""Node for an OPENQASM idlist.""" + +from .node import Node class IdList(Node): @@ -19,7 +18,7 @@ class IdList(Node): def __init__(self, children): """Create the idlist node.""" - Node.__init__(self, 'id_list', children, None) + super().__init__('id_list', children, None) def size(self): """Return the length of the list.""" diff --git a/qiskit/qasm/_node/_if.py b/qiskit/qasm/node/if_.py similarity index 86% rename from qiskit/qasm/_node/_if.py rename to qiskit/qasm/node/if_.py index 075e590e7ba4..5120a776e69e 100644 --- a/qiskit/qasm/_node/_if.py +++ b/qiskit/qasm/node/if_.py @@ -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 if statement. -""" -from ._node import Node +"""Node for an OPENQASM if statement.""" + +from .node import Node class If(Node): @@ -22,7 +21,7 @@ class If(Node): def __init__(self, children): """Create the if node.""" - Node.__init__(self, 'if', children, None) + super().__init__('if', children, None) def qasm(self, prec=15): """Return the corresponding OPENQASM string.""" diff --git a/qiskit/qasm/_node/_indexedid.py b/qiskit/qasm/node/indexedid.py similarity index 88% rename from qiskit/qasm/_node/_indexedid.py rename to qiskit/qasm/node/indexedid.py index 729119bb6974..4fbed5d29fe2 100644 --- a/qiskit/qasm/_node/_indexedid.py +++ b/qiskit/qasm/node/indexedid.py @@ -7,10 +7,9 @@ # pylint: disable=invalid-name -""" -Node for an OPENQASM indexed id. -""" -from ._node import Node +"""Node for an OPENQASM indexed id.""" + +from .node import Node class IndexedId(Node): @@ -22,7 +21,7 @@ class IndexedId(Node): def __init__(self, children): """Create the indexed id node.""" - Node.__init__(self, 'indexed_id', children, None) + super().__init__('indexed_id', children, None) self.id = children[0] self.name = self.id.name self.line = self.id.line diff --git a/qiskit/qasm/_node/_intnode.py b/qiskit/qasm/node/intnode.py similarity index 92% rename from qiskit/qasm/_node/_intnode.py rename to qiskit/qasm/node/intnode.py index d8195145f97d..d90fb318d764 100644 --- a/qiskit/qasm/_node/_intnode.py +++ b/qiskit/qasm/node/intnode.py @@ -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 integer. -""" +"""Node for an OPENQASM integer.""" + from sympy import N -from ._node import Node +from .node import Node class Int(Node): @@ -22,7 +21,7 @@ class Int(Node): def __init__(self, id): """Create the integer node.""" # pylint: disable=redefined-builtin - Node.__init__(self, "int", None, None) + super().__init__("int", None, None) self.value = id def to_string(self, indent): diff --git a/qiskit/qasm/_node/_measure.py b/qiskit/qasm/node/measure.py similarity index 83% rename from qiskit/qasm/_node/_measure.py rename to qiskit/qasm/node/measure.py index 0b10dc52da16..37d7861bc0a5 100644 --- a/qiskit/qasm/_node/_measure.py +++ b/qiskit/qasm/node/measure.py @@ -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 measure statement. -""" -from ._node import Node +"""Node for an OPENQASM measure statement.""" + +from .node import Node class Measure(Node): @@ -20,7 +19,7 @@ class Measure(Node): def __init__(self, children): """Create the measure node.""" - Node.__init__(self, 'measure', children, None) + super().__init__('measure', children, None) def qasm(self, prec=15): """Return the corresponding OPENQASM string.""" diff --git a/qiskit/qasm/_node/_node.py b/qiskit/qasm/node/node.py similarity index 96% rename from qiskit/qasm/_node/_node.py rename to qiskit/qasm/node/node.py index 175e8df0a5f2..0d536e1c7f09 100644 --- a/qiskit/qasm/_node/_node.py +++ b/qiskit/qasm/node/node.py @@ -5,9 +5,7 @@ # 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. -""" -Base node object for the OPENQASM syntax tree. -""" +"""Base node object for the OPENQASM syntax tree.""" class Node: diff --git a/qiskit/qasm/_node/_nodeexception.py b/qiskit/qasm/node/nodeexception.py similarity index 89% rename from qiskit/qasm/_node/_nodeexception.py rename to qiskit/qasm/node/nodeexception.py index b42fe5b7e6fd..57ba73dd0021 100644 --- a/qiskit/qasm/_node/_nodeexception.py +++ b/qiskit/qasm/node/nodeexception.py @@ -5,9 +5,7 @@ # 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. -""" -Exception for errors raised while interpreting nodes. -""" +"""Exception for errors raised while interpreting nodes.""" class NodeException(Exception): diff --git a/qiskit/qasm/_node/_opaque.py b/qiskit/qasm/node/opaque.py similarity index 92% rename from qiskit/qasm/_node/_opaque.py rename to qiskit/qasm/node/opaque.py index 1d826d99bcdf..bc9ff93ecaa6 100644 --- a/qiskit/qasm/_node/_opaque.py +++ b/qiskit/qasm/node/opaque.py @@ -7,10 +7,9 @@ # pylint: disable=invalid-name -""" -Node for an OPENQASM opaque gate declaration. -""" -from ._node import Node +"""Node for an OPENQASM opaque gate declaration.""" + +from .node import Node class Opaque(Node): @@ -24,7 +23,7 @@ class Opaque(Node): def __init__(self, children): """Create the opaque gate node.""" - Node.__init__(self, 'opaque', children, None) + super().__init__('opaque', children, None) self.id = children[0] # The next three fields are required by the symbtab self.name = self.id.name diff --git a/qiskit/qasm/_node/_prefix.py b/qiskit/qasm/node/prefix.py similarity index 91% rename from qiskit/qasm/_node/_prefix.py rename to qiskit/qasm/node/prefix.py index f2ce9722dc33..d68a2f4ae94b 100644 --- a/qiskit/qasm/_node/_prefix.py +++ b/qiskit/qasm/node/prefix.py @@ -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 prefix expression. -""" +"""Node for an OPENQASM prefix expression.""" + import sympy -from ._node import Node +from .node import Node class Prefix(Node): @@ -22,7 +21,7 @@ class Prefix(Node): def __init__(self, children): """Create the prefix node.""" - Node.__init__(self, 'prefix', children, None) + super().__init__('prefix', children, None) def qasm(self, prec=15): """Return the corresponding OPENQASM string.""" diff --git a/qiskit/qasm/_node/_primarylist.py b/qiskit/qasm/node/primarylist.py similarity index 85% rename from qiskit/qasm/_node/_primarylist.py rename to qiskit/qasm/node/primarylist.py index 2241b5f29cb4..ea110d666ce8 100644 --- a/qiskit/qasm/_node/_primarylist.py +++ b/qiskit/qasm/node/primarylist.py @@ -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 primarylist. -""" -from ._node import Node +"""Node for an OPENQASM primarylist.""" + +from .node import Node class PrimaryList(Node): @@ -19,7 +18,7 @@ class PrimaryList(Node): def __init__(self, children): """Create the primarylist node.""" - Node.__init__(self, 'primary_list', children, None) + super().__init__('primary_list', children, None) def size(self): """Return the size of the list.""" diff --git a/qiskit/qasm/_node/_program.py b/qiskit/qasm/node/program.py similarity index 83% rename from qiskit/qasm/_node/_program.py rename to qiskit/qasm/node/program.py index dc870adf6a1b..bf7ae36364a9 100644 --- a/qiskit/qasm/_node/_program.py +++ b/qiskit/qasm/node/program.py @@ -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 program. -""" -from ._node import Node +"""Node for an OPENQASM program.""" + +from .node import Node class Program(Node): @@ -19,7 +18,7 @@ class Program(Node): def __init__(self, children): """Create the program node.""" - Node.__init__(self, 'program', children, None) + super().__init__('program', children, None) def qasm(self, prec=15): """Return the corresponding OPENQASM string.""" diff --git a/qiskit/qasm/_node/_qreg.py b/qiskit/qasm/node/qreg.py similarity index 89% rename from qiskit/qasm/_node/_qreg.py rename to qiskit/qasm/node/qreg.py index 7d2bce678561..da1581561a98 100644 --- a/qiskit/qasm/_node/_qreg.py +++ b/qiskit/qasm/node/qreg.py @@ -7,10 +7,9 @@ # pylint: disable=invalid-name -""" -Node for an OPENQASM qreg statement. -""" -from ._node import Node +"""Node for an OPENQASM qreg statement.""" + +from .node import Node class Qreg(Node): @@ -21,7 +20,7 @@ class Qreg(Node): def __init__(self, children): """Create the qreg node.""" - Node.__init__(self, 'qreg', children, None) + super().__init__('qreg', children, None) # This is the indexed id, the full "id[n]" object self.id = children[0] # Name of the qreg diff --git a/qiskit/qasm/_node/_real.py b/qiskit/qasm/node/real.py similarity index 92% rename from qiskit/qasm/_node/_real.py rename to qiskit/qasm/node/real.py index b8a30e4c03ba..e57fd97d97c6 100644 --- a/qiskit/qasm/_node/_real.py +++ b/qiskit/qasm/node/real.py @@ -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 real number. -""" +"""Node for an OPENQASM real number.""" + from sympy import latex, pi from sympy.printing.ccode import ccode -from ._node import Node +from .node import Node class Real(Node): @@ -22,7 +21,7 @@ class Real(Node): def __init__(self, id): """Create the real node.""" # pylint: disable=redefined-builtin - Node.__init__(self, "real", None, None) + super().__init__("real", None, None) self.value = id def to_string(self, indent): diff --git a/qiskit/qasm/_node/_reset.py b/qiskit/qasm/node/reset.py similarity index 81% rename from qiskit/qasm/_node/_reset.py rename to qiskit/qasm/node/reset.py index a821ecafa7ad..c85abdab9568 100644 --- a/qiskit/qasm/_node/_reset.py +++ b/qiskit/qasm/node/reset.py @@ -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 reset statement. -""" -from ._node import Node +"""Node for an OPENQASM reset statement.""" + +from .node import Node class Reset(Node): @@ -19,7 +18,7 @@ class Reset(Node): def __init__(self, children): """Create the reset node.""" - Node.__init__(self, 'reset', children, None) + super().__init__('reset', children, None) def qasm(self, prec=15): """Return the corresponding OPENQASM string.""" diff --git a/qiskit/qasm/_node/_unaryoperator.py b/qiskit/qasm/node/unaryoperator.py similarity index 85% rename from qiskit/qasm/_node/_unaryoperator.py rename to qiskit/qasm/node/unaryoperator.py index 7635e5cddb61..ae4489dde310 100644 --- a/qiskit/qasm/_node/_unaryoperator.py +++ b/qiskit/qasm/node/unaryoperator.py @@ -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 unary operator. -""" +"""Node for an OPENQASM unary operator.""" + import operator -from ._node import Node -from ._nodeexception import NodeException +from .node import Node +from .nodeexception import NodeException VALID_OPERATORS = { @@ -27,7 +26,7 @@ class UnaryOperator(Node): """ def __init__(self, operation): """Create the operator node.""" - Node.__init__(self, 'unary_operator', None, None) + super().__init__('unary_operator', None, None) self.value = operation def operation(self): diff --git a/qiskit/qasm/_node/_universalunitary.py b/qiskit/qasm/node/universalunitary.py similarity index 83% rename from qiskit/qasm/_node/_universalunitary.py rename to qiskit/qasm/node/universalunitary.py index 29d7da500329..d25ca7d5f14a 100644 --- a/qiskit/qasm/_node/_universalunitary.py +++ b/qiskit/qasm/node/universalunitary.py @@ -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 U statement. -""" -from ._node import Node +"""Node for an OPENQASM U statement.""" + +from .node import Node class UniversalUnitary(Node): @@ -20,7 +19,7 @@ class UniversalUnitary(Node): def __init__(self, children): """Create the U node.""" - Node.__init__(self, 'universal_unitary', children, None) + super().__init__('universal_unitary', children, None) def qasm(self, prec=15): """Return the corresponding OPENQASM string.""" diff --git a/qiskit/qasm/_qasm.py b/qiskit/qasm/qasm.py similarity index 97% rename from qiskit/qasm/_qasm.py rename to qiskit/qasm/qasm.py index 8d030d78ea4e..dabe0f9e2a65 100644 --- a/qiskit/qasm/_qasm.py +++ b/qiskit/qasm/qasm.py @@ -9,7 +9,7 @@ OPENQASM circuit object. """ from .exceptions import QasmError -from ._qasmparser import QasmParser +from .qasmparser import QasmParser class Qasm: diff --git a/qiskit/qasm/_qasmlexer.py b/qiskit/qasm/qasmlexer.py similarity index 99% rename from qiskit/qasm/_qasmlexer.py rename to qiskit/qasm/qasmlexer.py index 47ae278db1a5..addb9928abe5 100644 --- a/qiskit/qasm/_qasmlexer.py +++ b/qiskit/qasm/qasmlexer.py @@ -17,7 +17,7 @@ import ply.lex as lex from sympy import Number -from . import _node as node +from . import node from .exceptions import QasmError CORE_LIBS_PATH = os.path.join(os.path.dirname(__file__), 'libs') diff --git a/qiskit/qasm/_qasmparser.py b/qiskit/qasm/qasmparser.py similarity index 99% rename from qiskit/qasm/_qasmparser.py rename to qiskit/qasm/qasmparser.py index 3086e966d1cc..72a4c0959a60 100644 --- a/qiskit/qasm/_qasmparser.py +++ b/qiskit/qasm/qasmparser.py @@ -5,9 +5,8 @@ # 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. -""" -OPENQASM parser. -""" +"""OpenQASM parser.""" + import os import shutil import tempfile @@ -15,9 +14,9 @@ import ply.yacc as yacc import sympy -from . import _node as node +from . import node from .exceptions import QasmError -from ._qasmlexer import QasmLexer +from .qasmlexer import QasmLexer class QasmParser: diff --git a/test/python/test_qasm_parser.py b/test/python/test_qasm_parser.py index 53a3d8eddfcd..274d3c9942f5 100644 --- a/test/python/test_qasm_parser.py +++ b/test/python/test_qasm_parser.py @@ -11,7 +11,7 @@ import ply from qiskit.qasm import Qasm, QasmError -from qiskit.qasm._node._node import Node +from qiskit.qasm.node.node import Node from qiskit.test import QiskitTestCase, Path