-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathITensorNetworksNextParallel.jl
More file actions
60 lines (49 loc) · 1.75 KB
/
Copy pathITensorNetworksNextParallel.jl
File metadata and controls
60 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module ITensorNetworksNextParallel
import ..ITensorNetworksNext.AlgorithmsInterfaceExtensions as AIE
import AlgorithmsInterface as AI
abstract type AbstractParallelizationStrategy end
function default_workers end
function initialize_parallel_state end
@kwdef struct Parallelized{Strategy, Workers, Algorithm <: AI.Algorithm} <: AI.Algorithm
parent::Algorithm
strategy::Strategy
workers::Workers = default_workers(parent, strategy)
end
function Base.getproperty(algorithm::Parallelized, name::Symbol)
if name in (:parent, :strategy, :workers)
return getfield(algorithm, name)
end
return getproperty(getfield(algorithm, :parent), name)
end
function AI.initialize_state(problem::AI.Problem, algorithm::Parallelized; kwargs...)
return initialize_parallel_state(
problem,
algorithm.parent,
algorithm.strategy;
kwargs...
)
end
# ====================================== Dagger.jl ======================================= #
abstract type AbstractDaggerStrategy <: AbstractParallelizationStrategy end
struct GenericDaggerStrategy <: AbstractDaggerStrategy end
function initialize_parallel_state(
_problem,
_algorithm,
strategy::AbstractDaggerStrategy;
_kwargs...
)
throw(
ArgumentError(
"package Dagger.jl not loaded; please install and load Dagger.jl to use \
strategy of type $(typeof(strategy))."
)
)
end
function default_workers(algorithm, strategy::AbstractDaggerStrategy)
@warn(
"package Dagger.jl may not be loaded; please install and load Dagger.jl to use \
strategy of type `$(typeof(strategy))`"
)
throw(MethodError(default_workers, (algorithm, strategy)))
end
end # ITensorNetworksNextParallel