Quantized periods in electromagnetic duality path integral In John McGreevy's notes (page 64 of https://mcgreevy.physics.ucsd.edu/w21/2021W-239-lectures.pdf), he describes a path integral derivation of electromagnetic duality for $p$-form gauge fields. The first step in the duality involves introducing a Lagrange multiplier field $A^\vee$:
$$\int [dA] e^{-\frac{1}{2g} \int dA \wedge \star dA} = \int [dA \, dB \, dA^\vee] e^{-\frac{1}{2g} \int (F-B) \wedge \star (F-B) + i \int B \wedge dA^\vee}.$$
Here $A$ is a $p$-form gauge field with field strength $F$, $A^\vee$ is a $(D-p-2)$-form gauge field, $B$ is a $(p+1)$-form field, and $D$ is the spacetime dimension. In the second term, we also have a redundancy: $A\rightarrow A+\Lambda, \, B \rightarrow B + d\Lambda$.
I understand how performing the functional integration over the Lagrange multiplier $A^\vee$ will impose the constraint $dB = 0$: essentially by integrating by parts we can get a delta function
$$\delta(dB) \sim \int [dA^\vee] e^{\pm i \int dB \wedge A^\vee} $$
However, he makes another claim, which I have seen elsewhere in the literature (e.g Section 2.2 in Witten's "On S-Duality in Abelian Gauge Theory"): that this integration also forces the field $B$ to have integral periods, such that
$$\oint_S B \in 2\pi \mathbb{Z}, $$
where $S$ is any (closed) cycle in the spacetime manifold.

*

*How does the Lagrange multiplier also enforce integer periods of $B$?


*Furthermore, if $B$ is closed ($dB=0$) and has integer periods, how can we set $B=0$ through a gauge transformation $B \rightarrow B + d
   \Lambda$?
Naively it seems to me like this gauge transformation cannot change the cohomology class of $B$ because it is shifting it by an exact form, yet it is claimed that we have the freedom to set $B=0$ (This claim is also repeated in Witten's article above - perhaps $d\Lambda$ is only locally exact?)
 A: In my opinion, in the lecture notes an monopole operator is implicitly inserted. Otherwise, it cannot make any sense. When a Dirac monopole is inserted in space, then the flux $B$ must satisfy the quantization condition $$\int_{S^{2}}\frac{B}{2\pi}\in\mathbb{Z}.$$
More explicity, let's consider a simpler action at the moment: $$S[B]=-\frac{1}{2}\int B\wedge\star B.$$
This model has two generalized symmetries, whose Noether currents are: $$j_{e}=B,\quad\mathrm{and}\quad j_{m}=\star B.$$
They are conserved on-shell because of the Bianchi identity $d\star j_{m}=dB=0$, and the equation of motion $d\star j_{e}=d\star B=0$.
To see this is indeed a global symmetry, one can impose the Bianchi identity in the path-integral $$\mathcal{Z}=\int\mathcal{D}B\int\mathcal{D}\sigma\exp\left(-i\frac{1}{2}\int B\wedge\star B+i\int\sigma dB\right),$$
and integrate out $B$ field. Then, one obtains $$\mathcal{Z}=\int\mathcal{D}\sigma\exp\left(i\frac{1}{2}\int d\sigma\wedge\star d\sigma\right).$$
From the above dual description, one finds that the symmetry is actually a constant shift $\sigma\rightarrow\sigma+a$, where $a$ is an arbitrary constant.
In the lecture notes, as far as I understand, it makes sense only when a Dirac monopole $$dB=2\pi\delta(x)$$
is imposed. Only in this case, then the condition $$\int_{S^3}dB=\oint_{S^2}B\in 2\pi\mathbb{Z}$$
makes sense. One can insert this monopole operator in the following procedure:
By introducing an auxiliary field as before, the partition function becomes $$\mathcal{Z}=\int\mathcal{D}B\int\mathcal{D}\sigma\exp\left(-i\frac{1}{2}\int B\wedge\star B+i\int\sigma(dB-2\pi\delta(x))\right).$$
Integrating out the $B$ field, one gets $$\mathcal{Z}=\int\mathcal{D}\sigma\left(e^{2\pi i\sigma(0)}\right)\exp\left(i\frac{1}{2}\int d\sigma\wedge\star d\sigma\right).$$
That is, one inserted a monopole operator $$\mathcal{M}(x)\equiv e^{2\pi i\sigma(x)}$$
at $x=0$ in the partition function. By doing so, the original $\mathbb{R}$ symmetry is broken into $\mathbb{Z}$.
But whenever $x\neq 0$, $dB=0$ is satisfied, which has a local redundancy $$B\rightarrow B+d\Lambda.$$
Then, by Poincaré lemma, one can always find an open neighborhood $U_{x}$ of $\forall x\neq 0$, where $B$ is exact, say $B=dC$ for some $p$-form $C$. Then, by choosing $\Lambda=-C$, one has $B=0$ on $U_{x}$. The result is not true if one chooses an open neighborhood $U_{x}$ containing $x=0$.
