deepquantum.photonic package#
Submodules#
deepquantum.photonic.ansatz module#
Ansatze: various photonic quantum circuits
- class deepquantum.photonic.ansatz.Clements(nmode: int, init_state: Any, cutoff: int | None = None, basis: bool = True, phi_first: bool = True, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
-
Clements circuit.
- dict2data(angle_dict: Dict, dtype=torch.float32) Tensor #
Convert the dictionary of angles to the input data for the circuit.
- class deepquantum.photonic.ansatz.GaussianBosonSampling(nmode: int, squeezing: Any, unitary: Any, cutoff: int | None = None, backend: str = 'gaussian', basis: bool = True, detector: str = 'pnrd', noise: bool = False, mu: float = 0, sigma: float = 0.1)#
-
Gaussian Boson Sampling circuit.
- class deepquantum.photonic.ansatz.GBS_Graph(adj_mat: Any, cutoff: int | None = None, mean_photon_num: int | None = None, detector: str = 'pnrd', noise: bool = False, mu: float = 0, sigma: float = 0.1)#
-
Simulate Gaussian Boson Sampling for graph problems.
- static norm_factor_c(n_num, lambd, trials=20)#
Get the normalization factor c of squeezing parameters for given total mean photon numbers.
- static postselect(samples: Dict, nodes_list: List) List #
Postselect the results with the fixed node subgraph.
- static graph_density(graph: Graph, samples: Dict) Dict #
Get all subgraph densities.
deepquantum.photonic.channel module#
Photonic quantum channels
- class deepquantum.photonic.channel.PhotonLoss(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, requires_grad: bool = False)#
基类:
Channel
Photon loss channel on single mode.
This channel couples the target mode $hat{a}$ to the vacuum mode $hat{b}$ using following transformation:
\[\hat{a}_{\text{out}} = \sqrt{T}\hat{a}_{\text{in}} + \sqrt{1-T}\hat{b}_{\text{vac}}\]- 参数:
inputs (Any, optional) – The parameter of the channel. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)
- property theta#
- property t#
Transmittance.
- update_matrix_state() Tensor #
Update the local Kraus matrices acting on Fock state density matrices.
- get_matrix_state(theta: Any) Tensor #
Get the local Kraus matrices acting on Fock state density matrices.
See https://arxiv.org/pdf/1012.4266 Eq.(2.4)
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- update_transform_xy() Tuple[Tensor, Tensor] #
Update the local transformation matrices X and Y acting on Gaussian states.
See https://arxiv.org/pdf/quant-ph/0503237 Eq.(4.19), Eq.(4.20)
deepquantum.photonic.circuit module#
Photonic quantum circuit
- class deepquantum.photonic.circuit.QumodeCircuit(nmode: int, init_state: Any, cutoff: int | None = None, backend: str = 'fock', basis: bool = True, den_mat: bool = False, detector: str = 'pnrd', name: str | None = None, mps: bool = False, chi: int | None = None, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Operation
Photonic quantum circuit.
- 参数:
nmode (int) – The number of modes in the circuit.
init_state (Any) – The initial state of the circuit. It can be a vacuum state with
'vac'
. For Fock backend, it can be a Fock basis state, e.g.,[1,0,0]
, or a Fock state tensor, e.g.,[(1/2**0.5, [1,0]), (1/2**0.5, [0,1])]
. Alternatively, it can be a tensor representation. For Gaussian backend, it can be arbitrary Gaussian states with[cov, mean]
. For Bosonic backend, it can be arbitrary linear combinations of Gaussian states with[cov, mean, weight]
, or a list of local Bosonic states. Usexxpp
convention and \(\hbar=2\) by default.cutoff (int or None, optional) – The Fock space truncation. Default:
None
backend (str, optional) – Use
'fock'
for Fock backend,'gaussian'
for Gaussian backend or'bosonic'
for Bosonic backend. Default:'fock'
basis (bool, optional) – Whether to use the representation of Fock basis state for the initial state. Default:
True
den_mat (bool, optional) – Whether to use density matrix representation. Only valid for Fock state tensor. Default:
False
detector (str, optional) – For Gaussian backend, use
'pnrd'
for the photon-number-resolving detector or'threshold'
for the threshold detector. Default:'pnrd'
name (str or None, optional) – The name of the circuit. Default:
None
mps (bool, optional) – Whether to use matrix product state representation. Default:
False
chi (int or None, optional) – The bond dimension for matrix product state representation. Default:
None
noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- set_init_state(init_state: Any) None #
Set the initial state of the circuit.
- to(arg: Any) QumodeCircuit #
Set dtype or device of the
QumodeCircuit
.
- forward(data: Tensor | None = None, state: Any | None = None, is_prob: bool | None = None, detector: str | None = None, stepwise: bool = False) Tensor | Dict | List[Tensor] #
Perform a forward pass of the photonic quantum circuit and return the final-state-related result.
- 参数:
data (torch.Tensor or None, optional) – The input data for the
encoders
. Default:None
state (Any, optional) – The initial state for the photonic quantum circuit. Default:
None
is_prob (bool or None, optional) – For Fock backend, whether to return probabilities or amplitudes. For Gaussian backend, whether to return probabilities or the final Gaussian state. For Fock backend with
basis=True
, setNone
to return the unitary matrix. Default:None
detector (str or None, optional) – For Gaussian backend, use
'pnrd'
for the photon-number-resolving detector or'threshold'
for the threshold detector. Default:None
stepwise (bool, optional) – Whether to use the forward function of each operator for Gaussian backend. Default:
False
- 返回:
The result of the photonic quantum circuit after applying the
operators
.- 返回类型:
Union[torch.Tensor, Dict, List[torch.Tensor]]
- global_circuit(nstep: int, use_deepcopy: bool = False) QumodeCircuit #
Get the global circuit given the number of time steps.
备注
The initial state of the global circuit is always the vacuum state.
- encode(data: Tensor | None) None #
Encode the input data into the photonic quantum circuit parameters.
This method iterates over the
encoders
of the circuit and initializes their parameters with the input data.- 参数:
data (torch.Tensor or None) – The input data for the
encoders
, must be a 1D tensor.
- get_unitary() Tensor #
Get the unitary matrix of the photonic quantum circuit.
- get_symplectic() Tensor #
Get the symplectic matrix of the photonic quantum circuit.
- get_displacement(init_mean: Any) Tensor #
Get the final mean value of the Gaussian state in
xxpp
order.
- get_amplitude(final_state: Any, init_state: Any | None = None, unitary: Tensor | None = None) Tensor #
Get the transfer amplitude between the final state and the initial state.
备注
When states are expanded due to photon loss or batched initial states, the amplitudes of the reduced states can not be added, please try
get_prob
instead.- 参数:
final_state (Any) – The final Fock basis state.
init_state (Any, optional) – The initial Fock basis state. Default:
None
unitary (torch.Tensor or None, optional) – The unitary matrix. Default:
None
- get_prob(final_state: Any, refer_state: Any | None = None, unitary: Tensor | None = None) Tensor #
Get the probability of the final state related to the reference state.
- 参数:
final_state (Any) – The final Fock basis state.
refer_state (Any, optional) – The initial Fock basis state or the final Gaussian state. Default:
None
unitary (torch.Tensor or None, optional) – The unitary matrix. Default:
None
- measure(shots: int = 1024, with_prob: bool = False, wires: int | List[int] | None = None, detector: str | None = None, mcmc: bool = False) Dict | List[Dict] | None #
Measure the final state.
- 参数:
shots (int, optional) – The number of times to sample from the quantum state. Default: 1024
with_prob (bool, optional) – A flag that indicates whether to return the probabilities along with the number of occurrences. Default:
False
wires (int, List[int] or None, optional) – The wires to measure. It can be an integer or a list of integers specifying the indices of the wires. Default:
None
(which means all wires are measured)detector (str or None, optional) – For Gaussian backend, use
'pnrd'
for the photon-number-resolving detector or'threshold'
for the threshold detector. Default:None
mcmc (bool, optional) – Whether to use MCMC sampling method. Default:
False
See https://arxiv.org/pdf/2108.01622 for MCMC.
- photon_number_mean_var(wires: int | List[int] | None = None) Tuple[Tensor, Tensor] | None #
Get the expectation value and variance of the photon number operator.
- 参数:
wires (int, List[int] or None, optional) – The wires to measure. It can be an integer or a list of integers specifying the indices of the wires. Default:
None
(which means all wires are measured)
- measure_homodyne(shots: int = 10, wires: int | List[int] | None = None) Tensor | None #
Get the homodyne measurement results.
If
self.measurements
is specified viaself.homodyne
, return the results of the conditional homodyne measurement. Otherwise, return the results of the ideal homodyne measurement. The Gaussian states after measurements are stored inself.state_measured
.备注
batch
*shots
can not be too large for Fock backend.- 参数:
shots (int, optional) – The number of times to sample from the quantum state. Default: 10
wires (int, List[int] or None, optional) – The wires to measure for the ideal homodyne. It can be an integer or a list of integers specifying the indices of the wires. Default:
None
(which means all wires are measured)
- property max_depth: int#
Get the max number of gates on the wires.
- draw(filename: str | None = None, unroll: bool = False)#
Visualize the photonic quantum circuit.
- 参数:
filename (str or None, optional) – The path for saving the figure.
unroll (bool, optional) – Whether to draw the unrolled circuit.
- cat(wires: int, r: Any | None = None, theta: Any | None = None, p: int = 1) None #
Prepare a cat state.
- gkp(wires: int, theta: Any | None = None, phi: Any | None = None, amp_cutoff: float = 0.1, epsilon: float = 0.05) None #
Prepare a GKP state.
- add(op: Operation, encode: bool = False, wires: int | List[int] | None = None) None #
A method that adds an operation to the photonic quantum circuit.
The operation can be a gate or another photonic quantum circuit. The method also updates the attributes of the photonic quantum circuit. If
wires
is specified, the parameters of gates are shared.- 参数:
op (Operation) – The operation to add. It is an instance of
Operation
class or its subclasses, such asGate
, orQumodeCircuit
.encode (bool, optional) – Whether the gate is to encode data. Default:
False
wires (int, List[int] or None, optional) – The wires to apply the gate on. It can be an integer or a list of integers specifying the indices of the wires. Default:
None
(which means the gate has its own wires)
- 抛出:
AssertionError – If the input arguments are invalid or incompatible with the quantum circuit.
- ps(wires: int, inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a phase shifter.
- bs(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a beam splitter.
- mzi(wires: List[int], inputs: Any | None = None, phi_first: bool = True, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a Mach-Zehnder interferometer.
- bs_theta(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a beam splitter with fixed \(\phi\) at \(\pi/2\).
- bs_phi(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a beam splitter with fixed \(\theta\) at \(\pi/4\).
- bs_rx(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add an Rx-type beam splitter.
- bs_ry(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add an Ry-type beam splitter.
- bs_h(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add an H-type beam splitter.
- dc(wires: List[int], mu: float | None = None, sigma: float | None = None) None #
Add a directional coupler.
- h(wires: List[int], mu: float | None = None, sigma: float | None = None) None #
Add a photonic Hadamard gate.
- any(unitary: Any, wires: int | List[int] | None = None, minmax: List[int] | None = None, name: str = 'uany') None #
Add an arbitrary unitary gate.
- clements(unitary: Any, wires: int | List[int] | None = None, minmax: List[int] | None = None, mu: float | None = None, sigma: float | None = None) None #
Add the Clements architecture of the unitary matrix.
This is equivalent to
any
, using ‘cssr’-type Clements decomposition. Whenbasis
isFalse
, this implementation is much faster.
- s(wires: int, r: Any | None = None, theta: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a squeezing gate.
- s2(wires: List[int], r: Any | None = None, theta: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a two-mode squeezing gate.
- d(wires: int, r: Any | None = None, theta: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a displacement gate.
- x(wires: int, inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a position displacement gate.
- z(wires: int, inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a momentum displacement gate.
- r(wires: int, inputs: Any | None = None, encode: bool = False, inv_mode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a rotation gate.
- f(wires: int, mu: float | None = None, sigma: float | None = None) None #
Add a Fourier gate.
- qp(wires: int, inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a quadratic phase gate.
- cx(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a controlled-X gate.
- cz(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a controlled-Z gate.
- cp(wires: int, inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a cubic phase gate.
- k(wires: int, inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a Kerr gate.
- ck(wires: List[int], inputs: Any | None = None, encode: bool = False, mu: float | None = None, sigma: float | None = None) None #
Add a cross-Kerr gate.
- delay(wires: int, ntau: int = 1, inputs: Any | None = None, convention: str = 'bs', encode: bool = False, loop_gates: List | None = None, mu: float | None = None, sigma: float | None = None) None #
Add a delay loop.
- homodyne(wires: int, phi: Any | None = None, eps: float = 0.0002, mu: float | None = None, sigma: float | None = None) None #
Add a homodyne measurement.
- homodyne_x(wires: int, eps: float = 0.0002, mu: float | None = None, sigma: float | None = None) None #
Add a homodyne measurement for quadrature x.
- homodyne_p(wires: int, eps: float = 0.0002, mu: float | None = None, sigma: float | None = None) None #
Add a homodyne measurement for quadrature p.
- loss(wires: int, inputs: Any | None = None, encode: bool = False) None #
Add a photon loss channel.
The inputs corresponds to theta of the loss channel.
- loss_t(wires: int, inputs: Any | None = None, encode: bool = False) None #
Add a photon loss channel.
The inputs corresponds to the transmittance of the loss channel.
- loss_db(wires: int, inputs: Any | None = None, encode: bool = False) None #
Add a photon loss channel.
The inputs corresponds to the probability of loss with the unit of dB and is positive.
deepquantum.photonic.decompose module#
Decompose the unitary matrix
- class deepquantum.photonic.decompose.UnitaryDecomposer(unitary: ndarray | Tensor, method: str = 'cssr')#
基类:
object
This class is to decompose a unitary matrix into the Clements/Reck architecture.
- 参数:
unitary (np.ndarray or torch.Tensor) – The unitary matrix to be decomposed.
method (str, optional) – The decomposition method, only 16 values (
'rssr'
,'rsdr'
,'rdsr'
,'rddr'
,'rssl'
,'rsdl'
,'rdsl'
,'rddl'
,'cssr'
,'csdr'
,'cdsr'
,'cddr'
,'cssl'
,'csdl'
,'cdsl'
,'cddl'
) are valid. The first char denotes the Clements or Reck architecture. The second char denotes single or double arms of outer phase shifters. The third char denotes single or double arms of inner phase shifters. The last char denotes the position of a column of phase shifters, i.e.,'l'
for left and'r'
for right. Default:'cssr'
- decomp() Tuple[Dict, Dict, Dict] #
Decompose the unitary matrix.The third dictionary is the representation of the positions and the angles of all phase shifters.
- sort_mzi(mzi_info)#
Sort mzi parameters in the same array for plotting.
- ps_pos(dic_mzi, phase_angle)#
Label the position of each phaseshifter for
'cssr'
case.
deepquantum.photonic.draw module#
Draw quantum circuit.
- class deepquantum.photonic.draw.DrawCircuit(circuit_name: str, circuit_nmode: int, circuit_operators: Sequential, measurements: ModuleList, nstep: int | None = None)#
基类:
object
Draw the photonic quantum circuit.
- 参数:
circuit_name (str) – The name of the circuit.
circuit_nmode (int) – The number of modes in the circuit.
circuit_operators (nn.Sequential) – The operators of the circuit.
measurements (nn.ModuleList) – The measurements of the circuit.
nstep (int or None, optional) – The number of time steps for the TDM circuit. Default:
None
- draw()#
Draw circuit
- draw_nstep()#
Draw unroll circuit with given step.
- draw_normal(depth=None, ops=None, measurements=None)#
Draw normal circuit.
- save(filename)#
Save the circuit as svg.
- draw_mode_num()#
- draw_bs(name, order, wires, theta, phi=None)#
Draw beamsplitter.
- draw_ps(order, wires, theta=0, name=None)#
Draw phaseshift (rotation) gate.
- draw_homodyne(order, wire, phi, name=None)#
Draw homodyne measurement.
- draw_sq(order, wires, para_dic, name=None)#
Draw squeezing gate, displacement gate.
- draw_delay(order, wires, inputs=None)#
Draw delay loop.
- draw_loss(order, wires, name, t)#
Draw loss gate.
- draw_any(order, wires, name, para_dict=None)#
Draw arbitrary unitary gate.
- draw_lines(order, wires)#
Act nothing.
- barrier(order)#
- class deepquantum.photonic.draw.DrawClements(nmode: int, mzi_info: Dict, cl: str = 'dodgerblue', fs: int = 30, method: str = 'cssr')#
基类:
object
Draw the n-mode Clements architecture.
- 参数:
nmode (int) – The number of modes of the Clements architecture.
mzi_info (Dict) – The dictionary for mzi parameters, resulting from the decompose function.
cl (str, optional) – The color for plotting. Default:
'dodgerblue'
fs (int, optional) – The fontsize. Default: 30
method (str, optional) – The way for Clements decomposition,
'cssr'
or'cssl'
. Default:'cssr'
- plotting_clements()#
Plot clements structure with
cssr
orcssl
type.
- plotting_clements_1()#
Plot
cssr
with left to right order.
- plotting_clements_2()#
Plot
cssl
with right to left order.
- sort_mzi()#
Sort mzi parameters in the same array for plotting.
- ps_pos()#
Label the position of each phaseshifter for
cssr
case.
- static connect1(coordinate, ax, cl, wid=0.1, height=0.08, a=-0.05, b=-0.05, c=0.7, d=-0.05)#
Connect odd column.
- static connect2(coordinate, cl)#
Connect even column.
- static plot_paras(sort_mzi_dic, nmode, fs=20)#
Plot mzi parameters for
cssl
case.
- static plot_paras_1(sort_mzi_dic, fs=20)#
Plot mzi parameters for
cssr
case.
deepquantum.photonic.gate module#
Photonic quantum gates
- class deepquantum.photonic.gate.SingleGate(name: str | None = None, inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Gate
A base class for single-mode photonic quantum gates.
- 参数:
name (str or None, optional) – The name of the gate. Default:
None
inputs (Any, optional) – The parameters of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- class deepquantum.photonic.gate.DoubleGate(name: str | None = None, inputs: Any | None = None, nmode: int = 2, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Gate
A base class for two-mode photonic quantum gates.
- 参数:
name (str or None, optional) – The name of the gate. Default:
None
inputs (Any, optional) – The parameters of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- class deepquantum.photonic.gate.PhaseShift(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1, inv_mode: bool = False)#
基类:
SingleGate
Phase Shifter.
Matrix Representation:
\[U_{\text{PS}}(\theta) = e^{i\theta}\]Symplectic Transformation:
\[\begin{split}PS^\dagger(\theta) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} PS(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \\ \end{pmatrix} \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
inv_mode (bool, optional) – Whether the rotation in the phase space is clockwise. Default:
False
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- get_matrix(theta: Any) Tensor #
Get the local unitary matrix acting on creation operators.
- update_matrix() Tensor #
Update the local unitary matrix acting on creation operators.
- get_matrix_state(matrix: Tensor) Tensor #
Get the local transformation matrix acting on Fock state tensors.
- get_transform_xp(theta: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.BeamSplitter(inputs: Any | None = None, nmode: int = 2, wires: List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
DoubleGate
Beam Splitter.
See https://arxiv.org/abs/2004.11002 Eq.(42b)
Matrix Representation:
\[\begin{split}U_{\text{BS}}(\theta, \phi) = \begin{pmatrix} \cos\left(\theta\right) & -e^{-i\phi} \sin\left(\theta\right) \\ e^{i\phi} \sin\left(\theta\right) & \cos\left(\theta\right) \\ \end{pmatrix}\end{split}\]Symplectic Transformation:
\[\begin{split}BS^\dagger(\theta, \phi) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} BS(\theta, \phi) = \begin{pmatrix} \mathrm{Re}(U_{\text{BS}}) & -\mathrm{Im}(U_{\text{BS}}) \\ \mathrm{Im}(U_{\text{BS}}) & \mathrm{Re}(U_{\text{BS}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameters of the gate (\(\theta\) and \(\phi\)). Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tuple[Tensor, Tensor] #
Convert inputs to torch.Tensor.
- get_matrix(theta: Any, phi: Any) Tensor #
Get the local unitary matrix acting on creation operators.
- update_matrix() Tensor #
Update the local unitary matrix acting on creation operators.
- get_matrix_state(matrix: Tensor) Tensor #
Get the local transformation matrix acting on Fock state tensors.
See https://arxiv.org/pdf/2004.11002.pdf Eq.(74) and Eq.(75)
- get_transform_xp(theta: Any, phi: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.MZI(inputs: Any | None = None, nmode: int = 2, wires: List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, phi_first: bool = True, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
BeamSplitter
Mach-Zehnder Interferometer.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{MZI}}(\theta, \phi) = ie^{i\theta/2} \begin{pmatrix} e^{i\phi} \sin\left(\th\right) & \cos\left(\th\right) \\ e^{i\phi} \cos\left(\th\right) & -\sin\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]or when
phi_first
isFalse
:\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{MZI}}(\theta, \phi) = ie^{i\theta/2} \begin{pmatrix} e^{i\phi} \sin\left(\th\right) & e^{i\phi} \cos\left(\th\right) \\ \cos\left(\th\right) & -\sin\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]Symplectic Transformation:
\[\begin{split}MZI^\dagger(\theta, \phi) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} MZI(\theta, \phi) = \begin{pmatrix} \mathrm{Re}(U_{\text{MZI}}) & -\mathrm{Im}(U_{\text{MZI}}) \\ \mathrm{Im}(U_{\text{MZI}}) & \mathrm{Re}(U_{\text{MZI}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameters of the gate (\(\theta\) and \(\phi\)). Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
phi_first (bool, optional) – Whether \(\phi\) is the first phase shifter. Default:
True
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- get_matrix(theta: Any, phi: Any) Tensor #
Get the local unitary matrix acting on creation operators.
- class deepquantum.photonic.gate.BeamSplitterTheta(inputs: Any | None = None, nmode: int = 2, wires: List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
BeamSplitter
Beam Splitter with fixed \(\phi\) at \(\pi/2\).
Matrix Representation:
\[\begin{split}U_{\text{BS}}(\theta) = \begin{pmatrix} \cos\left(\theta\right) & i\sin\left(\theta\right) \\ i\sin\left(\theta\right) & \cos\left(\theta\right) \\ \end{pmatrix}\end{split}\]Symplectic Transformation:
\[\begin{split}BS^\dagger(\theta) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} BS(\theta) = \begin{pmatrix} \mathrm{Re}(U_{\text{BS}}) & -\mathrm{Im}(U_{\text{BS}}) \\ \mathrm{Im}(U_{\text{BS}}) & \mathrm{Re}(U_{\text{BS}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.BeamSplitterPhi(inputs: Any | None = None, nmode: int = 2, wires: List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
BeamSplitter
Beam Splitter with fixed \(\theta\) at \(\pi/4\).
Matrix Representation:
\[\begin{split}U_{\text{BS}}(\phi) = \begin{pmatrix} \frac{\sqrt{2}}{2} & -\frac{\sqrt{2}}{2}e^{-i\phi} \\ \frac{\sqrt{2}}{2}e^{i\phi} & \frac{\sqrt{2}}{2} \\ \end{pmatrix}\end{split}\]Symplectic Transformation:
\[\begin{split}BS^\dagger(\phi) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} BS(\phi) = \begin{pmatrix} \mathrm{Re}(U_{\text{BS}}) & -\mathrm{Im}(U_{\text{BS}}) \\ \mathrm{Im}(U_{\text{BS}}) & \mathrm{Re}(U_{\text{BS}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.BeamSplitterSingle(inputs: Any | None = None, nmode: int = 2, wires: List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, convention: str = 'rx', requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
BeamSplitter
Beam Splitter with a single parameter.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{BS-Rx}}(\theta) = \begin{pmatrix} \cos\left(\th\right) & i\sin\left(\th\right) \\ i\sin\left(\th\right) & \cos\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{BS-Ry}}(\theta) = \begin{pmatrix} \cos\left(\th\right) & -\sin\left(\th\right) \\ \sin\left(\th\right) & \cos\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{BS-H}}(\theta) = \begin{pmatrix} \cos\left(\th\right) & \sin\left(\th\right) \\ \sin\left(\th\right) & -\cos\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]Symplectic Transformation:
\[\begin{split}BS^\dagger(\theta) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} BS(\theta) = \begin{pmatrix} \mathrm{Re}(U_{\text{BS}}) & -\mathrm{Im}(U_{\text{BS}}) \\ \mathrm{Im}(U_{\text{BS}}) & \mathrm{Re}(U_{\text{BS}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
convention (str, optional) – The convention of the type of the beam splitter, including
'rx'
,'ry'
and'h'
. Default:'rx'
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- get_matrix(theta: Any) Tensor #
Get the local unitary matrix acting on creation operators.
- update_matrix() Tensor #
Update the local unitary matrix acting on creation operators.
- get_transform_xp(theta: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.UAnyGate(unitary: Any, nmode: int = 1, wires: List[int] | None = None, minmax: List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, name: str = 'UAnyGate')#
基类:
Gate
Arbitrary unitary gate.
- 参数:
unitary (Any) – Any given unitary matrix.
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
minmax (List[int] or None, optional) – The minimum and maximum indices of the modes that the quantum operation acts on. Only valid when
wires
isNone
. Default:None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
name (str, optional) – The name of the gate. Default:
'UAnyGate'
- get_matrix_state(matrix: Tensor) Tensor #
Get the local transformation matrix acting on Fock state tensors.
See https://arxiv.org/pdf/2004.11002.pdf Eq.(71)
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- get_transform_xp(matrix: Tensor) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- class deepquantum.photonic.gate.Squeezing(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
SingleGate
Squeezing gate.
Symplectic Transformation:
\[\begin{split}S^\dagger(r, \theta) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} S(r, \theta) = \begin{pmatrix} \cosh r - \sinh r \cos\theta & -\sinh r \sin\theta \\ -\sinh r \sin\theta & \cosh r + \sinh r \cos\theta \\ \end{pmatrix} \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameters of the gate (\(r\) and \(\theta\)). Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tuple[Tensor, Tensor] #
Convert inputs to torch.Tensor.
- get_matrix(r: Any, theta: Any) Tensor #
Get the local symplectic matrix acting on annihilation and creation operators.
- update_matrix() Tensor #
Update the local symplectic matrix acting on annihilation and creation operators.
- get_matrix_state(r: Any, theta: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
See https://arxiv.org/pdf/2004.11002.pdf Eq.(51) and Eq.(52)
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- get_transform_xp(r: Any, theta: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.Squeezing2(inputs: Any | None = None, nmode: int = 2, wires: List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
DoubleGate
Two-mode Squeezing gate.
Symplectic Transformation:
\[\begin{split}S_2^\dagger(r, \theta) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} S_2(r, \theta) = \begin{pmatrix} \cosh r & \cos\theta\sinh r & 0 & \sin\theta\sinh r \\ \cos\theta\sinh r & \cosh r & \sin\theta\sinh r & 0 \\ 0 & \sin\theta\sinh r & \cosh r & -\cos\theta\sinh r \\ \sin\theta\sinh r & 0 & -\cos\theta\sinh r & \cosh r \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameters of the gate (\(r\) and \(\theta\)). Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tuple[Tensor, Tensor] #
Convert inputs to torch.Tensor.
- get_matrix(r: Any, theta: Any) Tensor #
Get the local symplectic matrix acting on annihilation and creation operators.
- update_matrix() Tensor #
Update the local symplectic matrix acting on annihilation and creation operators.
- get_matrix_state(r: Any, theta: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
See https://arxiv.org/pdf/2004.11002.pdf Eq.(64-67)
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- get_transform_xp(r: Any, theta: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.Displacement(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
SingleGate
Displacement gate.
Symplectic Transformation:
\[\begin{split}D^\dagger(r, \theta) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} D(r, \theta) = \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} + \frac{\sqrt{\hbar}}{\kappa} \begin{pmatrix} r\cos\theta \\ r\sin\theta \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameters of the gate (\(r\) and \(\theta\)). Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tuple[Tensor, Tensor] #
Convert inputs to torch.Tensor.
- get_matrix(r: Any, theta: Any) Tensor #
Get the local symplectic unitary matrix acting on annihilation and creation operators.
- update_matrix() Tensor #
Update the local symplectic unitary matrix acting on annihilation and creation operators.
- get_matrix_state(r: Any, theta: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
See https://arxiv.org/pdf/2004.11002.pdf Eq.(57) and Eq.(58)
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- get_transform_xp(r: Any, theta: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.DisplacementPosition(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Displacement
Position Displacement gate.
Symplectic Transformation:
\[\begin{split}X^\dagger(x) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} X(x) = \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} + \begin{pmatrix} x \\ 0 \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.DisplacementMomentum(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Displacement
Momentum Displacement gate.
Symplectic Transformation:
\[\begin{split}Z^\dagger(p) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} Z(p) = \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} + \begin{pmatrix} 0 \\ p \\ \end{pmatrix}\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.QuadraticPhase(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
SingleGate
Quadratic phase gate.
Operator Representation:
\[QP(s) = e^{i \frac{s}{2 \hbar} \hat{x}^2}\]Symplectic Transformation:
\[\begin{split}QP^\dagger(s) \begin{pmatrix} \hat{a} \\ \hat{a}^\dagger \\ \end{pmatrix} QP(s) = \begin{pmatrix} 1 + i \frac{s}{2} & i \frac{s}{2} \\ -i \frac{s}{2} & 1 - i \frac{s}{2} \\ \end{pmatrix} \begin{pmatrix} \hat{a} \\ \hat{a}^\dagger \\ \end{pmatrix}\end{split}\]\[\begin{split}QP^\dagger(s) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} QP(s) = \begin{pmatrix} 1 & 0 \\ s & 1 \\ \end{pmatrix} \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix}\end{split}\]Decomposition Representation:
\[QP(s) = PS(\theta) S(r e^{i \phi})\]where \(\cosh(r) = \sqrt{1 + (\frac{s}{2})^2}, \quad \tan(\theta) = \frac{s}{2}, \quad \phi = -\sign(s)\frac{\pi}{2} - \theta\).
- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- get_matrix(s: Any) Tensor #
Get the local symplectic matrix acting on annihilation and creation operators.
- update_matrix() Tensor #
Update the local symplectic matrix acting on annihilation and creation operators.
- get_matrix_state(s: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- get_transform_xp(s: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.ControlledX(inputs: Any | None = None, nmode: int = 2, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
DoubleGate
Controlled-X gate.
Operator Representation:
\[CX(s) = e^{-i \frac{s}{\hbar} \hat{x}_1 \hat{p}_2}\]Symplectic Transformation:
\[\begin{split}CX^\dagger(s) \begin{pmatrix} \hat{a}_1 \\ \hat{a}_2 \\ \hat{a}_1^\dagger \\ \hat{a}_2^\dagger \\ \end{pmatrix} CX(s) = \begin{pmatrix} 1 & -\frac{s}{2} & 0 & \frac{s}{2} \\ \frac{s}{2} & 1 & \frac{s}{2} & 0 \\ 0 & \frac{s}{2} & 1 & -\frac{s}{2} \\ \frac{s}{2} & 0 & \frac{s}{2} & 1 \\ \end{pmatrix} \begin{pmatrix} \hat{a}_1 \\ \hat{a}_2 \\ \hat{a}_1^\dagger \\ \hat{a}_2^\dagger \\ \end{pmatrix}\end{split}\]\[\begin{split}CX^\dagger(s) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} CX(s) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ s & 1 & 0 & 0 \\ 0 & 0 & 1 & -s \\ 0 & 0 & 0 & 1 \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]Decomposition Representation:
\[CX(s) = BS(\frac{\pi}{2} + \theta, 0) \left(S(r, 0) \otimes S(-r, 0)\right) BS(\theta, 0)\]where \(\sin(2 \theta) = -\frac{1}{\cosh r}, \quad \cos(2 \theta) = -\tanh r, \quad \sinh(r) = -\frac{s}{2}\).
- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- get_matrix(s: Any) Tensor #
Get the local symplectic matrix acting on annihilation and creation operators.
- update_matrix() Tensor #
Update the local symplectic matrix acting on annihilation and creation operators.
- get_matrix_state(s: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- get_transform_xp(s: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.ControlledZ(inputs: Any | None = None, nmode: int = 2, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
DoubleGate
Controlled-Z gate.
Operator Representation:
\[CZ(s) = e^{-i \frac{s}{\hbar} \hat{x}_1 \hat{x}_2}\]Symplectic Transformation:
\[\begin{split}CZ^\dagger(s) \begin{pmatrix} \hat{a}_1 \\ \hat{a}_2 \\ \hat{a}_1^\dagger \\ \hat{a}_2^\dagger \\ \end{pmatrix} CZ(s) = \begin{pmatrix} 1 & i \frac{s}{2} & 0 & i \frac{s}{2} \\ i \frac{s}{2} & 1 & i \frac{s}{2} & 0 \\ 0 & -i \frac{s}{2} & 1 & -i \frac{s}{2} \\ -i \frac{s}{2} & 0 & -i \frac{s}{2} & 1 \\ \end{pmatrix} \begin{pmatrix} \hat{a}_1 \\ \hat{a}_2 \\ \hat{a}_1^\dagger \\ \hat{a}_2^\dagger \\ \end{pmatrix}\end{split}\]\[\begin{split}CZ^\dagger(s) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} CZ(s) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & s & 1 & 0 \\ s & 0 & 0 & 1 \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]Decomposition Representation:
\[CZ(s) = PS_2(\pi/2) CX(s) PS_2^\dagger(\pi/2)\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- get_matrix(s: Any) Tensor #
Get the local symplectic matrix acting on annihilation and creation operators.
- update_matrix() Tensor #
Update the local symplectic matrix acting on annihilation and creation operators.
- get_matrix_state(s: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- get_transform_xp(s: Any) Tuple[Tensor, Tensor] #
Get the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in
xxpp
order.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.CubicPhase(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
SingleGate
Cubic phase gate.
Operator Representation:
\[CP(\gamma) = e^{i \frac{\gamma}{3 \hbar} \hat{x}^3}\]Operator Transformation:
\[CP^\dagger(\gamma) \hat{a} CP(\gamma) = \hat{a} + i\frac{\gamma(\hat{a} + \hat{a}^\dagger)^2}{2\sqrt{2/\hbar}}\]\[\begin{split}CP^\dagger(\gamma) \hat{x} CP(\gamma) &= \hat{x}, \\ CP^\dagger(\gamma) \hat{p} CP(\gamma) &= \hat{p} + \gamma\hat{x}^2.\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- get_matrix_state(gamma: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.Kerr(inputs: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
SingleGate
Kerr gate.
Operator Representation:
\[K(\kappa) = e^{i \kappa \hat{n}^2}\]Operator Transformation:
\[\begin{split}K^\dagger(\kappa) \hat{a} K(\kappa) &= e^{i \kappa (2 \hat{a}^\dagger \hat{a} + 1)} \hat{a} = \hat{a} e^{i \kappa (2 \hat{a}^\dagger \hat{a} - 1)}, \\ K^\dagger(\kappa) \hat{a}^\dagger K(\kappa) &= \hat{a}^\dagger e^{-i \kappa (2 \hat{a}^\dagger \hat{a} + 1)} = e^{i \kappa (2 \hat{a}^\dagger \hat{a} + 1)} \hat{a}^\dagger.\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- get_matrix_state(kappa: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.CrossKerr(inputs: Any | None = None, nmode: int = 2, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
DoubleGate
Cross-Kerr gate.
Operator Representation:
\[CK(\kappa) = e^{i \kappa \hat{n}_1 \hat{n}_2}\]Operator Transformation:
\[\begin{split}CK^\dagger(\kappa) \hat{a}_1 CK(\kappa) &= e^{i \kappa \hat{n}_2} \hat{a}_1 = \hat{a}_1 e^{i \kappa \hat{n}_2}, \\ CK^\dagger(\kappa) \hat{a}_2 CK(\kappa) &= e^{i \kappa \hat{n}_1} \hat{a}_2 = \hat{a}_2 e^{i \kappa \hat{n}_1}, \\ CK^\dagger(\kappa) \hat{a}_1^\dagger CK(\kappa) &= e^{-i \kappa \hat{n}_2} \hat{a}_1^\dagger = \hat{a}_1^\dagger e^{-i \kappa \hat{n}_2}, \\ CK^\dagger(\kappa) \hat{a}_2^\dagger CK(\kappa) &= e^{-i \kappa \hat{n}_1} \hat{a}_2^\dagger = \hat{a}_2^\dagger e^{-i \kappa \hat{n}_1}.\end{split}\]- 参数:
inputs (Any, optional) – The parameter of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 2
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- get_matrix_state(kappa: Any) Tensor #
Get the local transformation matrix acting on Fock state tensors.
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- class deepquantum.photonic.gate.DelayBS(inputs: Any | None = None, ntau: int = 1, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, loop_gates: List | None = None, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Delay
Delay loop with
BeamSplitterTheta
andPhaseShift
.- 参数:
inputs (Any, optional) – The parameters of the gate. Default:
None
ntau (int, optional) – The number of modes in the delay loop. Default: 1
nmode (int, optional) – The number of spatial modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- property theta#
- property phi#
- class deepquantum.photonic.gate.DelayMZI(inputs: Any | None = None, ntau: int = 1, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, loop_gates: List | None = None, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Delay
Delay loop with MZI.
- 参数:
inputs (Any, optional) – The parameters of the gate. Default:
None
ntau (int, optional) – The number of modes in the delay loop. Default: 1
nmode (int, optional) – The number of spatial modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
requires_grad (bool, optional) – Whether the parameters are
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- property theta#
- property phi#
deepquantum.photonic.hafnian_ module#
functions for hafnian
- deepquantum.photonic.hafnian_.integer_partition(remaining: int, max_num: int) List #
Generate all unique integer partitions of m using integers up to n.
- deepquantum.photonic.hafnian_.count_unique_permutations(nums: List | array) float64 #
Count the number of unique permutations of a list of numbers.
- deepquantum.photonic.hafnian_.get_submat_haf(a: Tensor, z: Tensor) Tensor #
Get the sub-matrix for hafnian calculation.
See https://arxiv.org/abs/1805.12498 paragraph after Eq.(3.20)
- deepquantum.photonic.hafnian_.poly_lambda(submat: Tensor, int_partition: List, power: int, loop: bool = False) Tensor #
Get the coefficient of the polynomial.
- deepquantum.photonic.hafnian_.hafnian(matrix: Tensor, loop: bool = False) Tensor #
Calculate the hafnian for symmetric matrix, using the eigenvalue-trace method.
See https://arxiv.org/abs/2108.01622 Eq.(B3)
- deepquantum.photonic.hafnian_.hafnian_batch(matrix: Tensor, loop: bool = False) Tensor #
Calculate the batch hafnian.
deepquantum.photonic.mapper module#
Map the quantum gate to photonic quantum circuit
- class deepquantum.photonic.mapper.UnitaryMapper(nqubit: int, nmode: int, ugate: Any, success: float, aux: List | None = None, aux_pos: List | None = None)#
基类:
object
Map the quantum gate to the unitary matrix of the photonic quantum circuit based on dual-rail encoding.
- 参数:
nqubit (int) – The number of qubits of the quantum gates.
nmode (int) – The number of modes in the circuit.
ugate (Any) – The target quantum gate.
success (float) – The square root of the probability of the target quantum gate. The preferred value is 1/3 for 2 qubits or 1/4 for 3 qubits.
aux (List or None, optional) – Two auxiliary modes in the circuit, which could be
[0,0]
or[1,0]
. Default:None
aux_pos (List or None, optional) – The positions of the auxiliary modes. Default:
None
(which means the last two modes).
- create_basis(aux_position)#
Create the nqubit bases in dual-rail encoding.
- get_coeff_sym(input_state: Tensor, output_states: List | None = None)#
Return the transfer state coefficient in a symbolic way.
- get_indx_coeff(coeff_i, all_inputs=None)#
Get the index of y_var for given state transfer coefficients.
- indx_eqs()#
Get the dictinonary of indices of y_mat for each nonlinear equations for n modes.
- static single_prod(single_idx_i, y_test)#
- static single_output(single_idx, y_test)#
- get_transfer_mat(y)#
- f_real(y)#
Construct \(2^{nqubit}*2^{nqubit}\) equations for \(n*n\) matrix y, obtain real solutions for real part of u_gate.
- 参数:
y – an array with \(n^2\) element
- f_real_unitary(y)#
Return the quantum gate constrains and the unitary constrains.
- static unitary_constrains(u_temp: Tensor)#
Return \(n^2\) equations for \(n*n\) matrix with unitary condition.
- f_complex_unitary(paras)#
Return quantum gate constrains and the unitary constrains.
- f_complex(y)#
Construct \(2^{nqubit}*2^{nqubit}\) equations for \(n*n\) matrix y, obtain complex solutions.
- 参数:
y – an array with \(2*n^2\) element
- static unitary_constrains_complex(u_temp: Tensor)#
Return \(2*n^2\) equations for \(n*n\) complex matrix with unitary condition.
- solve_eqs_real(total_trials=10, trials=1000, precision=1e-06)#
Solve the non-linear eqautions for matrix satisfying ugate with real solution.
- solve_eqs_complex(total_trials=10, trials=1000, precision=1e-05)#
Solve the non-linear eqautions for matrix satisfying ugate with complex solution.
- static exchange(matrix, aux1_pos)#
- static sub_matrix_sym(unitary, input_state, output_state)#
Get the sub_matrix of transfer probs for given input and output state.
- static set_copy_indx(state)#
Pick up indices from the nonezero elements of state, repeat times depend on the nonezero value.
- static permanent(mat)#
Use Ryser formula for permanent, only valid for square matrix.
- static product_factorial(state)#
Get the product of the factorial from the state, i.e., \(|s_1,s_2,...s_n> --> s_1!*s_2!*...s_n!\).
- static create_subset(num_coincidence)#
Get all subset from \(\{1,2,...n\}\).
- static save_dict(dictionary, file_path)#
- static plot_u(unitary, vmax=1, vmin=0, fs=20, len_ticks=5, cl='RdBu')#
Plot the matrix in graphic way.
- 参数:
unitary – the plotting matrix
vmax – max value of the unitary matrix
vmin – min value of the unitary matrix
fs – fontsize
len_ticks – number of ticks in colorbar
cl – color of plotting
- static is_unitary(u_temp)#
Check the matrix is unitary or not.
- state_basis()#
Map ‘000’ to dual_rail.
deepquantum.photonic.measurement module#
Photonic measurements
- class deepquantum.photonic.measurement.Generaldyne(cov_m: Any, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, name: str = 'Generaldyne', noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Operation
General-dyne measurement.
- 参数:
cov_m (Any) – The covariance matrix for the general-dyne measurement.
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
name (str, optional) – The name of the measurement. Default: ``’Generaldyne’`
noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- forward(x: List[Tensor]) List[Tensor] #
Perform a forward pass for Gaussian states.
See Quantum Continuous Variables: A Primer of Theoretical Methods (2024) by Alessio Serafini Eq.(5.143) and Eq.(5.144) in page 121
For Bosonic state, see https://arxiv.org/abs/2103.05530 Eq.(35-37)
- class deepquantum.photonic.measurement.Homodyne(phi: Any | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, eps: float = 0.0002, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1, name: str = 'Homodyne')#
基类:
Generaldyne
Homodyne measurement.
- 参数:
phi (Any, optional) – The homodyne measurement angle. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
eps (float, optional) – The measurement accuracy. Default: 2e-4
requires_grad (bool, optional) – Whether the parameter is
nn.Parameter
orbuffer
. Default:False
(which meansbuffer
)name (str, optional) – The name of the gate. Default:
'Homodyne'
noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- inputs_to_tensor(inputs: Any | None = None) Tensor #
Convert inputs to torch.Tensor.
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- op_fock(x: Tensor) Tensor #
Perform a forward pass for Fock state tensors.
- op_cv(x: List[Tensor]) List[Tensor] #
Perform a forward pass for Gaussian (Bosonic) states.
- forward(x: Tensor | List[Tensor]) Tensor | List[Tensor] #
Perform a forward pass.
deepquantum.photonic.operation module#
Base classes
- class deepquantum.photonic.operation.Operation(name: str | None = None, nmode: int = 1, wires: int | List | None = None, cutoff: int = 2, den_mat: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Module
A base class for quantum operations.
- 参数:
name (str or None, optional) – The name of the quantum operation. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int, optional) – The Fock space truncation. Default: 2
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- tensor_rep(x: Tensor) Tensor #
Get the tensor representation of the state.
- init_para() None #
Initialize the parameters.
- forward(x: Tensor) Tensor #
Perform a forward pass.
- class deepquantum.photonic.operation.Gate(name: str | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Operation
A base class for photonic quantum gates.
- 参数:
name (str or None, optional) – The name of the gate. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- update_matrix() Tensor #
Update the local unitary matrix acting on creation operators.
- get_unitary() Tensor #
Get the global unitary matrix acting on creation operators.
- get_matrix_state(matrix: Tensor) Tensor #
Get the local transformation matrix acting on Fock state tensors.
- update_matrix_state() Tensor #
Update the local transformation matrix acting on Fock state tensors.
- op_state_tensor(x: Tensor) Tensor #
Perform a forward pass for state tensors.
- op_den_mat(x: Tensor) Tensor #
Perform a forward pass for density matrices.
- update_transform_xp() Tuple[Tensor, Tensor] #
Update the local affine symplectic transformation acting on quadrature operators in xxpp order.
- get_symplectic() Tensor #
Get the global symplectic matrix acting on quadrature operators in xxpp order.
- get_displacement() Tensor #
Get the global displacement vector acting on quadrature operators in xxpp order.
- op_cv(x: List[Tensor]) List[Tensor] #
Perform a forward pass for Gaussian (Bosonic) states.
- get_mpo() Tuple[List[Tensor], int] #
Convert gate to MPO form with identities at empty sites.
备注
If sites are not adjacent, insert identities in the middle, i.e.,
>>> | | | | | >>> --A---x---B-- -> --A---I---B-- >>> | | | | |
where
>>> a >>> | >>> --i--I--j-- >>> | >>> b
means \(\delta_{i,j} \delta_{a,b}\)
- op_mps(mps: MatrixProductState) MatrixProductState #
Perform a forward pass for the
MatrixProductState
.
- forward(x: Tensor | List[Tensor] | MatrixProductState) Tensor | List[Tensor] | MatrixProductState #
Perform a forward pass.
- class deepquantum.photonic.operation.Channel(name: str | None = None, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None)#
基类:
Operation
A base class for photonic quantum channels.
- 参数:
name (str or None, optional) – The name of the channel. Default:
None
nmode (int, optional) – The number of modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
- update_matrix_state() Tensor #
Update the local Kraus matrices acting on Fock state density matrices.
- op_den_mat(x: Tensor) Tensor #
Perform a forward pass for density matrices.
- update_transform_xy() Tuple[Tensor, Tensor] #
Update the local transformation matrices X and Y acting on Gaussian states.
- op_cv(x: List[Tensor]) List[Tensor] #
Perform a forward pass for Gaussian (Bosonic) states.
See Quantum Continuous Variables: A Primer of Theoretical Methods (2024) by Alessio Serafini Eq.(5.35-5.37) in page 90
- forward(x: Tensor | List[Tensor]) Tensor | List[Tensor] #
Perform a forward pass.
- class deepquantum.photonic.operation.Delay(name='Delay', ntau: int = 1, nmode: int = 1, wires: int | List[int] | None = None, cutoff: int | None = None, den_mat: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
基类:
Operation
Delay loop.
- 参数:
name (str or None, optional) – The name of the quantum operation. Default:
'Delay'
ntau (int, optional) – The number of modes in the delay loop. Default: 1
nmode (int, optional) – The number of spatial modes that the quantum operation acts on. Default: 1
wires (int, List[int] or None, optional) – The indices of the modes that the quantum operation acts on. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
den_mat (bool, optional) – Whether to use density matrix representation. Default:
False
noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- init_para(inputs: Any | None = None) None #
Initialize the parameters.
- forward(x: Tensor | List[Tensor] | MatrixProductState) Tensor | List[Tensor] | MatrixProductState #
Perform a forward pass.
deepquantum.photonic.qmath module#
Common functions
- deepquantum.photonic.qmath.dirac_ket(matrix: Tensor) Dict #
Convert the batched Fock state tensor to the dictionary of Dirac ket.
- deepquantum.photonic.qmath.sort_dict_fock_basis(state_dict: Dict, idx: int = 0) Dict #
Sort the dictionary of Fock basis states in the descending order of probs.
- deepquantum.photonic.qmath.sub_matrix(u: Tensor, input_state: Tensor, output_state: Tensor) Tensor #
Get the submatrix for calculating the transfer amplitude and transfer probs from the given matrix, the input state and the output state. The rows are chosen according to the output state and the columns are chosen according to the input state.
- 参数:
u (torch.Tensor) – The unitary matrix.
input_state (torch.Tensor) – The input state.
output_state (torch.Tensor) – The output state.
- deepquantum.photonic.qmath.permanent(mat: Tensor) Tensor #
Calculate the permanent.
- deepquantum.photonic.qmath.create_subset(num_coincidence: int) Generator[Tensor, None, None] #
Create all subsets from \(\{1,2,...,n\}\).
- deepquantum.photonic.qmath.get_powerset(n: int) List #
Get the powerset of \(\{0,1,...,n-1\}\).
- deepquantum.photonic.qmath.permanent_ryser(mat: Tensor) Tensor #
Calculate the permanent by Ryser’s formula.
- deepquantum.photonic.qmath.product_factorial(state: Tensor) Tensor #
Get the product of the factorial from the Fock state, i.e., \(|s_1,s_2,...s_n> -> s_1!s_2!...s_n!\).
- deepquantum.photonic.qmath.fock_combinations(nmode: int, nphoton: int, cutoff: int | None = None, nancilla: int = 0) List #
Generate all possible combinations of Fock states for a given number of modes, photons, and cutoff.
- 参数:
nmode (int) – The number of modes in the system.
nphoton (int) – The total number of photons in the system.
cutoff (int or None, optional) – The Fock space truncation. Default:
None
nancilla (int, optional) – The number of ancilla modes (NOT limited by
cutoff
). Default:0
- 返回:
A list of all possible Fock states, each represented by a list of occupation numbers for each mode.
- 返回类型:
List[List[int]]
示例
>>> fock_combinations(2, 3) [[0, 3], [1, 2], [2, 1], [3, 0]] >>> fock_combinations(3, 2) [[0, 0, 2], [0, 1, 1], [0, 2, 0], [1, 0, 1], [1, 1, 0], [2, 0, 0]] >>> fock_combinations(4, 4, 2) [[1, 1, 1, 1]]
- deepquantum.photonic.qmath.ladder_ops(cutoff: int, dtype=torch.complex64, device='cpu') Tuple[Tensor, Tensor] #
Get the matrix representation of the annihilation and creation operators.
- deepquantum.photonic.qmath.shift_func(l: List, nstep: int) List #
Shift a list by a number of steps.
If
nstep
is positive, it shifts to the left.
- deepquantum.photonic.qmath.xxpp_to_xpxp(matrix: Tensor) Tensor #
Transform the representation in
xxpp
ordering to the representation inxpxp
ordering.
- deepquantum.photonic.qmath.xpxp_to_xxpp(matrix: Tensor) Tensor #
Transform the representation in
xpxp
ordering to the representation inxxpp
ordering.
- deepquantum.photonic.qmath.quadrature_to_ladder(tensor: Tensor, symplectic: bool = False) Tensor #
Transform the representation in
xxpp
ordering to the representation inaaa^+a^+
ordering.- 参数:
tensor (torch.Tensor) – The input tensor in
xxpp
ordering.symplectic (bool, optional) – Whether the transformation is applied for symplectic matrix or Gaussian state. Default:
False
(which means covariance matrix or displacement vector)
- deepquantum.photonic.qmath.ladder_to_quadrature(tensor: Tensor, symplectic: bool = False) Tensor #
Transform the representation in
aaa^+a^+
ordering to the representation inxxpp
ordering.- 参数:
tensor (torch.Tensor) – The input tensor in
aaa^+a^+
ordering.symplectic (bool, optional) – Whether the transformation is applied for symplectic matrix or Gaussian state. Default:
False
(which means covariance matrix or displacement vector)
- deepquantum.photonic.qmath.photon_number_mean_var(cov: Tensor, mean: Tensor, weight: Tensor | None = None) Tuple[Tensor, Tensor] #
Get the expectation value and variance of the photon number for single-mode Gaussian (Bosonic) states.
- deepquantum.photonic.qmath.takagi(a: Tensor) Tuple[Tensor, Tensor] #
Tagaki decomposition for symmetric complex matrix.
- deepquantum.photonic.qmath.sample_homodyne_fock(state: Tensor, wire: int, nmode: int, cutoff: int, shots: int = 1, den_mat: bool = False) Tensor #
Get the samples of homodyne measurement for batched Fock state tensors on one mode.
- deepquantum.photonic.qmath.sample_reject_bosonic(cov: Tensor, mean: Tensor, weight: Tensor, cov_m: Tensor, shots: int) Tensor #
Get the samples of the Bosonic states via rejection sampling.
See https://arxiv.org/abs/2103.05530 Algorithm 1 in Section VI B
- deepquantum.photonic.qmath.align_shape(cov: Tensor, mean: Tensor, weight: Tensor) List[Tensor] #
Align the shape for Bosonic state.
deepquantum.photonic.state module#
Quantum states
- class deepquantum.photonic.state.FockState(state: Any, nmode: int | None = None, cutoff: int | None = None, basis: bool = True, den_mat: bool = False)#
基类:
Module
A Fock state of n modes, including Fock basis states and Fock state tensors.
- 参数:
state (Any) – The Fock state. It can be a vacuum state with
'vac'
or'zeros'
. It can be a Fock basis state, e.g.,[1,0,0]
, or a Fock state tensor, e.g.,[(1/2**0.5, [1,0]), (1/2**0.5, [0,1])]
. Alternatively, it can be a tensor representation.nmode (int or None, optional) – The number of modes in the state. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
basis (bool, optional) – Whether the state is a Fock basis state or not. Default:
True
den_mat (bool, optional) – Whether to use density matrix representation. Only valid for Fock state tensor. Default:
False
- class deepquantum.photonic.state.GaussianState(state: str | List = 'vac', nmode: int | None = None, cutoff: int | None = None)#
基类:
Module
A Gaussian state of n modes, representing by covariance matrix and displacement vector.
- 参数:
state (str or List) – The Gaussian state. It can be a vacuum state with
'vac'
, or arbitrary Gaussian state with[cov, mean]
.cov
andmean
are the covariance matrix and the displacement vector of the Gaussian state, respectively. Usexxpp
convention and \(\hbar=2\) by default. Default:'vac'
nmode (int or None, optional) – The number of modes in the state. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
- check_purity(rtol=1e-05, atol=1e-08)#
Check if the Gaussian state is pure state
See https://arxiv.org/pdf/quant-ph/0503237.pdf Eq.(2.5)
- class deepquantum.photonic.state.BosonicState(state: str | List = 'vac', nmode: int | None = None, cutoff: int | None = None)#
基类:
Module
A Bosoncic state of n modes, representing by a linear combination of Gaussian states.
- 参数:
state (str or List) – The Bosoncic state. It can be a vacuum state with
'vac'
, or arbitrary linear combinations of Gaussian states with[cov, mean, weight]
.cov
,``mean`` andweight
are the covariance matrices, the displacement vectors and the weights of the Gaussian states, respectively. Usexxpp
convention and \(\hbar=2\) by default. Default:'vac'
nmode (int or None, optional) – The number of modes in the state. Default:
None
cutoff (int or None, optional) – The Fock space truncation. Default:
None
- to(arg: Any) BosonicState #
Set dtype or device of the
BosonicState
.
- tensor_product(state: BosonicState) BosonicState #
Get the tensor product of two Bosonic states.
- wigner(wire: int, qvec: Tensor, pvec: Tensor, plot: bool = False, k: int = 0)#
Get the discretized Wigner function of the specified mode.
- 参数:
wire (int) – The wigner function for given wire.
qvec (torch.Tensor) – The discrete values for quadrature q.
pvec (torch.Tensor) – The discrete values for quadrature p.
plot (bool, optional) – Whether to plot the wigner function. Default:
False
k (int, optional) – The wigner function of kth batch to plot. Default: 0
- marginal(wire: int, qvec: Tensor, phi: float = 0.0, plot: bool = False, k: int = 0)#
Get the discretized marginal distribution of the specified mode along \(x\cos\phi + p\sin\phi\).
- 参数:
wire (int) – The marginal function for given wire.
qvec (torch.Tensor) – The discrete values for quadrature q.
phi (float) – The angle used to compute the linear combination of quadratures.
plot (bool, optional) – Whether to plot the marginal function. Default:
False
k (int, optional) – The marginal function of kth batch to plot. Default: 0
- class deepquantum.photonic.state.CatState(r: Tensor | None = None, theta: Tensor | None = None, p: int = 1, cutoff: int = 5)#
基类:
BosonicState
Single-mode cat state.
The cat state is a superposition of coherent states.
See https://arxiv.org/abs/2103.05530 Section IV B.
- 参数:
r (float) – Displacement magnitude \(|r|\)
theta (float) – Displacement angle \(\theta\)
p (int) – Parity, where \(\theta=p\pi\).
p=0
corresponds to an even cat state, andp=1
an odd cat state.cutoff (int, optional) – The Fock space truncation. Default: 5
- class deepquantum.photonic.state.GKPState(theta: Tensor | None = None, phi: Tensor | None = None, amp_cutoff: float = 0.1, epsilon: float = 0.05, cutoff: int = 5)#
基类:
BosonicState
Finite-energy single-mode GKP state.
Using GKP states to encode qubits, with the qubit state defined by: \(\ket{\psi}_{gkp} = \cos\frac{\theta}{2}\ket{0}_{gkp} + e^{-i\phi}\sin\frac{\theta}{2}\ket{1}_{gkp}\)
See https://arxiv.org/abs/2103.05530 Section IV A.
- 参数:
theta (float) – angle \(\theta\) in Bloch sphere
phi (float) – angle \(\phi\) in Bloch sphere
amp_cutoff (float) – amplitude threshold for keeping the terms. Default: 0.5
epsilon (float) – finite energy damping parameter. Default: 0.1
cutoff (int, optional) – the Fock space truncation. Default: 5
- deepquantum.photonic.state.combine_tensors(tensors: List[Tensor], ndim_ds: int = 2) Tensor #
Combine a list of 3D tensors for Bosonic states according to the dimension of direct sum.
- 参数:
tensors (List[torch.Tensor]) – The list of 3D tensors to combine.
ndim_ds (int, optional) – The dimension of direct sum. Use 1 for direct sum along rows, or use 2 for direct sum along both rows and columns. Default: 2
- deepquantum.photonic.state.combine_bosonic_states(states: List[BosonicState], cutoff: int | None = None) BosonicState #
Combine multiple Bosonic states into a single state.
- 参数:
states (List[BosonicState]) – List of Bosonic states to combine.
cutoff (int or None, optional) – The Fock space truncation. If
None
, the cutoff of the first state is used. Default:None
deepquantum.photonic.tdm module#
Time domain multiplexing
- class deepquantum.photonic.tdm.QumodeCircuitTDM(nmode: int, init_state: Any, cutoff: int | None = None, backend: str = 'gaussian', name: str | None = None, noise: bool = False, mu: float = 0, sigma: float = 0.1)#
-
Time-domain-multiplexed photonic quantum circuit.
备注
When using large squeezing parameters, we recommend using a double data type and a smaller
eps
for Homodyne to avoid issues with non-positive definiteness of the covariance matrix.- 参数:
nmode (int) – The number of spatial modes in the circuit.
init_state (Any) – The initial state of the circuit. It can be a vacuum state with
'vac'
. For Gaussian backend, it can be arbitrary Gaussian states with[cov, mean]
. Usexxpp
convention and \(\hbar=2\) by default.cutoff (int or None, optional) – The Fock space truncation. Default:
None
backend (str, optional) – Use
'gaussian'
for Gaussian backend or'bosonic'
for Bosonic backend. Default:'gaussian'
name (str or None, optional) – The name of the circuit. Default:
None
noise (bool, optional) – Whether to introduce Gaussian noise. Default:
False
mu (float, optional) – The mean of Gaussian noise. Default: 0
sigma (float, optional) – The standard deviation of Gaussian noise. Default: 0.1
- forward(data: Tensor | None = None, state: Any | None = None, nstep: int | None = None) List[Tensor] #
Perform a forward pass of the TDM photonic quantum circuit and return the final state.
- 参数:
data (torch.Tensor or None, optional) – The input data for the
encoders
with the shape of \((\text{batch}, \text{ntimes}, \text{nfeat})\). Default:None
state (Any, optional) – The initial state for the photonic quantum circuit. Default:
None
nstep (int or None, optional) – The number of the evolved time steps. Default:
None
- 返回:
The covariance matrix and displacement vector of the measured final state.
- 返回类型:
List[torch.Tensor]
- get_samples(wires: int | List[int] | None = None) Tensor #
Get the measured samples according to the given
wires
.
deepquantum.photonic.torontonian_ module#
functions for torontonian
- deepquantum.photonic.torontonian_.get_submat_tor(a: Tensor, z: Tensor) Tensor #
Get the sub-matrix for torontonian calculation.
- deepquantum.photonic.torontonian_.torontonian(o_mat: Tensor, gamma: Tensor | None = None) Tensor #
Calculate the torontonian function for the given matrix.
See https://research-information.bris.ac.uk/ws/portalfiles/portal/329011096/thesis.pdf Eq.(3.54)
- deepquantum.photonic.torontonian_.torontonian_batch(o_mat: Tensor, gamma: Tensor | None = None) Tensor #
Calculate the batch torontonian.
deepquantum.photonic.utils module#
Utilities
- deepquantum.photonic.utils.set_hbar(hbar: float) None #
Set the global reduced Planck constant.
- deepquantum.photonic.utils.set_kappa(kappa: float) None #
Set the global kappa.
- deepquantum.photonic.utils.load_sample(filename)#
load the sample data with the given filename
- deepquantum.photonic.utils.save_sample(filename, data)#
save the sample data with the given filename
- deepquantum.photonic.utils.load_adj(filename)#
load the adjacent matrix with the given filename
- deepquantum.photonic.utils.save_adj(filename, data)#
save the adjacent matrix with the given filename
- deepquantum.photonic.utils.mem_to_chunksize(device: device, dtype: dtype) int | None #
Return the chunk size of vmap according to device free memory and dtype.
Note: Currently only optimized for permanent and complex dtype.
- deepquantum.photonic.utils.set_perm_chunksize(device: device, dtype: dtype, chunksize: int | None) None #
Set the global chunk size for permanent calculations.
Module contents#
Photonic Module