It freezes as you are not sending in the appropriate MPI communicator to the expression.
Since you are not sending in a communicator (which in your case should be MPI.COMM_SELF
, it is using the mesh communicator, thus waiting for a sync step between all processes that never happens. See: dolfinx.fem — DOLFINx 0.7.3 documentation
i.e.
E = Expression(expr, x_ref, comm=MPI.COMM_SELF)
does the trick