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)#

基类:QumodeCircuit

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)#

基类:QumodeCircuit

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)#

基类:GaussianBosonSampling

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.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, 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]. Use xxpp 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 or 'gaussian' for Gaussian backend. Default: 'fock'

  • basis (bool, optional) – Whether to use the representation of Fock basis state for the initial state. Default: True

  • 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

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, set None 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]]

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: FockState | None = None) Tensor#

Get the transfer amplitude between the final state and the initial state.

参数:
  • final_state (Any) – The final Fock basis state.

  • init_state (FockState or None, optional) – The initial Fock basis state. Default: None

get_prob(final_state: Any, refer_state: FockState | GaussianState | 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 (FockState or GaussianState or None, optional) – The initial Fock basis state or the final Gaussian state. 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. Only valid for Fock backend. 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 = 1024, wires: int | List[int] | None = None) Tensor | None#

Get the homodyne measurement results for quadratures x and p.

参数:
  • shots (int, optional) – The number of times to sample from the quantum state. Default: 1024

  • 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)

property max_depth: int#

Get the max number of gates on the wires.

draw(filename: str | None = None)#

Visualize the photonic quantum circuit.

参数:

filename (str or None, optional) – The path for saving the figure.

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 as Gate, or QumodeCircuit.

  • encode (bool) – Whether the gate is to encode data. Default: False

  • wires (Union[int, List[int], None]) – 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. When basis is False, 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.

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)#

基类: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.

draw()#

Draw 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, name=None)#

Draw phaseshif (rotation) gate.

draw_sq(order, wires, r, theta, name=None)#

Draw squeezing gate, displacement gate.

draw_any(order, wires, name, para_dict=None)#

Draw arbitrary unitary gate.

draw_lines(order, wires)#

Act nothing.

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 or cssl 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, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#

基类:Gate

Single-mode photonic quantum gate. :param name: The name of the gate. Default: None :type name: str or None, optional :param inputs: The parameters of the gate. Default: None :type inputs: Any, optional :param nmode: The number of modes that the quantum operation acts on. Default: 1 :type nmode: int, optional :param wires: 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 or buffer. Default: False (which means buffer)

  • 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, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)#

基类:Gate

Two-mode photonic quantum gate. :param name: The name of the gate. Default: None :type name: str or None, optional :param inputs: The parameters of the gate. Default: None :type inputs: Any, optional :param nmode: The number of modes that the quantum operation acts on. Default: 2 :type nmode: int, optional :param wires: 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 or buffer. Default: False (which means buffer)

  • 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, 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

  • requires_grad (bool, optional) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • 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, 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

  • requires_grad (bool, optional) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • 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, 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 is False:

\[ \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

  • phi_first (bool, optional) – Whether \(\phi\) is the first phase shifter. Default: True

  • requires_grad (bool, optional) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • 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 operators.

class deepquantum.photonic.gate.BeamSplitterTheta(inputs: Any | None = None, nmode: int = 2, wires: List[int] | None = None, cutoff: int | None = None, 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

  • requires_grad (bool, optional) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • 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, 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

  • requires_grad (bool, optional) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • 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, 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

  • 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 or buffer. Default: False (which means buffer)

  • 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, 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 is None. Default: None

  • cutoff (int or None, optional) – The Fock space truncation. Default: None

  • 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, 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

  • requires_grad (bool, optional) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • 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 matrix acting on annihilation and creation operators.

update_matrix() Tensor#

Update the local 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, 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

  • requires_grad (bool, optional) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • 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 matrix acting on annihilation and creation operators.

update_matrix() Tensor#

Update the local 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, 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

  • requires_grad (bool, optional) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • 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 unitary matrix acting on annihilation and creation operators.

update_matrix() Tensor#

Update the local 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, 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

  • requires_grad (bool, optional) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • 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, 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

  • requires_grad (bool, optional) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • 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.

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.operation module#

Base classes

class deepquantum.photonic.operation.Operation(name: str | None = None, nmode: int = 1, wires: int | List | None = None, cutoff: int = 2, 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

  • 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, 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

  • 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.

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_gaussian(x: List[Tensor]) List[Tensor]#

Perform a forward pass for Gaussian 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.

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) List#

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) List#

Generate all possible combinations of Fock states for a given number of modes and photons.

参数:
  • nmode (int) – The number of modes in the system.

  • nphoton (int) – The total number of photons in the system.

返回:

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]]
deepquantum.photonic.qmath.xxpp_to_xpxp(matrix: Tensor) Tensor#

Transform the representation in xxpp ordering to the representation in xpxp ordering.

deepquantum.photonic.qmath.xpxp_to_xxpp(matrix: Tensor) Tensor#

Transform the representation in xpxp ordering to the representation in xxpp ordering.

deepquantum.photonic.qmath.quadrature_to_ladder(matrix: Tensor) Tensor#

Transform the representation in xxpp ordering to the representation in aa^+ ordering.

deepquantum.photonic.qmath.ladder_to_quadrature(matrix: Tensor) Tensor#

Transform the representation in aa^+ ordering to the representation in xxpp ordering.

deepquantum.photonic.qmath.photon_number_mean_var(cov: Tensor, mean: Tensor) Tuple[Tensor, Tensor]#

Get the expectation value and variance of the photon number for single-mode Gaussian states.

deepquantum.photonic.qmath.takagi(a: Tensor)#

Tagaki decomposition for symmetric complex matrix.

See https://math.stackexchange.com/questions/2026110/

deepquantum.photonic.qmath.sample_sc_mcmc(prob_func: Callable, proposal_sampler: Callable, shots: int = 1024, num_chain: int = 5) defaultdict#

Get the samples of the probability distribution function via SC-MCMC method.

deepquantum.photonic.state module#

Quantum states

class deepquantum.photonic.state.FockState(state: Any, nmode: int | None = None, cutoff: int | None = None, basis: bool = True)#

基类: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

class deepquantum.photonic.state.GaussianState(state: str | List = 'vac', nmode: int | None = None, cutoff: int = 5)#

基类: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 states with [cov, mean]. cov and mean are the covariance matrix and the displacement vector of the Gaussian state, respectively. Use xxpp convention and \(\hbar=2\) by default. Default: 'vac'

  • nmode (int or None, optional) – The number of modes in the state. Default: None

  • cutoff (int, optional) – The Fock space truncation. Default: 5

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)

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

Module contents#

Photonic Module