Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import array
import math
import unittest
from julia import Julia, JuliaError
import sys
import os
python_version = sys.version_info
julia = Julia(jl_runtime_path=os.getenv("JULIA_EXE"), debug=True)
class JuliaTest(unittest.TestCase):
def test_call(self):
julia._call('1 + 1')
julia._call('sqrt(2.0)')
def test_eval(self):
self.assertEqual(2, julia.eval('1 + 1'))
self.assertEqual(math.sqrt(2.0), julia.eval('sqrt(2.0)'))
self.assertEqual(1, julia.eval('PyObject(1)'))
self.assertEqual(1000, julia.eval('PyObject(1000)'))
self.assertEqual((1, 2, 3), julia.eval('PyObject((1, 2, 3))'))
def test_call_error(self):
try:
def _call_powermodels(buffer_file, julia_file): # pragma: no cover
# checks if julia works, otherwise raises an error
try:
import julia
from julia import Main
except ImportError:
raise ImportError("Please install pyjulia to run pandapower with PowerModels.jl")
try:
j = julia.Julia()
except:
raise UserWarning(
"Could not connect to julia, please check that Julia is installed and pyjulia is correctly configured")
# import two julia scripts and runs powermodels julia_file
Main.include(os.path.join(pp_dir, "opf", 'pp_2_pm.jl'))
try:
run_powermodels = Main.include(julia_file)
except ImportError:
raise UserWarning("File %s could not be imported" % julia_file)
result_pm = run_powermodels(buffer_file)
return result_pm
def __init__(self, julia=None):
from julia import Julia
self.julia = Julia() if julia is None else julia
self.magic_re = re.compile(r".*(\s|^)%%?julia\s*")
# With this regexp, "=%julia Cha" won't work. But maybe
def load_julia_with_Shearlab():
"""Function to load Shearlab."""
# Importing base
j = julia.Julia()
j.eval('using Shearlab')
j.eval('using PyPlot')
j.eval('using Images')
return j
# Import ConfigSpace and different types of parameters
from smac.configspace import ConfigurationSpace
from ConfigSpace.hyperparameters import CategoricalHyperparameter, \
UniformFloatHyperparameter, UniformIntegerHyperparameter
from ConfigSpace.conditions import InCondition
# Import SMAC-utilities
from smac.tae.execute_func import AbstractTAFunc
from smac.scenario.scenario import Scenario
from smac.facade.smac_facade import SMAC
# Otherwise we leak GPU memory. See https://github.com/JuliaGPU/CuArrays.jl/releases/tag/v0.6.1
os.environ['CUARRAYS_MANAGED_POOL'] = 'false'
j = julia.Julia()
j.include("smac/test_lsq.jl")
rdqb = j.eval("smac_util.run_demos_query_base")
rdtqb = j.eval("smac_util.run_demos_train_query_base")
# call_counter = 1
def recall_from_cfg(cfg):
""" Runs MCQ from julia based on the passed configuration
Params
cfg: Configuration (ConfigSpace.ConfigurationSpace.Configuration)
Configuration containing the parameters.
Configurations are indexable!
Returns: