Ahlfors and Beurling [16] proved that set $E$ is removable for class $AD^2$ of analytic functions with the finite Dirichlet integral if and only if $E$ does not change extremal distances. Their proof uses the conformal invariance of class $AD^2$, so it does not immediately generalize to $p\ne2$ and to the relevant classes of harmonic functions in the space. In 1974 Hedberg [19] proposed new approaches to the problem of describing removable singularities in the function theory. In particular he gave the exact functional capacitive conditions for a set to be removable for class $HD^p(G)$. Here $HD^p(G)$ is the class of real-valued harmonic functions $u$ in a bounded open set $G\subset R^n$, $n\ge2$, and such that
$$
\int\limits_G|\nabla u|^p\,dx\infty, \quad p>1.
$$
In this paper we extend Hedberg's results on class $HD^{p,w}(G)$ of harmonic functions $u$ in $G$ and such that
$$
\int\limits_G|\nabla u|^p\,wdx\infty.
$$
Here a locally integrable function $w:R^n\to(0,+\infty)$ satisfies the Muckenhoupt condition [20]
$$
\sup\frac1{|Q|}\int\limits_Qwdx \left(\frac1{|Q|}\int\limits_Qw^{1-q}dx\right)^{p-1}\infty,
$$
where the supremum is taking over all coordinate cubes $Q\subset R^n$, $q\in (1,+\infty)$ and $\frac1p+\frac1q=1$; by $\mathcal L_n (Q)=|Q|$ we denote the $n$-dimensional Lebesgue measure of $Q$.
We denote by $L^1_{q,\tilde w}(G)$ the Sobolev space of locally integrable functions $F$ on $G$, whose generalized gradient in $G$ are such that
$$
\|f\|_{L^1_{q,\tilde w}(G)}=\left(\int\limits_G|\nabla f|^q\,\tilde wdx\right)^{\frac1q}\infty,\text{ where }\tilde w=w^{1-q}.
$$ The closure of $C_0^\infty(G)$ in $\|\cdot \|_{L^1_{q,\tilde w}(G)}$ is denoted by $L^{\circ 1}_{q,\tilde w}(G)$.
For compact set $K\subset G$ $(q,\tilde w)$-capacity regarding $G$ is defined by
$$
C_{q,\tilde w}(K)=\inf_v\int\limits_G|\nabla v|^q\,\tilde wdx,
$$
where the infimum is taken over all $v\in C^\infty_0(G)$ such that $v=1$ in some neighbourhood of $K$.
Note that $C_{q,\tilde w}(K)=0$ is independent from the choice of bounded set $G\subset R^n$. We set $C_{q,\tilde w}(F)=0$ for arbitrary $F\subset R^n$ if for every compact $K\subset F$ there exists a bounded open set $G$ such that $C_{q,\tilde w}(K)=0$ regarding $G$.
To conclude, we formulate the main results.
Theorem 1. Compact $E\subset G$ is removable for $HD^{p,w}(G)$ if and only if $C_0^\infty(G\setminus E)$ is dense in $L^{\circ 1}_{q,\tilde w}(G)$.
Theorem 2. Compact $E\subset G$ is removable for $HD^{p,w}(G)$ if and only if $C_{q,\tilde w}(E)=0$.
Corollary. The property of being removable for $HD^{p,w}(G)$ is local, i.e. compact $E\subset G$ is removable if and only if every $x\in E$ has a compact neighbourhood, whose intersection with $G$ is removable.
Theorem 3. If $G$ is an open set in $R^n$ and $C_{q,\tilde w}(R^n\setminus G)=0$. Then $C_0^\infty(G)$ is dense in $L^{\circ 1}_{q,\tilde w}(R^n)$.