本文整理汇总了Python中field.Field.optimize_size方法的典型用法代码示例。如果您正苦于以下问题:Python Field.optimize_size方法的具体用法?Python Field.optimize_size怎么用?Python Field.optimize_size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field.Field
的用法示例。
在下文中一共展示了Field.optimize_size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_schematic
# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import optimize_size [as 别名]
def generate_schematic(self, circuit_raw=None, circuit_id=None, options=None):
"""
Generate a schematic for the given raw circuit data.
circuit_raw: list-dict like [{"name":.. ,"type":.. , "conns":.. , "groups":..}, ..]
circuit_id: of the circuit as a tuple of strings ("foo", "bar")
options: a {} to set various config options, see __init__()
"""
# allow to pre-set target circuit as object-attr,
# instead of passing as argument
self.cur_circ = circuit_id or self.cur_circ
self.cur_circ_raw = circuit_raw or self.cur_circ_raw
# make sure both contain something useful
assert self.cur_circ
assert self.cur_circ_raw
# apply available OPTIONS here
options = self.options = options or {}
xsize = options.get("xsize") or 40
ysize = options.get("ysize") or 40
optimizer = "deterministic"
if "optimizer" in options:
optimizer = options["optimizer"]
try:
# max field size is critical...
# DETERMINISTIC -> can be biiig, makes no difference
# EVOLUTIONARY -> small approx 14x14 for 4block+bias
print "\n".join(str(x) for x in self.cur_circ_raw)
field = Field(self.cur_circ, xsize, ysize)
#if optimizer == "deterministic":
# o = Deterministic(field)
#elif optimizer == "evolution":
# o = GeneticAlgorithm(field)
#else:
# print "[ERR] Unknown optimizer!"
# sys.exit(1)
o = FakeOptimizer(field, self.cur_circ_raw)
field = o.run()
field.optimize_size()
self.plot(field)
return True
except (OptimizerError, FieldException) as e:
print "[-] failed to create schematic for circ {}".format(self.cur_circ)
print e.message
return False
return None # never reached
示例2: Regression
# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import optimize_size [as 别名]
#.........这里部分代码省略.........
self.assertEqual(len(self.field), len(self.raw_data))
def test_block_move(self):
self.test_add_blocks()
blk = filter(lambda a: a.name == "m3", self.field.get_blocks())
self.assertEqual(len(blk), 1)
blk = blk[0]
pos = (6, 0)
self.assertTrue(self.field.move(blk, pos))
self.assertEqual(self.field.get_block_pos(blk), pos)
def test_block_swap(self):
self.test_add_blocks()
name2blk = dict((b.name, b) for b in self.field.get_blocks())
self.assertTrue(
self.field.swap(name2blk["m1"], name2blk["m2"])
)
def test_field_copy_roundtrip(self):
self.test_add_blocks()
f1 = self.field.copy()
self.test_add_blocks()
f2 = self.field.copy()
list_props = lambda blks, prop: tuple(sorted(getattr(blk, prop) for blk in blks))
bl1 = f1.get_blocks()
bl2 = f2.get_blocks()
for pname in ["name", "groups", "type"]:
self.assertSequenceEqual(list_props(bl1, pname), list_props(bl2, pname))
self.assertEqual(f1.ny, f2.ny)
self.assertEqual(f1.nx, f2.nx)
self.assertEqual(len(f1.block2xy), len(f2.block2xy))
self.assertEqual(len(f1.block2yx), len(f2.block2yx))
self.assertEqual(len(f1.xy2block), len(f2.xy2block))
self.assertEqual(len(f1.yx2block), len(f2.yx2block))
def test_field_finalization(self):
self.test_add_blocks()
self.field.optimize_size()
# no error is good at this point
self.assertTrue(True)
def test_expansion(self):
self.test_field_finalization()
nx, ny = self.field.nx, self.field.ny
self.field.expand_field(4)
fn = draw_field(self.field, self.get_tempfile(4))
self.assertTrue(nx < self.field.nx)
self.assertTrue(ny < self.field.ny)
def test_routing(self):
self.test_field_finalization()
r = Routing(self.field)
ret = r.route(4)
self.assertGreaterEqual(ret[0], 1)
def test_draw_pdf(self):
self.test_routing()
fn = draw_field(self.field, self.get_tempfile(1))
self.assertTrue( os.path.isfile(fn) )
self.assertTrue( os.path.exists(fn) )
self.assertTrue( len(file(fn).read()) > 10 )
def test_draw_without_routing(self):
self.test_field_finalization()
fn = draw_field(self.field, self.get_tempfile(2))
self.assertTrue( os.path.isfile(fn) )
self.assertTrue( os.path.exists(fn) )
self.assertTrue( len(file(fn).read()) > 10 )
def test_draw_with_grid(self):
self.test_field_finalization()
fn = draw_field(self.field, self.get_tempfile(3), grid=(10, 10, 0, 0, 1))
self.assertTrue( os.path.isfile(fn) )
self.assertTrue( os.path.exists(fn) )
self.assertTrue( len(file(fn).read()) > 10 )