Dynamical QCD simulation with theta terms