Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def eval(self):
func = None
if self.func == QasmRealUnaryFunctions.Sin:
func = math.sin
elif self.func == QasmRealUnaryFunctions.Cos:
func = math.cos
elif self.func == QasmRealUnaryFunctions.Tan:
func = math.tan
elif self.func == QasmRealUnaryFunctions.Exp:
func = math.exp
elif self.func == QasmRealUnaryFunctions.Ln:
func = math.log
elif self.func == QasmRealUnaryFunctions.Sqrt:
func = math.sqrt
else:
raise ValueError('Unexpected Enum value.')
return func(self.arg.eval())
def eval(self):
func = None
if self.func == QasmRealUnaryFunctions.Sin:
func = math.sin
elif self.func == QasmRealUnaryFunctions.Cos:
func = math.cos
elif self.func == QasmRealUnaryFunctions.Tan:
func = math.tan
elif self.func == QasmRealUnaryFunctions.Exp:
func = math.exp
elif self.func == QasmRealUnaryFunctions.Ln:
func = math.log
elif self.func == QasmRealUnaryFunctions.Sqrt:
func = math.sqrt
else:
raise ValueError('Unexpected Enum value.')
return func(self.arg.eval())
def from_str(s: str) -> 'QasmRealUnaryFunctions':
if s == 'sin':
return QasmRealUnaryFunctions.Sin
if s == 'cos':
return QasmRealUnaryFunctions.Cos
if s == 'tan':
return QasmRealUnaryFunctions.Tan
if s == 'exp':
return QasmRealUnaryFunctions.Exp
if s == 'ln':
return QasmRealUnaryFunctions.Ln
if s == 'sqrt':
return QasmRealUnaryFunctions.Sqrt
raise ValueError('Unexpected value')
def eval(self):
func = None
if self.func == QasmRealUnaryFunctions.Sin:
func = math.sin
elif self.func == QasmRealUnaryFunctions.Cos:
func = math.cos
elif self.func == QasmRealUnaryFunctions.Tan:
func = math.tan
elif self.func == QasmRealUnaryFunctions.Exp:
func = math.exp
elif self.func == QasmRealUnaryFunctions.Ln:
func = math.log
elif self.func == QasmRealUnaryFunctions.Sqrt:
func = math.sqrt
else:
raise ValueError('Unexpected Enum value.')
return func(self.arg.eval())
def _parse_factor(tokens):
if tokens.get_if('('):
expr = _parse_expr(tokens)
tokens.get_if(')', 'Corresponded `)` not found.')
return expr
if tokens.get_if('pi'):
return QasmRealConst(QasmRealConstValues.Pi)
line_tok = tokens.get_if(_is_func)
if line_tok:
func = QasmRealUnaryFunctions.from_str(line_tok[1])
tokens.get_if('(', '`(` is required after function')
arg = _parse_expr(tokens)
tokens.get_if(')', 'Corresponded `)` not found.')
return QasmRealCall(func, arg)
return _parse_number(tokens)
def from_str(s: str) -> 'QasmRealUnaryFunctions':
if s == 'sin':
return QasmRealUnaryFunctions.Sin
if s == 'cos':
return QasmRealUnaryFunctions.Cos
if s == 'tan':
return QasmRealUnaryFunctions.Tan
if s == 'exp':
return QasmRealUnaryFunctions.Exp
if s == 'ln':
return QasmRealUnaryFunctions.Ln
if s == 'sqrt':
return QasmRealUnaryFunctions.Sqrt
raise ValueError('Unexpected value')
def from_str(s: str) -> 'QasmRealUnaryFunctions':
if s == 'sin':
return QasmRealUnaryFunctions.Sin
if s == 'cos':
return QasmRealUnaryFunctions.Cos
if s == 'tan':
return QasmRealUnaryFunctions.Tan
if s == 'exp':
return QasmRealUnaryFunctions.Exp
if s == 'ln':
return QasmRealUnaryFunctions.Ln
if s == 'sqrt':
return QasmRealUnaryFunctions.Sqrt
raise ValueError('Unexpected value')