Skip to content

Commit e5319d8

Browse files
committed
docs
1 parent c6e1872 commit e5319d8

File tree

1 file changed

+83
-52
lines changed

1 file changed

+83
-52
lines changed

netket_fidelity/infidelity/logic.py

Lines changed: 83 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -19,93 +19,124 @@ def InfidelityOperator(
1919
sample_Upsi=False,
2020
):
2121
r"""
22-
Operator I_op computing the infidelity I among two variational states |ψ⟩ and |Φ⟩ as:
22+
Operator I_op computing the infidelity I among two variational states
23+
:math:`|\psi\rangle` and :math:`|\phi\rangle` as:
2324
2425
.. math::
2526
26-
I = 1 - |⟨ψ|Φ⟩|^2 / ⟨ψ|ψ⟩ ⟨Φ|Φ⟩ = 1 - ⟨ψ|I_op|ψ⟩ / ⟨ψ|ψ⟩
27+
I = 1 - \frac{|⟨\Psi|\Phi⟩|^2 }{ ⟨\Psi|\Psi⟩ ⟨\Phi|\Phi⟩ } = 1 - \frac{⟨\Psi|\hat{I}_{op}|\Psi⟩ }{ ⟨\Psi|\Psi⟩ }
2728
2829
where:
2930
30-
.. math::
31+
.. math::
3132
32-
I_op = |Φ⟩⟨Φ| / ⟨Φ|Φ⟩
33+
I_{op} = \frac {|\Phi\rangle\langle\Phi| }{ \langle\Phi|\Phi\rangle }
3334
34-
The state |Φ⟩ can be an autonomous state |Φ⟩ =|ϕ⟩ or an operator U applied to it, namely
35-
|Φ⟩ = U|ϕ⟩. I_op is defined by the state |ϕ⟩ (called target) and, possibly, by the operator U.
36-
If U is not passed, it is assumed |Φ⟩ =|ϕ⟩.
35+
The state :math:`|\phi\rangle` can be an autonomous state :math:`|\Phi\rangle = |\phi\rangle`
36+
or an operator :math:`U` applied to it, namely
37+
:math:`|\Phi\rangle = U|\phi\rangle`. :math:`I_{op}` is defined by the
38+
state :math:`|\phi\rangle` (called target) and, possibly, by the operator
39+
:math:`U`. If :math:`U` is not specified, it is assumed :math:`|\Phi\rangle = |\phi\rangle`.
3740
3841
The Monte Carlo estimator of I is:
3942
40-
..math::
43+
.. math::
44+
45+
I = \mathbb{E}_{χ}[ I_{loc}(\sigma,\eta) ] =
46+
\mathbb{E}_{χ}\left[\frac{⟨\sigma|\Phi⟩ ⟨\eta|\Psi⟩}{⟨σ|\Psi⟩ ⟨η|\Phi⟩}\right]
47+
48+
where the sampled probability distribution :math:`χ` is defined as:
49+
50+
.. math::
51+
52+
\chi(\sigma, \eta) = \frac{|\psi(\sigma)|^2 |\Phi(\eta)|^2}{
53+
\langle\Psi|\Psi\rangle \langle\Phi|\Phi\rangle}.
54+
55+
In practice, since I is a real quantity, :math:`\rm{Re}[I_{loc}(\sigma,\eta)]`
56+
is used. This estimator can be utilized both when :math:`|\Phi\rangle =|\phi\rangle` and
57+
when :math:`|\Phi\rangle =U|\phi\rangle`, with :math:`U` a (unitary or non-unitary) operator.
58+
In the second case, we have to sample from :math:`U|\phi\rangle` and this is implemented in
59+
the function :class:`netket_fidelity.infidelity.InfidelityUPsi` .
60+
61+
This works only with the operators provdided in the package.
62+
We remark that sampling from :math:`U|\phi\rangle` requires to compute connected elements of
63+
:math:`U` and so is more expensive than sampling from an autonomous state.
64+
The choice of this estimator is specified by passing :code:`sample_Upsi=True`,
65+
while the flag argument :code:`is_unitary` indicates whether :math:`U` is unitary or not.
4166
42-
I = \mathbb{E}_{χ}[ I_loc(σ,η) ] = \mathbb{E}_{χ}[ ⟨σ|Φ⟩ ⟨η|ψ⟩ / ⟨σ|ψ⟩ ⟨η|Φ⟩ ]
67+
If :math:`U` is unitary, the following alternative estimator can be used:
4368
44-
where χ(σ, η) = |Ψ(σ)|^2 |Φ(η)|^2 / ⟨ψ|ψ⟩ ⟨Φ|Φ⟩. In practice, since I is a real quantity, Re{I_loc(σ,η)}
45-
is used. This estimator can be utilized both when |Φ⟩ =|ϕ⟩ and when |Φ⟩ = U|ϕ⟩, with U a (unitary or
46-
non-unitary) operator. In the second case, we have to sample from U|ϕ⟩ and this is implemented in
47-
the function :ref:`jax.:ref:`InfidelityUPsi`. This works only with the operators provdided in the package.
48-
We remark that sampling from U|ϕ⟩ requires to compute connected elements of U and so is more expensive
49-
than sampling from an autonomous state. The choice of this estimator is specified by passing
50-
`sample_Upsi=True`, while the flag argument `is_unitary` indicates whether U is unitary or not.
69+
.. math::
70+
71+
I = \mathbb{E}_{χ'}\left[ I_{loc}(\sigma, \eta) \right] =
72+
\mathbb{E}_{χ}\left[\frac{\langle\sigma|U|\phi\rangle \langle\eta|\psi\rangle}{
73+
\langle\sigma|U^{\dagger}|\psi\rangle ⟨\eta|\phi⟩} \right].
5174
52-
If U is unitary, the following alternative estimator can be used:
75+
where the sampled probability distribution :math:`\chi` is defined as:
5376
54-
..math::
77+
.. math::
5578
56-
I = \mathbb{E}_{χ'}[ I_loc(σ,η) ] = \mathbb{E}_{χ}[ ⟨σ|U|ϕ⟩ ⟨η|ψ⟩ / ⟨σ|U^{\dagger}|ψ⟩ ⟨η|ϕ⟩ ].
79+
\chi'(\sigma, \eta) = \frac{|\psi(\sigma)|^2 |\phi(\eta)|^2}{
80+
\langle\Psi|\Psi\rangle \langle\phi|\phi\rangle}.
5781
58-
where χ'(σ, η) = |Ψ(σ)|^2 |ϕ(η)|^2 / ⟨ψ|ψ⟩ ⟨ϕ|ϕ⟩. This estimator is more efficient since it does not
59-
require to sample from U|ϕ⟩, but only from |ϕ⟩. This choice of the estimator is the default and it works only
60-
with `is_unitary==True` (besides `sample_Upsi=False`). When |Φ⟩ = |ϕ⟩ the two estimators coincides.
82+
This estimator is more efficient since it does not require to sample from
83+
:math:`U|\phi\rangle`, but only from :math:`|\phi\rangle`.
84+
This choice of the estimator is the default and it works only
85+
with `is_unitary==True` (besides :code:`sample_Upsi=False` ).
86+
When :math:`|\Phi⟩ = |\phi⟩` the two estimators coincides.
6187
6288
To reduce the variance of the estimator, the Control Variates (CV) method can be applied. This consists
6389
in modifying the estimator into:
6490
65-
..math::
91+
.. math::
6692
67-
I_loc^{CV} = Re{I_loc(σ,η)} - c (|1 - I_loc(σ,η)^2| - 1)
93+
I_{loc}^{CV} = \rm{Re}\left[I_{loc}(\sigma, \eta)\right] - c \left(|1 - I_{loc}(\sigma, \eta)^2| - 1\right)
6894
69-
where c ∈ \mathbb{R}. The constant c is chosen to minimize the variance of I_loc^{CV} as:
95+
where :math:`c ∈ \mathbb{R}`. The constant c is chosen to minimize the variance of
96+
:math:`I_{loc}^{CV}` as:
7097
71-
..math::
98+
.. math::
7299
73-
c* = Cov_{χ}[ |1-I_loc|^2, Re{1-I_loc}] / Var_{χ}[ |1-I_loc|^2 ],
100+
c* = \frac{\rm{Cov}_{χ}\left[ |1-I_{loc}|^2, \rm{Re}\left[1-I_{loc}\right]\right]}{
101+
\rm{Var}_{χ}\left[ |1-I_{loc}|^2\right] },
74102
75-
where Cov[..., ...] indicates the covariance and Var[...] the variance. In the relevant limit
76-
|Ψ⟩ →|Φ⟩, we have c*→-1/2. The value -1/2 is adopted as default value for c in the infidelity
103+
where :math:`\rm{Cov}\left\cdot, \cdot\right]` indicates the covariance and :math:`\rm{Var}\left[\cdot\right]` the variance.
104+
In the relevant limit :math:`|\Psi⟩ \rightarrow|\Phi⟩`, we have :math:`c^\star \rightarrow -1/2`. The value :math:`-1/2` is
105+
adopted as default value for c in the infidelity
77106
estimator. To not apply CV, set c=0.
78107
79108
Args:
80-
target: target variational state |ϕ⟩.
81-
U: operator U.
82-
U_dagger: dagger operator U^{\dagger}.
109+
target: target variational state :math:`|\phi⟩` .
110+
U: operator :math:`\hat{U}`.
111+
U_dagger: dagger operator :math:`\hat{U^\dagger}`.
83112
cv_coeff: Control Variates coefficient c.
84-
is_unitary: flag specifiying the unitarity of U. If True with `sample_Upsi=False`, the second estimator is used.
113+
is_unitary: flag specifiying the unitarity of :math:`\hat{U}`. If True with
114+
:code:`sample_Upsi=False`, the second estimator is used.
85115
dtype: The dtype of the output of expectation value and gradient.
86-
sample_Upsi: flag specifiying whether to sample from |ϕ⟩ or from U|ϕ⟩. If False with `is_unitary=False`, an error occurs.
116+
sample_Upsi: flag specifiying whether to sample from |ϕ⟩ or from U|ϕ⟩. If False with `is_unitary=False` , an error occurs.
87117
88118
Returns:
89119
Infidelity operator for which computing expected value and gradient.
90120
91-
Example:
92-
import netket as nk
93-
import netket_fidelity as nkf
94-
95-
hi = nk.hilbert.Spin(0.5, 4)
96-
sampler = nk.sampler.MetropolisLocal(hilbert=hi, n_chains_per_rank=16)
97-
model = nk.models.RBM(alpha=1, param_dtype=complex)
98-
target_vstate = nk.vqs.MCState(sampler=sampler, model=model, n_samples=100)
99-
100-
# To optimise the overlap with |ϕ⟩
101-
I_op = nkf.InfidelityOperator(target_vstate)
102-
103-
# To optimise the overlap with U|ϕ⟩ by sampling from |ψ⟩ and |ϕ⟩
104-
U = nkf.operator.Rx(0.3)
105-
I_op = nkf.InfidelityOperator(target_vstate, U=U, is_unitary=True)
106-
107-
# To optimise the overlap with U|ϕ⟩ by sampling from |ψ⟩ and U|ϕ⟩
108-
I_op = nkf.InfidelityOperator(target_vstate, U=U, sample_Upsi=True)
121+
Examples:
122+
123+
>>> import netket as nk
124+
>>> import netket_fidelity as nkf
125+
>>>
126+
>>> hi = nk.hilbert.Spin(0.5, 4)
127+
>>> sampler = nk.sampler.MetropolisLocal(hilbert=hi, n_chains_per_rank=16)
128+
>>> model = nk.models.RBM(alpha=1, param_dtype=complex)
129+
>>> target_vstate = nk.vqs.MCState(sampler=sampler, model=model, n_samples=100)
130+
>>>
131+
>>> # To optimise the overlap with |ϕ⟩
132+
>>> I_op = nkf.InfidelityOperator(target_vstate)
133+
>>>
134+
>>> # To optimise the overlap with U|ϕ⟩ by sampling from |ψ⟩ and |ϕ⟩
135+
>>> U = nkf.operator.Rx(0.3)
136+
>>> I_op = nkf.InfidelityOperator(target_vstate, U=U, is_unitary=True)
137+
>>>
138+
>>> # To optimise the overlap with U|ϕ⟩ by sampling from |ψ⟩ and U|ϕ⟩
139+
>>> I_op = nkf.InfidelityOperator(target_vstate, U=U, sample_Upsi=True)
109140
110141
"""
111142
if U is None:

0 commit comments

Comments
 (0)