Commit f4465c69 authored by Frank Hellmann's avatar Frank Hellmann
Browse files

Added classical model for test purposes

parent 3f9b89b7
from __future__ import absolute_import, print_function, division, unicode_literals
import numpy as np
import networkx as nx
import scipy.sparse as sps
def define_oscillator_rhs(dim):
nn = dim // 2
def right_hand_side(y, t, coupling, infeed, droop):
phases = np.exp(1.j * y[:nn])
return np.append(y[nn:], infeed - droop * y[nn:] -
np.imag(phases * coupling.dot(phases).conjugate()))
return right_hand_side
def find_fixpoint(self, args, fp_guess=None):
from scipy.optimize import root
if fp_guess is None:
fp_guess = np.zeros(self.size_of_system * 2, dtype=np.float64)
res = root(lambda x: self._rhs(x, 0., *args), fp_guess)
if res.success:
return res.x
else:
print("Failed to find fix point")
return None
def calculate_rhs_args(G):
coupling = 8. * sps.csr_matrix(nx.adj_matrix(G))
size = len(G)
droop = 0.1
infeed = np.ones(size, dtype=np.float64)
infeed[:size // 2] = -1.
infeed[-1] -= np.sum(infeed)
return coupling, infeed, droop, size
def define_rc_gen(G, brp):
coupling, infeed, droop, size = calculate_rhs_args(G)
num_batch_inv = 1. / brp.number_of_batches
def gen(batch, run):
ic = np.random.random(brp.system_dimension) - 0.5
ic[:size] *= 2. * np.pi
ic[size:] *= 1.0
return ic, (batch * num_batch_inv * coupling, infeed, droop)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment