google-research / nasbench

NASBench: A Neural Architecture Search Dataset and Benchmark
Apache License 2.0
682 stars 129 forks source link

Query neighbors of an architecture #9

Open bkj opened 5 years ago

bkj commented 5 years ago

Is there code somewhere here that takes an architecture and returns all of it's neighbors? Eg, the architectures that can be generated by adding/removing one edge or changing the op at one node?

Something like

neighbors = get_neighbors(arch)
assert all([edit_distance(arch, n) == 1 for n in neighbors])

Thanks!

aaronkl commented 5 years ago

We implemented a wrapper that combines nasbench with the ConfigSpace package, which provides an efficient function to compute the neighborhood of an architecture encoded as a Configuration object. It is for example also used in SMAC for the local search of the acquisition function.

The following example demonstrates how you can get all neighbors of a random configuration:

from tabular_benchmarks import NASCifar10A
from ConfigSpace.util import get_one_exchange_neighbourhood
b = NASCifar10A(PATH_TO_NASBENCH)
cs = b.get_configuration_space()
config = cs.sample_configuration()
for n in get_one_exchange_neighbourhood(config, 42):
    print(n)