• 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

43.75
/waveforms/qlisp/qasm/node/binaryop.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 operation expression."""
9✔
14

15
import warnings
9✔
16

17
from .node import Node
9✔
18

19

20
class BinaryOp(Node):
9✔
21
    """Node for an OPENQASM binary operation expression.
22
    children[0] is the operation, as a binary operator node.
23
    children[1] is the left expression.
24
    children[2] is the right expression.
25
    """
26

27
    def __init__(self, children):
9✔
28
        """Create the binaryop node."""
29
        super().__init__('binop', children, None)
9✔
30

31
    def qasm(self, prec=None, nested_scope=None):
9✔
32
        """Return the corresponding OPENQASM string."""
33
        if prec is not None:
×
34
            warnings.warn('Parameter \'BinaryOp.qasm(..., prec)\' is no longer '
×
35
                          'used and is being deprecated.', DeprecationWarning, 2)
36
        if nested_scope is not None:
×
37
            warnings.warn('Parameter \'BinaryOp.qasm(..., nested_scope)\' is no longer '
×
38
                          'used and is being deprecated.', DeprecationWarning, 2)
39
        return "(" + self.children[1].qasm() + self.children[0].value + \
×
40
               self.children[2].qasm() + ")"
41

42
    def latex(self, prec=None, nested_scope=None):
9✔
43
        """Return the corresponding math mode latex string."""
44
        if prec is not None:
×
45
            warnings.warn('Parameter \'BinaryOp.latex(..., prec)\' is no longer used '
×
46
                          'and is being deprecated.', DeprecationWarning, 2)
47
        if nested_scope is not None:
×
48
            warnings.warn('Parameter \'BinaryOp.latex(..., nested_scope)\' is no longer used '
×
49
                          'and is being deprecated.', DeprecationWarning, 2)
50
        try:
×
51
            from pylatexenc.latexencode import utf8tolatex
×
52
        except ImportError:
×
53
            raise ImportError("To export latex from qasm "
×
54
                              "pylatexenc needs to be installed. Run "
55
                              "'pip install pylatexenc' before using this "
56
                              "method.")
57
        return utf8tolatex(self.sym())
×
58

59
    def real(self, nested_scope=None):
9✔
60
        """Return the correspond floating point number."""
61
        operation = self.children[0].operation()
9✔
62
        lhs = self.children[1].real(nested_scope)
9✔
63
        rhs = self.children[2].real(nested_scope)
9✔
64
        return operation(lhs, rhs)
9✔
65

66
    def sym(self, nested_scope=None):
9✔
67
        """Return the correspond symbolic number."""
68
        operation = self.children[0].operation()
×
69
        lhs = self.children[1].sym(nested_scope)
×
70
        rhs = self.children[2].sym(nested_scope)
×
71
        return operation(lhs, rhs)
×
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