def generate_network(mem_pars, net_pars): if net_pars['type'] == graph_type[1]: G = nx.watts_strogatz_graph(net_pars['N'], net_pars['k'], net_pars['p']) elif net_pars['type'] == graph_type[2]: G = nx.random_regular_graph(net_pars['degree'], net_pars['N']) cir = Circuit('Memristor network test') # assign dictionary with terminals and memristors memdict = {} w = mem_pars['w'] D = mem_pars['D'] Roff = mem_pars['Roff'] Ron = mem_pars['Ron'] mu = mem_pars['mu'] Tao = mem_pars['Tao'] for e in G.edges_iter(): rval = round(Roff + 0.01 * Roff * (random.random() - 0.5), 2) key = 'R' + str(e[0]) + str(e[1]) [v1, v2] = [e[0], e[1]] memdict[key] = [ v1, v2, memristor.memristor(w, D, Roff, Ron, mu, Tao, 0.0) ] # we set v=0.0 value in the beginning cir.add_resistor(key, 'n' + str(v1), 'n' + str(v2), rval) G[e[0]][e[1]]['weight'] = rval # edge_labels[e]=rval; for n in G.nodes_iter(): G.node[n]['number'] = n # Add random ground and voltage terminal nodes [v1, gnd] = random.sample(xrange(0, len(G.nodes())), 2) lastnode = len(G.nodes()) G.add_edge(v1, lastnode) G.node[lastnode]['number'] = 'V1' lastnode += 1 G.add_edge(gnd, lastnode) G.node[lastnode]['number'] = 'gnd' plot_graph(G) export_graph( G, '/Users/nfrik/CloudStation/Research/LaBean/ESN/FalstadSPICE/test.txt') cir.add_resistor("RG", 'n' + str(gnd), cir.gnd, 0.001) cir.add_vsource("V1", 'n' + str(v1), cir.gnd, 1000) opa = new_op() # netdict contains setup graph and circuit networkdict = {} networkdict['Graph'] = G networkdict['Circuit'] = cir networkdict['Memristors'] = memdict networkdict['Opa'] = opa return networkdict
def generate_network(mem_pars, net_pars): if net_pars['type']==graph_type[1]: G = nx.watts_strogatz_graph(net_pars['N'],net_pars['k'],net_pars['p']) elif net_pars['type']==graph_type[2]: G = nx.random_regular_graph(net_pars['degree'], net_pars['N']) cir = Circuit('Memristor network test') # assign dictionary with terminals and memristors memdict = {} w = mem_pars['w'] D = mem_pars['D'] Roff = mem_pars['Roff'] Ron = mem_pars['Ron'] mu = mem_pars['mu'] Tao = mem_pars['Tao'] for e in G.edges_iter(): rval = round(Roff + 0.01 * Roff * (random.random() - 0.5), 2) key = 'R' + str(e[0]) + str(e[1]) [v1, v2] = [e[0], e[1]] memdict[key] = [v1, v2, memristor.memristor(w, D, Roff, Ron, mu, Tao, 0.0)] # we set v=0.0 value in the beginning cir.add_resistor(key, 'n' + str(v1), 'n' + str(v2), rval) G[e[0]][e[1]]['weight'] = rval # edge_labels[e]=rval; for n in G.nodes_iter(): G.node[n]['number'] = n # Add random ground and voltage terminal nodes [v1, gnd] = random.sample(xrange(0, len(G.nodes())), 2) lastnode = len(G.nodes()) G.add_edge(v1, lastnode) G.node[lastnode]['number'] = 'V1' lastnode += 1 G.add_edge(gnd, lastnode) G.node[lastnode]['number'] = 'gnd' plot_graph(G) export_graph(G,'/Users/nfrik/CloudStation/Research/LaBean/ESN/FalstadSPICE/test.txt') cir.add_resistor("RG", 'n' + str(gnd), cir.gnd, 0.001) cir.add_vsource("V1", 'n' + str(v1), cir.gnd, 1000) opa = new_op() # netdict contains setup graph and circuit networkdict = {} networkdict['Graph'] = G networkdict['Circuit'] = cir networkdict['Memristors'] = memdict networkdict['Opa']=opa return networkdict
from ahkab import new_ac, run from ahkab.circuit import Circuit from ahkab.plotting import plot_results # calls matplotlib for you import numpy as np import matplotlib.pyplot as plt # Define the circuit cir = Circuit('Butterworth 1kHz band-pass filter') cir.add_vsource('V1', 'n1', cir.gnd, dc_value=0., ac_value=1.) cir.add_resistor('R1', 'n1', 'n2', 50.) cir.add_inductor('L1', 'n2', 'n3', 0.245894) cir.add_capacitor('C1', 'n3', 'n4', 1.03013e-07) cir.add_inductor('L2', 'n4', cir.gnd, 9.83652e-05) cir.add_capacitor('C2', 'n4', cir.gnd, 0.000257513) cir.add_inductor('L3', 'n4', 'n5', 0.795775) cir.add_capacitor('C3', 'n5', 'n6', 3.1831e-08) cir.add_inductor('L4', 'n6', cir.gnd, 9.83652e-05) cir.add_capacitor('C4', 'n6', cir.gnd, 0.000257513) cir.add_capacitor('C5', 'n7', 'n8', 1.03013e-07) cir.add_inductor('L5', 'n6', 'n7', 0.245894) cir.add_resistor('R2', 'n8', cir.gnd, 50.) # Define the analysis ac1 = new_ac(.97e3, 1.03e3, 1e2, x0=None) # run it res = run(cir, ac1) # plot the results plot_results('5th order 1kHz Butterworth filter', [('|Vn8|',"")], res['ac'], outfilename='bpf_transfer_fn.png')
from ahkab import new_dc, run from ahkab.circuit import Circuit from ahkab.plotting import plot_results, show_plots # calls matplotlib for you import scipy as np from ahkab.components.TunnelJunction import * # Define the circuit tjm = TunnelJunctionModel("tjm") cir = Circuit('Scanning Tunnel Microscope IV') cir.add_model("diode", "ddd", {"IS": 0.000139 * 3 * 2.5, "N": 160}) cir.add_vsource('V1', 'n1', cir.gnd, dc_value=1., ac_value=0.) cir.add_diode('D1', 'n1', 'n2', "ddd") cir.add_resistor('R1', 'n1', 'n3', 1.) tj = TunnelJunction('tj1', cir.add_node('n2'), cir.add_node(cir.gnd), tjm, d=10) cir.append(tj) dc1 = new_dc(-2.1, 3, 1e2, source="V1") res = run(cir, dc1) plot_results('Scanning Tunnel Microscope IV', [('I(V1)', '')], res['dc']) show_plots()
__author__ = 'nfrik' from ahkab import * from ahkab.circuit import Circuit cir = Circuit('asdf') cir.add_vsource('V1','n1',cir.gnd,dc_value=1.,ac_value=0.) cir.add_resistor('R1','n1','n2',50.) cir.add_resistor('R2','n2','n3',1100) cir.add_resistor('R4','n3',cir.gnd,10) # ac1 = new_ac(2.*np.pi*.97e3, 2.*np.pi*1.03e3,1e2,x0=None) opa = new_op() r = run(cir,opa)['op'] print r['VN2'][0][0] print r cir[0].dc_value=10. r = run(cir,opa)['op'] print r['VN2'][0][0] print r # res = run(cir, ac1) # # # plot_results('asdf',[('|Vn8|',"")],res['ac'],outfilename='dccircuit.png') # # plot_results('5th order 1kHz Butterworth filter', [('|Vn3|',"")], res['ac'], # outfilename='bpf_transfer_fn.png')
from ahkab import new_ac, run from ahkab.circuit import Circuit from ahkab.plotting import plot_results # calls matplotlib for you import numpy as np cir = Circuit('Simple circuit') cir.add_vsource('V1', 'n1', cir.gnd, dc_value=5) cir.add_resistor('R1', 'n1', 'n2', 50) res = run(cir) print res print type(res)
import ahkab from ahkab.circuit import Circuit from ahkab.symbolic import symbolic_analysis import matplotlib.pyplot as plt R = 1 #0.1e3 L = 1e-2 #0.2e-12 C = 0.5 #0.3e-9 c = Circuit('Sincronização de circuito LC') # resistors must be placed so all tanks are connected through one c.add_resistor('R1', 'n1', 'n2', R) c.add_resistor('R2', 'n2', 'n3', R) c.add_resistor('R3', 'n3', 'n4', R) c.add_resistor('R3', 'n4', 'n2', R) # tank1 c.add_inductor('L1', 'n1', c.gnd, L) c.add_capacitor('C1', 'n1', c.gnd, C) # tank2 c.add_inductor('L2', 'n2', c.gnd, L) c.add_capacitor('C2', 'n2', c.gnd, C) # tank3 c.add_inductor('L3', 'n3', c.gnd, L) c.add_capacitor('C3', 'n3', c.gnd, C) # tank4 c.add_inductor('L4', 'n4', c.gnd, L) c.add_capacitor('C4', 'n4', c.gnd, C) # Interferência destrutiva x0 = ahkab.new_x0(c, { 'V(n1)': -0.2 / C, 'V(n2)': -0.1 / C,
from ahkab import run, new_dc, new_tran, diode from ahkab.circuit import Circuit from ahkab.plotting import plot_results from ahkab import circuit, printing, time_functions import numpy as np import pylab as plt cir = Circuit("NEW CIRCUIT") gnd = cir.get_ground_node() def CircuitAnalysis(components, parameters): for i in components: if 'r' in i[0]: if (i[2] == '0'): cir.add_resistor(i[0], gnd, i[3], i[1]) elif (i[3] == '0'): cir.add_resistor(i[0], i[2], gnd, i[1]) else: cir.add_resistor(i[0], i[2], i[3], i[1]) elif 'c' in i[0]: if (i[2] == '0'): cir.add_capacitor(i[0], gnd, i[3], i[1]) elif (i[3] == '0'): cir.add_capacitor(i[0], i[2], gnd, i[1]) else: cir.add_capacitor(i[0], i[2], i[3], i[1]) elif 'i' in i[0]: if (i[2] == '0'): cir.add_inductor(i[0], gnd, i[3], i[1]) elif (i[3] == '0'):
from ahkab import new_dc, run from ahkab.circuit import Circuit from ahkab.plotting import plot_results, show_plots # calls matplotlib for you import scipy as np from ahkab.components.TunnelJunction import * # Define the circuit tjm=TunnelJunctionModel("tjm") cir = Circuit('Scanning Tunnel Microscope IV') cir.add_model("diode","ddd",{"IS":0.000139*3*2.5,"N":160}) cir.add_vsource('V1','n1', cir.gnd, dc_value=1., ac_value=0.) cir.add_diode('D1','n1','n2',"ddd") cir.add_resistor('R1', 'n1', 'n3', 1.) tj=TunnelJunction('tj1',cir.add_node('n2'),cir.add_node(cir.gnd),tjm,d=10) cir.append(tj) dc1 = new_dc(-2.1,3, 1e2, source="V1") res = run(cir, dc1) plot_results('Scanning Tunnel Microscope IV', [('I(V1)','')], res['dc']) show_plots()