They both are grammatically right. Both 'to' and 'with' can be used with compare but they differ slightly is usage. - To compare to is traditionally used to point out or imply resemblances between objects.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.