Home › Forums › Nazca › Create trial cells when using minimizer algorithm? › Reply To: Create trial cells when using minimizer algorithm?
18 April 2021 at 21:12
#6446
Ronald
Keymaster
A decorator can clean up the code a bit like this:
def trial_cell(func):
def wrapper(*args, **kwargs):
cell = kwargs.pop('cell', False)
if not cell:
S1 = set(nd.cfg.cellnames.keys())
out = func(*args, cell=cell, **kwargs)
if not cell:
S2 = set(nd.cfg.cellnames.keys())
for s in S2 - S1:
nd.cfg.cellnames.pop(s)
return out
return wrapper
@trial_cell
def cell_to_solve(offset=10, target_diff=20, cell=False):
with nd.Cell('test') as C:
m1 = demo.mmi1x2_dp().put(0)
nd.trace.trace_start()
demo.deep.sbend(offset=offset).put(m1.pin['b0'])
demo.deep.sbend(offset=-offset).put()
nd.trace.trace_stop()
L1 = nd.trace.trace_length()
m2 = demo.mmi2x2_dp().put()
nd.trace.trace_start()
demo.deep.sbend_p2p(pin1=m1.pin['b1'], pin2=m2.pin['a1']).put()
nd.trace.trace_stop()
L2 = nd.trace.trace_length()
diff = L1 - L2
if cell:
return C
else:
return diff - target_diff
Ronald