An integrated self-optimizing programmable chemical synthesis and reaction engine