  Variational Quantum Algorithms (VQA) are promising to demonstrate quantum
advantages on near-term devices. Designing ansatz, a variational circuit with
parameterized gates, is of paramount importance for VQA as it lays the
foundation for parameter optimizations. Due to the large noise on
Noisy-Intermediate Scale Quantum (NISQ) machines, considering circuit size and
real device noise in the ansatz design process is necessary. Unfortunately,
recent works on ansatz design either consider no noise impact or only treat the
real device as a black box with no specific noise information. In this work, we
propose to open the black box by designing specific ansatz tailored for the
qubit topology on target machines. Specifically, we propose a bottom-up
approach to generate topology-specific ansatz. Firstly, we generate
topology-compatible sub-circuits with desirable properties such as high
expressibility and entangling capability. Then, the sub-circuits are combined
together to form an initial ansatz. We further propose circuits stitching to
solve the sparse connectivity issue between sub-circuits, and dynamic circuit
growing to improve the accuracy. The ansatz constructed with this method is
highly flexible and thus we can explore a much larger design space than
previous state-of-the-art method in which all ansatz candidates are strict
subsets of a pre-defined large ansatz. We use a popular VQA algorithm - Quantum
Neural Networks (QNN) for Machine Learning (ML) task as the benchmarks.
Experiments on 14 ML tasks show that under the same performance, the
TopGen-searched ansatz can reduce the circuit depth and the number of CNOT
gates by up to 2 * and 4 * respectively. Experiments on three real quantum
machines demonstrate on average 17% accuracy improvements over baselines.
