def setup(compiled_modules=True): julia.install() jl = Julia(compiled_modules=compiled_modules) from julia import Pkg Pkg.add("[email protected]") # Lock to specific version for stability Pkg.add("Distributions") # Install Distributions after Bigsimr
def install( runtime = default_runtime, project = default_project, ): """ Build julia module and install DECAES """ if project is not None: os.environ["JULIA_PROJECT"] = project # Build julia module using given runtime julia.install(julia = runtime) # Install DECAES.jl decaes_install_script = """try @info "Trying to import DECAES..." import DECAES catch e @error "`import DECAES` failed" exception=(e, catch_backtrace()) @info "Installing DECAES..." import Pkg Pkg.add("DECAES") import DECAES end """.replace(" ", "") with tempfile.TemporaryDirectory() as jl_dir: jl_script_name = os.path.join(jl_dir, 'decaes_install.jl') with open(jl_script_name, "w") as jl_script: jl_script.write(decaes_install_script) subprocess.check_call([runtime, "--startup-file=no", jl_script_name])
def install( julia_download_path='https://julialang-s3.julialang.org/bin/linux/x64/1.4/julia-1.4.0-linux-x86_64.tar.gz', julia_target_path=None): ''' :param julia_download_path: Path for the julia download, you can modify for your preferred version :param julia_target_path: Specify where to install Julia, if not specified will install in $HOME$/julia ''' if julia_target_path == None: julia_target_path = os.path.join(os.path.expanduser("~"), 'julia') if not os.path.isdir(julia_target_path): os.mkdir(julia_target_path) download_path = os.path.join(julia_target_path, 'julia_install.tar.gz') print("Downloading Julia:") wget.download(julia_download_path, download_path) print("\nExtracting...") tar = tarfile.open(download_path, "r:gz") tar.extractall(julia_target_path) _, partial_path = get_julia_path_from_dir(julia_target_path) os.environ["PATH"] += os.pathsep + partial_path os.system("echo '# added by dpmmpython' >> ~/.bashrc") os.system("echo 'export PATH=\"" + partial_path + ":$PATH\"' >> ~/.bashrc") print("Configuring PyJulia") julia.install() julia.Julia(compiled_modules=False) print("Adding DPMMSubClusters package") from julia import Pkg Pkg.add("DPMMSubClusters") print( "Please exit the shell and restart, before attempting to use the package" )
def test_rebuild_broken_pycall(juliainfo): if juliainfo.version_info < (0, 7): pytest.skip("Julia >= 0.7 required") subprocess.check_call( [ juliainfo.julia, "--startup-file=no", "-e", """using Pkg; Pkg.develop("PyCall")""", ] ) # Remove ~/.julia/dev/PyCall/deps/deps.jl depsjl = os.path.join( os.path.expanduser("~"), ".julia", "dev", "PyCall", "deps", "deps.jl" ) if os.path.exists(depsjl): print("Removing", depsjl) os.remove(depsjl) # julia.install() should fix it: install(julia=juliainfo.julia) assert os.path.exists(depsjl)
def test_add_pycall(juliainfo): if juliainfo.version_info < (0, 7): pytest.skip("Julia >= 0.7 required") # Try to remove PyCall subprocess.call( [juliainfo.julia, "--startup-file=no", "-e", """using Pkg; Pkg.rm("PyCall")"""] ) # julia.install() should add PyCall: install(julia=juliainfo.julia)
def init_api(sysimage_path): jlinfo = JuliaInfo.load(julia = get_JULIA_RUNTIME_NAME()) if not jlinfo.libpython_path: logging.info("PyCall does not seem to be installed. Trying to remedy this fact...") install( julia = get_JULIA_RUNTIME_NAME() ) elif get_FORCE_PYCALL_REBUILD or not os.path.isfile(jlinfo.python) or not os.path.samefile( jlinfo.python, executable ): logging.info("PyCall not compatbile, rebuilding...") build_pycall( julia = get_JULIA_RUNTIME_NAME(), quiet = True ) try: Julia( runtime = get_JULIA_RUNTIME(), compiled_modules = False, sysimage = sysimage_path) except JuliaError as e: logging.warn("Could not load Julia.") raise e
def install(julia_project=None): # pragma: no cover import julia julia.install() julia_project = _get_julia_project(julia_project) init_julia() from julia import Pkg Pkg.activate(f"{_escape_filename(julia_project)}") Pkg.update() Pkg.instantiate() Pkg.precompile() warnings.warn( "It is recommended to restart Python after installing PySR's dependencies," " so that the Julia environment is properly initialized.")
def get_jl_interpreter(): global jl_interpreter if jl_interpreter is None: # Only suppress std if not in debug mode. out = nullcontext() if DEBUG else SuppressStd() try: with out: import julia # configure the julia runtime runtime_config = { 'compiled_modules': False, 'debug': bool(DEBUG) } julia.install() jl_interpreter = julia.Julia(**runtime_config) except BaseException: if hasattr(out, 'output'): print(out.output) raise return jl_interpreter
import os import sys sys.path.insert( 0, os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir, "src")) import julia # isort:skip julia.install(color=True)
import julia julia.install() from julia import Pkg Pkg.add('QXZoo') import pyqx.qxzoo
def test_noop(juliainfo): install(julia=juliainfo.julia)
import os import sys sys.path.insert( 0, os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir, "src") ) import julia # isort:skip julia.install(color=True)
# Member functions for class Generator. import julia import os import subprocess import pandas as pd import numpy as np import json import sys import traceback from Python_src.log import log from Python_src.profiler import Profiler import gurobipy as gp from gurobipy import GRB julia.install() #need to run this only the first time while using the julia package (or if changing python path) # Include definition of Node class #include "node.h" # Include Generator solver class defintion profiler = Profiler() log.info("Loading Julia...") profiler.start() julSol = julia.Julia() julSol.using("Pkg") julSol.eval('Pkg.activate(".")') """ julSol.include(os.path.join("JuMP_src", "gensolverFirst.jl")) # definition of Gensolver class for base case scenario first interval julSol.include(os.path.join("JuMP_src", "gensolverFirstBase.jl")) # definition of Gensolver class for base case scenario dummy zeroth interval in case of Dummy zero (i.e. gensolver for zeroth interval) julSol.include(os.path.join("JuMP_src", "gensolverFirstCont.jl")) # definition of Gensolver class for contingency case scenario first interval julSol.include(os.path.join("JuMP_src", "gensolverFirstDZ.jl")) # definition of Gensolver class for base case scenario first interval with dummy zero interval julSol.include(os.path.join("JuMP_src", "gensolverFirstDZCont.jl")) # definition of Gensolver class for contingency case scenario first interval with dummy zero interval julSol.include(os.path.join("JuMP_src", "gensolverSecondBase.jl")) # definition of Gensolver class for base case scenario for second interval
import random np.random.seed(0) random.seed(42) #To run the code, first needs to download julia 1.1 and then set its ENVIRONMENTAL PATH. #These needs to be done if want to run the code and plot the result. plt.rcParams[ 'animation.ffmpeg_path'] = '/usr/local/Cellar/ffmpeg/4.1.4/bin/ffmpeg' #Change the path for your own computer mpl.style.use('seaborn') cmap = mpl.cm.get_cmap('plasma') mywriter = animation.FFMpegWriter(fps=100, metadata=dict(artist='Me'), bitrate=18000) julia.install("/Applications/Julia-1.1.app/Contents/Resources/julia/bin/julia" ) #Change the path for your own computer j = julia.Julia() j.include("./fast-segmented-regression-master/src/linear_merging.jl" ) #Change the path for your own computer ########THEIR CODE FOR GENERATING DATA############## # endpoint_values = Base.rand([1,2,3,4,5,6,7,8,9,10], 6) # n = 500 # k = len(endpoint_values) - 1 # sigma = 1.0 # y, ystar, X = j.generate_equal_size_linear_data(endpoint_values, n, sigma) # print(X) # print(endpoint_values) # print(np.shape(X)) # print(np.shape(ystar))
# Configure PyJulia import julia julia.install() # install PyCall.jl etc. # Add the Tempotrons.jl package from julia import Pkg Pkg.add(url = "https://github.com/bci4cpl/Tempotrons.jl")
def __init__(self, predict, p, targeted, tolerance=1e-6, clip_min=0, clip_max=1, main_parameters=None, tightening_parameters=None, exploration_main_parameters=None, exploration_tightening_parameters=None, correction_factor_schedule=None, main_attempts=1, retry_gap=1e-4, retry_absolute_gap=1e-5, original_if_failed=False, seed=None): super().__init__(predict, None, clip_min, clip_max) if main_parameters is None: main_parameters = dict() if tightening_parameters is None: tightening_parameters = dict() if exploration_main_parameters is None: exploration_main_parameters = dict() if exploration_tightening_parameters is None: exploration_tightening_parameters = dict() if correction_factor_schedule is None: correction_factor_schedule = [1.05] if seed is not None: # Global seed provided: set it for all solvers that do not # have a custom seed parameter_pairs = [(main_parameters, 'main solver'), (tightening_parameters, 'tightening solver'), (exploration_main_parameters, 'exploration main solver'), (exploration_tightening_parameters, 'exploration tightening solver')] for parameter_dict, name in parameter_pairs: if 'Seed' in parameter_dict: logger.info('Found custom seed for the %s.', name) else: logger.info( 'No custom seed provided for the %s. Using ' 'the global one.', name) parameter_dict['Seed'] = seed if not np.isposinf(p): raise NotImplementedError('MIPAttack only supports p=inf.') # Lazy import if not MIPAttack._pyjulia_installed: import julia julia.install() MIPAttack._pyjulia_installed = True if tolerance == 0: logger.warning( 'MIP\'s tolerance is set to 0. Given the possible numerical errors, ' 'it is likely that MIP\'s adversarials will be considered unsuccessful by ' 'Torch\'s model.') for parameters in [ main_parameters, tightening_parameters, exploration_main_parameters, exploration_tightening_parameters ]: # TimeLimit=0 means that it does not have a time limit if 'TimeLimit' in parameters and parameters['TimeLimit'] == 0: parameters['TimeLimit'] = np.inf mip_gap = main_parameters[ 'MIPGap'] if 'MIPGap' in main_parameters else 1e-4 if mip_gap != retry_gap: logger.warning( 'Main Solver MIPGap differs from retry_gap: this might ' 'interfere with the retry system.') mip_gap_abs = main_parameters[ 'MIPGapAbs'] if 'MIPGapAbs' in main_parameters else 1e-5 if mip_gap_abs != retry_absolute_gap: logger.warning( 'Main Solver MIPGapAbs differs from retry_absolute_gap: this might ' 'interfere with the retry system.') self.p = p self.targeted = targeted self.tolerance = tolerance self.correction_factor_schedule = correction_factor_schedule self.main_attempts = main_attempts self.retry_gap = retry_gap self.retry_absolute_gap = retry_absolute_gap self.original_if_failed = original_if_failed self.mip_model = sequential_to_mip(predict) self.main_parameters = main_parameters self.tightening_parameters = tightening_parameters self.exploration_main_parameters = exploration_main_parameters self.exploration_tightening_parameters = exploration_tightening_parameters