Skip to content

Commit

Permalink
pysweep working
Browse files Browse the repository at this point in the history
Removed unnecessary files,
Added sample config. Renamed pysweep.py
  • Loading branch information
dreoilin committed Jul 21, 2023
1 parent d5dc8af commit 09342dc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
File renamed without changes.
3 changes: 0 additions & 3 deletions src/pygmid/sweep/requirements.txt

This file was deleted.

4 changes: 0 additions & 4 deletions src/pygmid/sweep/setup.sh

This file was deleted.

37 changes: 11 additions & 26 deletions src/pygmid/sweep/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, config_file_path: str):

self._simulator = SpectreSimulator(*spectre_args)

def run(self) -> (str, str):
def run(self):
Ls = self._config['SWEEP']['LENGTH']
VSBs = self._config['SWEEP']['VSB']
nch = self._config.generate_m_dict()
Expand Down Expand Up @@ -58,8 +58,8 @@ def run(self) -> (str, str):
params_p = p
values_p = p_dict[params_p[0]]
for m, outvar in enumerate(self._config['outvars']):
nch[outvar][i,:,:,j] = np.squeeze(values_n*params_n[2][m])
pch[outvar][i,:,:,j] = np.squeeze(values_p*params_p[2][m])
nch[outvar][i,:,:,j] += np.squeeze(values_n*params_n[2][m])
pch[outvar][i,:,:,j] += np.squeeze(values_p*params_p[2][m])

params = [ k[0].split(':')[1] for k in self._config['n_noise'] ]

Expand All @@ -71,8 +71,8 @@ def run(self) -> (str, str):
params_p = p
values_p = p_dict[params_p[0]]
for m, outvar in enumerate(self._config['outvars_noise']):
nch[outvar][i,:,:,j] = np.squeeze(values_n)
pch[outvar][i,:,:,j] = np.squeeze(values_p)
nch[outvar][i,:,:,j] += np.squeeze(values_n)
pch[outvar][i,:,:,j] += np.squeeze(values_p)

# TODO: uncomment this and clean the temporary files up from the runs
# self._cleanup()
Expand Down Expand Up @@ -110,8 +110,8 @@ def _extract_sweep_params(self, params, sweep_type="DC"):
Params -> list of strings
size -> len(VGS) x len(VDS)
"""
# TODO: take directory from command line, have this be default
sweep_output_directory = Path(__file__).parent / "sweep.ascii-from-run/psf"
## TODO: take directory from command line, have this be default
sweep_output_directory = "./sweep/psf"
# TODO: filename pattern should be taken from config file, but could also be hardcoded ?
if sweep_type == "DC":
filename_pattern = 'sweepvds-*_sweepvgs.dc'
Expand All @@ -121,10 +121,7 @@ def _extract_sweep_params(self, params, sweep_type="DC"):
file_paths = glob.glob(os.path.join(sweep_output_directory, filename_pattern))
# remove directory in case it contains number. Only want to sort based on filename itself
filelist = sorted([os.path.basename(f) for f in file_paths], key=self._extract_number_regex)
# psf = PSF( os.path.join(directory, filelist[0]) , use_cache=False, update_cache=False)

# nmos = {f"mn:{param}" : [] for param in params}
# pmos = {f"mp:{param}" : [] for param in params}

nmos = {f"mn:{param}" : np.zeros((len(self._config['SWEEP']['VGS']), len(self._config['SWEEP']['VDS']))) for param in params}
pmos = {f"mp:{param}" : np.zeros((len(self._config['SWEEP']['VGS']), len(self._config['SWEEP']['VDS']))) for param in params}
for VDS_i, f in enumerate(filelist):
Expand All @@ -135,19 +132,7 @@ def _extract_sweep_params(self, params, sweep_type="DC"):
psf = psf_utils.PSF( file_path )

for param in params:
# TODO: set these arrays to be the correct length and not use .append
# nmos[f'mn:{param}'].append( (psf.get_signal(f"mn:{param}").ordinate).T )
# pmos[f'mp:{param}'].append( (psf.get_signal(f"mp:{param}").ordinate).T )
# nmos[f'mn:{param}'] = (psf.get_signal(f"mn:{param}").ordinate).T
# pmos[f'mp:{param}'] = (psf.get_signal(f"mp:{param}").ordinate).T

# might need to be transposed or not
nmos[f'mn:{param}'][:, VDS_i] = (psf.get_signal(f"mn:{param}").ordinate).T
pmos[f'mp:{param}'][:, VDS_i] = (psf.get_signal(f"mp:{param}").ordinate).T

# dimensions
# nmos_stacked = { mn_param:np.stack(v).T for mn_param,v in nmos.items() }
# pmos_stacked = { k:np.stack(v).T for k,v in pmos.items() }

# return (nmos_stacked, pmos_stacked)
nmos[f'mn:{param}'][:,VDS_i] = (psf.get_signal(f"mn:{param}").ordinate).T
pmos[f'mp:{param}'][:,VDS_i] = (psf.get_signal(f"mp:{param}").ordinate).T

return (nmos, pmos)
32 changes: 32 additions & 0 deletions tests/pygmid/sweep/sample_config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This is a test config, paired with the sweep.ascii data if you have access
[MODEL]
file = "/mcci-sw/cadence.64/design_kits/cadence/90nm/gpdk090_v4.6/models/spectre/gpdk090.scs" section=NN
info = 90nm CMOS, cadence gpdk, BSIMv4
corner = NOM
temp = 300
modeln = gpdk090_nmos1v
modelp = gpdk090_pmos1v
savefilen = 90n1rvt
savefilep = 90p1rvt
paramfile = params.scs
# Make sure to indent the strings in this array or you'll get a DuplicateOptionError
mp = ["l=L w=Wtot m=1 simM=1\\",
"ad=(((Wtot) / (1)) < 239.5n) ? ((floor((1) / 2.0) * (((((120n) - 0) + 120n) * 240n) + (((Wtot) / (1)) * 200n))) + ((((1) / 2) - floor((1) / 2) != 0) ? (((100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n)) * 240n) + (((Wtot) / (1)) * 100n)) : 0)) / 1 : ((floor((1) / 2.0) * ((((120n) - 0) + 200n) * ((Wtot) / (1)))) + ((((1) / 2) - floor((1) / 2) != 0) ? ((200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n)) * ((Wtot) / (1))) : 0)) / 1 \\",
"as=(((Wtot) / (1)) < 239.5n) ? ((((100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n)) * 240n) + (((Wtot) / (1)) * 100n)) + (floor(((1) - 1) / 2.0) * (((((120n) - 0) + 120n) * 240n) + (((Wtot) / (1)) * 200n))) + ((((1) / 2) - floor((1) / 2) == 0) ? (((100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n)) * 240n) + (((Wtot) / (1)) * 100n)) : 0)) / 1 : (((200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n)) * ((Wtot) / (1))) + (floor(((1) - 1) / 2.0) * ((((120n) - 0) + 200n) * ((Wtot) / (1)))) + ((((1) / 2) - floor((1) / 2) == 0) ? ((200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n)) * ((Wtot) / (1))) : 0)) / 1 \\",
"pd=(((Wtot) / (1)) < 239.5n) ? ((floor((1) / 2.0) * ((2 * (((120n) - 0) + 120n)) + 880n)) + ((((1) / 2) - floor((1) / 2) != 0) ? ((2 * (100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n))) + 680n) : 0)) / 1 : ((floor((1) / 2.0) * ((2 * (((120n) - 0) + 200n)) + (2 * ((Wtot) / (1))))) + ((((1) / 2) - floor((1) / 2) != 0) ? ((2 * (200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n))) + (2 * ((Wtot) / (1)))) : 0)) / 1 \\",
"ps=(((Wtot) / (1)) < 239.5n) ? (((2 * (100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n))) + 680n) + (floor(((1) - 1) / 2.0) * ((2 * (((120n) - 0) + 120n)) + 880n)) + ((((1) / 2) - floor((1) / 2) == 0) ? ((2 * (100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n))) + 680n) : 0)) / 1 : (((2 * (200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n))) + (2 * ((Wtot) / (1)))) + (floor(((1) - 1) / 2.0) * ((2 * (((120n) - 0) + 200n)) + (2 * ((Wtot) / (1))))) + ((((1) / 2) - floor((1) / 2) == 0) ? ((2 * (200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n))) + (2 * ((Wtot) / (1)))) : 0)) / 1 \\"]
mn = ["l=L w=Wtot m=1 simM=1 \\",
"ad=(((Wtot) / (1)) < 239.5n) ? ((floor((1) / 2.0) * (((((120n) - 0) + 120n) * 240n) + (((Wtot) / (1)) * 200n))) + ((((1) / 2) - floor((1) / 2) != 0) ? (((100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n)) * 240n) + (((Wtot) / (1)) * 100n)) : 0)) / 1 : ((floor((1) / 2.0) * ((((120n) - 0) + 200n) * ((Wtot) / (1)))) + ((((1) / 2) - floor((1) / 2) != 0) ? ((200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n)) * ((Wtot) / (1))) : 0)) / 1 \\",
"as=(((Wtot) / (1)) < 239.5n) ? ((((100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n)) * 240n) + (((Wtot) / (1)) * 100n)) + (floor(((1) - 1) / 2.0) * (((((120n) - 0) + 120n) * 240n) + (((Wtot) / (1)) * 200n))) + ((((1) / 2) - floor((1) / 2) == 0) ? (((100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n)) * 240n) + (((Wtot) / (1)) * 100n)) : 0)) / 1 : (((200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n)) * ((Wtot) / (1))) + (floor(((1) - 1) / 2.0) * ((((120n) - 0) + 200n) * ((Wtot) / (1)))) + ((((1) / 2) - floor((1) / 2) == 0) ? ((200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n)) * ((Wtot) / (1))) : 0)) / 1 \\",
"pd=(((Wtot) / (1)) < 239.5n) ? ((floor((1) / 2.0) * ((2 * (((120n) - 0) + 120n)) + 880n)) + ((((1) / 2) - floor((1) / 2) != 0) ? ((2 * (100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n))) + 680n) : 0)) / 1 : ((floor((1) / 2.0) * ((2 * (((120n) - 0) + 200n)) + (2 * ((Wtot) / (1))))) + ((((1) / 2) - floor((1) / 2) != 0) ? ((2 * (200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n))) + (2 * ((Wtot) / (1)))) : 0)) / 1 \\",
"ps=(((Wtot) / (1)) < 239.5n) ? (((2 * (100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n))) + 680n) + (floor(((1) - 1) / 2.0) * ((2 * (((120n) - 0) + 120n)) + 880n)) + ((((1) / 2) - floor((1) / 2) == 0) ? ((2 * (100n > (((120n) - 0) + 120n) ? 100n : (((120n) - 0) + 120n))) + 680n) : 0)) / 1 : (((2 * (200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n))) + (2 * ((Wtot) / (1)))) + (floor(((1) - 1) / 2.0) * ((2 * (((120n) - 0) + 200n)) + (2 * ((Wtot) / (1))))) + ((((1) / 2) - floor((1) / 2) == 0) ? ((2 * (200n > (((120n) - 0) + 160n) ? 200n : (((120n) - 0) + 160n))) + (2 * ((Wtot) / (1)))) : 0)) / 1 \\"]

[SWEEP]
# (start ,step,stop)
# VGS = (0 ,200e-3,1.8)
VGS = (0 ,100e-3,1.8)
VDS = (0,200e-3,1.8)
VSB = (0,0.5,1)
LENGTH = [(0.1,0.05,0.2)]
WIDTH = 1
NFING = 1

0 comments on commit 09342dc

Please sign in to comment.