def test_error_when_trying_to_plot_from_Network_show_normal_modes(self): circuit = core.Network([ core.C(0,1,'C'), core.J(0,1,'Lj') ]) with self.assertRaises(TypeError): circuit.show_normal_mode()
def test_q_zpf(self): Cj = 100e-15 Lj = 10e-9 junction = core.J(0, 1, Lj) circuit = core.Network([core.C(0, 1, Cj), junction, core.R(0, 1, 1e6)]) Z = np.sqrt(Lj / Cj) q_zpf = np.sqrt(hbar / Z / 2) self.assertRelativelyClose( q_zpf / e, np.absolute(junction.zpf(mode=0, quantity='charge')))
def parameters(self, Cj, Lj, Cc, Cr, Lr): circuit = core.Network([ core.C(0, 1, Cj), core.J(0, 1, Lj), core.C(1, 2, Cc), core.C(0, 2, Cr), core.L(0, 2, Lr) ]) return circuit.f_k_A_chi()
def test_anharmonicity_using_hamiltonian(self): Cj = 1e-10 circuit = core.Network([core.C(0, 1, Cj), core.J(0, 1, 10e-9)]) H = circuit.hamiltonian(modes=[0], taylor=4, excitations=[10]) ee = H.eigenenergies() A = np.absolute((ee[1] - ee[0]) - (ee[2] - ee[1])) # Due to higher order terms, the mismatch with e**2/2/Cj/h is # (193702.3+0j) != (194712.7+0j) A_expected = 194712.7 self.assertRelativelyClose(A_expected, A)
def test_double_series_capacitor(self): C = 100e-15 Lj = 10e-9 circuit = core.Network( [core.C(0, 1, C * 2), core.C(1, 2, C * 2), core.J(0, 2, Lj)]) f, k, A, chi = circuit.f_k_A_chi() self.assertArrayRelativelyClose( [e**2 / 2. / C / h, 1 / (np.sqrt(C * Lj) * 2. * pi)], [A[0], f[0]])
def parameters(self, C, L): circuit = core.Network([ core.C(0, 2, C), core.C(1, 3, C), core.J(0, 1, L), core.J(1, 2, L), core.J(2, 3, L), core.J(3, 0, L) ]) return circuit.f_k_A_chi()
def test_sweeping_LJ_in_fkAchi(self): cir = core.Network([ core.C(0, 1, 100e-15), core.J(0, 1, 'L_J'), core.C(1, 2, 1e-15), core.C(2, 0, 100e-15), core.L(2, 0, 10e-9), core.R(2, 0, 1e6) ]) [cir.f_k_A_chi(L_J=x) for x in [1e-9, 2e-9]]
def test_phi_zpf(self): Cj = 100e-15 Lj = 10e-9 junction = core.J(0, 1, Lj) circuit = core.Network([core.C(0, 1, Cj), junction, core.R(0, 1, 1e6)]) phi_0 = hbar / 2 / e Z = np.sqrt(Lj / Cj) phi_zpf = np.sqrt(hbar * Z / 2) self.assertRelativelyClose(phi_zpf / phi_0, junction.zpf(mode=0, quantity='flux'))
def test_LC_double_series_L_double_series_C(self): C = 1e-8 L = 3 circuit = core.Network([ core.C(0, 1, C * 2), core.C(1, 2, C * 2), core.L(2, 3, L / 2), core.L(3, 0, L / 2) ]) f, k, A, chi = circuit.f_k_A_chi() f_expected = 1 / np.sqrt(L * C) / 2 / np.pi self.assertRelativelyClose(f_expected, f)
def test_sweeping_CJ_array_in_zpf(self): C_comp = core.C(0, 1, 'C_J') cir = core.Network([ C_comp, core.J(0, 1, 10e-9), core.C(1, 2, 1e-15), core.C(2, 0, 100e-15), core.L(2, 0, 10e-9), core.R(2, 0, 1e6) ]) self.assertRelativelyClose( C_comp.zpf(mode=1, quantity='charge', C_J=1.5e-9), C_comp.zpf(mode=1, quantity='charge', C_J=[1e-9, 1.5e-9, 3e-9])[1])
def revaluing_labelled_valued_component_twice(self): ''' Adressing last error appearing in issue #83 ''' cir = core.Network( [core.L(0, 1, 1), core.C(0, 1, 1), core.R(0, 1, 'R', 1)]) try: cir.loss_rates(R=1) except Exception: pass with self.assertRaises(ValueError): cir.loss_rates(R=1)
def parameters(self, R, L, C): circuit = core.Network( [core.C(0, 1, C), core.L(1, 2, L), core.R(0, 2, R)]) return circuit.f_k_A_chi()
def parameters(self, C, Lj): circuit = core.Network([core.C(0, 1, C), core.J(0, 1, Lj)]) return circuit.f_k_A_chi()
plt.show() plt.clf() # CartPole-v0 if example == "CartPole": def score(rewards): return np.sum(rewards) env = gym.make('CartPole-v0') net = pf.Network(network={ 'type': 'fc', 'layers': [4, 64, 64, 2] }, agent='reinforce', actions=[0, 1], learning_rate=0.0001, decay_steps=1000, decay_factor=0.90, keep_prob=1.00) agent = pf.Reinforce(net=net, env=env, discount_rate=1.00, max_episodes=500, score=score) agent.train() evaluate(env, agent, score, 100) # LunarLander-v1 if example == "LunarLander":
def test_error_when_trying_to_plot_from_Network_show(self): circuit = core.Network([core.C(0, 1, "C"), core.J(0, 1, "Lj")]) with self.assertRaises(TypeError): circuit.show()
import tensorflow as tf import numpy as np import core as pf import time import gym import sys env = gym.make('CartPole-v0') for lr in 10.0**np.random.uniform(-3, -5, size=10): print("Training with lr={:f}".format(lr)) net = pf.Network(network={ 'type': 'fc', 'layers': [4 * 1, 256, 256, 2] }, agent='deepq', actions=[0, 1], learning_rate=lr, decay_steps=1000, decay_factor=0.99, keep_prob=0.50, batch_size=32) net.build() agent = pf.DeepQ( net=net, env=env, discount_rate=0.99, max_episodes=500, score=np.sum, min_mem=10**4, # 5-10% of max_mem max_mem=10**5, seq_length=1,
import tensorflow as tf import numpy as np import core as pf import time import gym import sys env = gym.make('CartPole-v0') net = pf.Network(network={ 'type': 'fc', 'layers': [4, 1024, 512, 2] }, agent='reinforce', actions=[0, 1], learning_rate=0.0001, decay_steps=1000, decay_factor=0.90, keep_prob=0.50) net.build() agent = pf.Reinforce(net=net, env=env, discount_rate=1.00, max_episodes=500, print_episodes=10, score=np.sum) agent.train() agent.evaluate()
min_epsilon = 0.01 max_episodes = 500 print_episodes = 10 def score(x): return np.sum(x * 0.99**np.range(1, len(x) + 1)) env = gym.make('LunarLander-v2') net = pf.Network(network={ 'type': 'fc', 'layers': [8, 256, 256, 4] }, agent='deepq', actions=[0, 1, 2, 3], learning_rate=learning_rate, decay_steps=lr_decay_steps, decay_factor=lr_decay_factor, keep_prob=keep_prob, batch_size=batch_size) net.build() agent = pf.DeepQ(net=net, env=env, discount_rate=discount_rate, max_episodes=max_episodes, score=score, min_mem=min_mem, max_mem=max_mem, seq_length=seq_length, batch_size=batch_size,