コード例 #1
0
ファイル: fitP.py プロジェクト: mniehus/SiPANN
def costFunctionFinal(x, grad):
    radius = x[0]
    couplerLength = x[1]
    width = x[2]
    thickness = x[3]
    # widthCoupler = x[4]
    gap = x[5]
    # angle = x[6]
    loss = x[7:]

    E, alpha, t, _ = SiP.racetrack_AP_RR_TF(
        wavelength,
        radius=radius,
        couplerLength=couplerLength,
        gap=gap,
        width=width,
        thickness=thickness,
        loss=loss,
    )

    throughPort = np.abs(np.squeeze(E))**2

    error = np.mean(np.abs(throughPort - power)**2)
    print(error)
    return error
コード例 #2
0
ファイル: test.py プロジェクト: rspotc/SiP-ANN
def costFunction_FSR(x,grad):
    radius        = x[0]
    couplerLength = x[1]
    gap           = 0.2
    width         = x[2]
    thickness     = x[3]

    # Evaluate the functin
    E, alpha, t, _ = SiP.racetrack_AP_RR_TF(wavelength,radius=radius,
    couplerLength=couplerLength,gap=gap,width=width,
    thickness=thickness)

    # get the transmission spectrum
    throughPort = np.abs(np.squeeze(E)) ** 2

    # Pull the peaks from the simulation
    peaksSim, _ = find_peaks(1-throughPort,height=peakThreshold)

    # calculate the number of peaks
    wavelengthSim = wavelength[peaksSim]
    powerSim      = throughPort[peaksSim]
    

    if wavelengthSim.size > numPeaks:
        wavelengthSim = wavelengthSim[0:numPeaks]
        powerSim      = powerSim[0:numPeaks]
    elif wavelengthSim.size < numPeaks:
        wavelengthSim = np.append(wavelengthSim,np.zeros((numPeaks-wavelengthSim.size,)))
        powerSim      = np.append(powerSim,np.zeros((numPeaks-powerSim.size,)))
    # Estimate the error
    error = np.sum(np.abs(wavelengthSim - wavelengthPeaks) ** 2)
    print(error)
    return error
コード例 #3
0
ファイル: fitP.py プロジェクト: mniehus/SiPANN
def costFunction_coupling(params, x, grad):
    radius = params[0]
    couplerLength = params[1]
    gap = x[0]
    width = params[2]
    thickness = params[3]

    # Evaluate the functin
    E, alpha, t, _ = SiP.racetrack_AP_RR_TF(
        wavelength,
        radius=radius,
        couplerLength=couplerLength,
        gap=gap,
        width=width,
        thickness=thickness,
    )

    # throughPort = np.abs(np.squeeze(E)) ** 2

    bp_sim = np.polyfit(wavelength, t, polyOrder)
    bz_sim = np.poly1d(bp_sim)

    error = np.mean(np.abs(bz_sim(w) - b)**2)
    print(error)

    return error
コード例 #4
0
ファイル: fitP.py プロジェクト: mniehus/SiPANN
def costFunction_loss(params, gapA, x, grad):
    radius = params[0]
    couplerLength = params[1]
    width = params[2]
    thickness = params[3]
    gap = params[4]

    # Evaluate the functin
    E, alpha, t, _ = SiP.racetrack_AP_RR_TF(
        wavelength,
        radius=radius,
        couplerLength=couplerLength,
        gap=gap,
        width=width,
        thickness=thickness,
        loss=x,
    )

    # throughPort = np.abs(np.squeeze(E)) ** 2

    ap_sim = np.polyfit(wavelength, alpha, polyOrder)
    az_sim = np.poly1d(ap_sim)

    error = np.mean(np.abs(az_sim(wavelength) - az(wavelength))**2)

    print(error)

    return error
コード例 #5
0
ファイル: test.py プロジェクト: rspotc/SiP-ANN
def plotFinal(x):
    radius        = x[0]
    couplerLength = x[1]
    width         = x[2]
    thickness     = x[3]
    gap           = x[4]
    loss          = x[5:]

    E, alpha, t, alpha_s = SiP.racetrack_AP_RR_TF(wavelength,radius=radius,
    couplerLength=couplerLength,gap=gap,width=width,
    thickness=thickness,loss=loss)

    # get the transmission spectrum
    throughPort = np.abs(np.squeeze(E)) ** 2

    plt.figure(figsize=(7,7))
    plt.subplot(2,2,1)
    plt.plot(wavelength,power)
    plt.plot(wavelength,throughPort,'--')
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (a.u.)')
    plt.grid(True)
    
    plt.subplot(2,2,3)
    plt.plot(wavelength,10*np.log10(power))
    plt.plot(wavelength,10*np.log10(throughPort),'--')
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (dB)')
    plt.grid(True)
    
    plt.subplot(2,2,2)
    plt.plot(wavelength,power,'o')
    plt.plot(wavelength,throughPort)
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (a.u.)')
    plt.grid(True)
    plt.xlim(1.552,1.554)
    
    plt.subplot(2,2,4)
    plt.plot(wavelength,10*np.log10(power),'o')
    plt.plot(wavelength,10*np.log10(throughPort))
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (dB)')
    plt.grid(True)
    plt.xlim(1.552,1.554)

    plt.tight_layout()
    plt.savefig('results.png')
    plt.show()

    # Save the data as a numpy archive
    np.savez(filenamePrefix + '_data.npz',radius=radius,couplerLength=couplerLength,
    gap=gap,width=width,thickness=thickness,loss=loss,E=E,alpha=alpha,t=t,alpha_r=alpha_s)
コード例 #6
0
ファイル: fitP.py プロジェクト: mniehus/SiPANN
def costFunction_FSR(x, grad):
    radius = x[0]
    couplerLength = x[1]
    width = x[2]
    thickness = x[3]
    widthCoupler = x[4]
    gap = x[5]
    angle = x[6]

    E, alpha, t, _ = SiP.racetrack_AP_RR_TF(
        wavelength,
        radius=radius,
        couplerLength=couplerLength,
        gap=gap,
        width=width,
        widthCoupler=widthCoupler,
        angle=angle,
        thickness=thickness,
        loss=ap,
    )

    throughPort = np.abs(np.squeeze(E))**2

    error1 = np.mean(np.abs(throughPort - power)**2)

    bp_sim = np.polyfit(wavelength, t, polyOrderGap)
    bz_sim = np.poly1d(bp_sim)

    error2 = np.mean(np.abs(bz_sim(w) - b)**2)

    # Pull the peaks from the simulation
    peaksSim, _ = find_peaks(1 - throughPort, height=peakThreshold)

    # calculate the number of peaks
    wavelengthSim = wavelength[peaksSim]
    powerSim = throughPort[peaksSim]

    if wavelengthSim.size > numPeaks:
        wavelengthSim = wavelengthSim[0:numPeaks]
        powerSim = powerSim[0:numPeaks]
    elif wavelengthSim.size < numPeaks:
        wavelengthSim = np.append(wavelengthSim,
                                  np.zeros((numPeaks - wavelengthSim.size, )))
        powerSim = np.append(powerSim, np.zeros((numPeaks - powerSim.size, )))
    # [[0,numPeaks-1]]
    # Estimate the error
    error1 = np.sum(np.abs(wavelengthSim - wavelengthPeaks)**2)
    error = error1 * 1e8 + error2 * 1e6
    print([error1, error2, error])
    return error
コード例 #7
0
ファイル: test.py プロジェクト: rspotc/SiP-ANN
def plotResult(radius,couplerLength,width,thickness):
    
    gap = 0.2

    E, alpha, t, _ = SiP.racetrack_AP_RR_TF(wavelength,radius=radius,
    couplerLength=couplerLength,gap=gap,width=width,
    thickness=thickness)

    # get the transmission spectrum
    throughPort = np.abs(np.squeeze(E)) ** 2

    plt.figure()
    plt.plot(wavelength,power)
    plt.plot(wavelength,throughPort)
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (a.u.)')
    plt.grid(True)

    plt.tight_layout()
    plt.show()
    return
コード例 #8
0
ファイル: test.py プロジェクト: rspotc/SiP-ANN
numParams = len(z0)

# Just do a local optimization
opt = nlopt.opt(algorithmLocal, numParams)
opt.set_lower_bounds(lowerBounds)
opt.set_upper_bounds(upperBounds)
opt.set_min_objective(costFunction_loss_mode)
opt.set_maxtime(maxtime_local)
#z0 = opt.optimize(z0)
print('=================')
print('Local')
print(z0)
print(costFunction_loss_mode(z0,0))

E, alpha, t, _ = SiP.racetrack_AP_RR_TF(wavelength,radius=x0[0],
couplerLength=x0[1],gap=y0[0],width=x0[2],
thickness=x0[3],loss=z0)

throughPort = np.abs(np.squeeze(E)) ** 2

plt.figure()
plt.plot(wavelength,alpha)
plt.plot(w,a,'o')

# ------------------------------------------------------------------------- #
# Step 4: Final optimization
# ------------------------------------------------------------------------- #

P0 = list(x0) + list(y0) + list(z0)

print(P0)
コード例 #9
0
ファイル: fitP.py プロジェクト: rspotc/SiP-ANN
def plotFinal(x):
    radius        = x[0]
    couplerLength = x[1]
    width         = x[2]
    thickness     = x[3]
    widthCoupler  = x[4]
    gap           = x[5]
    angle         = x[6]
    loss          = x[7:]

    E, alpha, t, alpha_s = SiP.racetrack_AP_RR_TF(wavelength,radius=radius,
    couplerLength=couplerLength,gap=gap,width=width,widthCoupler=widthCoupler,angle=angle,
    thickness=thickness,loss=loss)


    # get the transmission spectrum
    throughPort = np.abs(np.squeeze(E)) ** 2

    peaksSim, _ = find_peaks(1-throughPort,height=peakThreshold)
    print(peaksSim)

    fig = plt.figure(figsize=(7,7))
    plt.subplot(3,3,1)
    plt.plot(wavelength,power)
    plt.plot(wavelength,throughPort,'--')
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (a.u.)')
    plt.grid(True)
    
    plt.subplot(3,3,4)
    plt.plot(wavelength,10*np.log10(power))
    plt.plot(wavelength,10*np.log10(throughPort),'--')
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (dB)')
    plt.grid(True)

    plt.subplot(3,3,2)
    plt.plot(wavelength,power,'o')
    plt.plot(wavelength,throughPort)
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (a.u.)')
    plt.grid(True)
    plt.xlim(wavelength[peaksSim[0]]-0.5e-3,wavelength[peaksSim[0]]+0.5e-3)

    plt.subplot(3,3,3)
    plt.plot(wavelength,power,'o')
    plt.plot(wavelength,throughPort)
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (a.u.)')
    plt.grid(True)
    plt.xlim(wavelength[peaksSim[-1]]-0.5e-3,wavelength[peaksSim[-1]]+0.5e-3)
    
    plt.subplot(3,3,5)
    plt.plot(wavelength,10*np.log10(power),'o')
    plt.plot(wavelength,10*np.log10(throughPort))
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (dB)')
    plt.grid(True)
    plt.xlim(wavelength[peaksSim[0]]-0.5e-3,wavelength[peaksSim[0]]+0.5e-3)

    plt.subplot(3,3,6)
    plt.plot(wavelength,10*np.log10(power),'o')
    plt.plot(wavelength,10*np.log10(throughPort))
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Power (dB)')
    plt.grid(True)
    plt.xlim(wavelength[peaksSim[-1]]-0.5e-3,wavelength[peaksSim[-1]]+0.5e-3)

    plt.subplot(3,2,5)
    plt.plot(w,a,'o')
    plt.plot(wavelength,alpha)
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Loss')
    plt.grid(True)

    plt.subplot(3,2,6)
    plt.plot(w,b,'o')
    plt.plot(wavelength,t)
    plt.xlabel('Wavelength ($\mu$m)')
    plt.ylabel('Coupling')
    plt.grid(True)

    fig.suptitle('Iter={:d}, Die={:d}, Device={:d}'.format(currentIter,die,device))

    fig.tight_layout(rect=[0, 0.03, 1, 0.95])
    plt.savefig('results.png')
    plt.show()

    # Save the data as a numpy archive
    np.savez('data.npz',radius=radius,couplerLength=couplerLength,
    gap=gap,width=width,thickness=thickness,loss=loss,E=E,alpha=alpha,t=t,alpha_r=alpha_s)