• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

feihoo87 / waveforms / 6534953321

16 Oct 2023 02:19PM UTC coverage: 35.674% (-22.7%) from 58.421%
6534953321

push

github

feihoo87
fix Coveralls

5913 of 16575 relevant lines covered (35.67%)

3.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.94
/waveforms/qlisp/qasm/node/id.py
1
# This code is part of Qiskit.
2
#
3
# (C) Copyright IBM 2017.
4
#
5
# This code is licensed under the Apache License, Version 2.0. You may
6
# obtain a copy of this license in the LICENSE.txt file in the root directory
7
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
#
9
# Any modifications or derivative works of this code must retain this
10
# copyright notice, and modified files need to carry a notice indicating
11
# that they have been altered from the originals.
12

13
"""Node for an OPENQASM id."""
9✔
14

15
import warnings
9✔
16

17
from .node import Node
9✔
18
from .nodeexception import NodeException
9✔
19

20

21
class Id(Node):
9✔
22
    """Node for an OPENQASM id.
23
    The node has no children but has fields name, line, and file.
24
    There is a flag is_bit that is set when XXXXX to help with scoping.
25
    """
26

27
    def __init__(self, id, line, file):
9✔
28
        """Create the id node."""
29
        # pylint: disable=redefined-builtin
30
        super().__init__("id", None, None)
9✔
31
        self.name = id
9✔
32
        self.line = line
9✔
33
        self.file = file
9✔
34
        # To help with scoping rules, so we know the id is a bit,
35
        # this flag is set to True when the id appears in a gate declaration
36
        self.is_bit = False
9✔
37

38
    def to_string(self, indent):
9✔
39
        """Print the node with indent."""
40
        ind = indent * ' '
×
41
        print(ind, 'id', self.name)
×
42

43
    def qasm(self, prec=None):
9✔
44
        """Return the corresponding OPENQASM string."""
45
        if prec is not None:
×
46
            warnings.warn('Parameter \'Id.qasm(..., prec)\' is no longer used and is being '
×
47
                          'deprecated.', DeprecationWarning, 2)
48
        return self.name
×
49

50
    def latex(self, prec=None, nested_scope=None):
9✔
51
        """Return the correspond math mode latex string."""
52
        if prec is not None:
×
53
            warnings.warn('Parameter \'Id.latex(..., prec)\' is no longer used and is being '
×
54
                          'deprecated.', DeprecationWarning, 2)
55
        if not nested_scope:
×
56
            return "\textrm{" + self.name + "}"
×
57
        else:
58
            if self.name not in nested_scope[-1]:
×
59
                raise NodeException("Expected local parameter name: ",
×
60
                                    "name=%s, " % self.name,
61
                                    "line=%s, " % self.line,
62
                                    "file=%s" % self.file)
63

64
            return nested_scope[-1][self.name].latex(nested_scope[0:-1])
×
65

66
    def sym(self, nested_scope=None):
9✔
67
        """Return the correspond symbolic number."""
68
        if not nested_scope or self.name not in nested_scope[-1]:
×
69
            raise NodeException("Expected local parameter name: ",
×
70
                                "name=%s, line=%s, file=%s" % (
71
                                    self.name, self.line, self.file))
72
        return nested_scope[-1][self.name].sym(nested_scope[0:-1])
×
73

74
    def real(self, nested_scope=None):
9✔
75
        """Return the correspond floating point number."""
76
        if not nested_scope or self.name not in nested_scope[-1]:
9✔
77
            raise NodeException("Expected local parameter name: ",
×
78
                                "name=%s, line=%s, file=%s" % (
79
                                    self.name, self.line, self.file))
80

81
        return nested_scope[-1][self.name].real(nested_scope[0:-1])
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc