• 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

73.68
/waveforms/qlisp/qasm/node/binaryoperator.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 binary operator."""
9✔
14

15
import operator
9✔
16
import warnings
9✔
17

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

21

22
VALID_OPERATORS = {
9✔
23
    '+': operator.add,
24
    '-': operator.sub,
25
    '*': operator.mul,
26
    '/': operator.truediv,
27
    '^': operator.pow
28
}
29

30

31
class BinaryOperator(Node):
9✔
32
    """Node for an OPENQASM binary operator.
33
    This node has no children. The data is in the value field.
34
    """
35
    def __init__(self, operation):
9✔
36
        """Create the operator node."""
37
        super().__init__('operator', None, None)
9✔
38
        self.value = operation
9✔
39

40
    def operation(self):
9✔
41
        """
42
        Return the operator as a function f(left, right).
43
        """
44
        try:
9✔
45
            return VALID_OPERATORS[self.value]
9✔
46
        except KeyError:
×
47
            raise NodeException("internal error: undefined operator '%s'" %
×
48
                                self.value)
49

50
    def qasm(self, prec=None):
9✔
51
        """Return the QASM representation."""
52
        if prec is not None:
×
53
            warnings.warn('Parameter \'BinaryOperator.qasm(..., prec)\' is no longer used and is '
×
54
                          'being deprecated.', DeprecationWarning, 2)
55
        return self.value
×
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

© 2025 Coveralls, Inc