mapper#

Map the quantum gate to photonic quantum circuit

Classes

UnitaryMapper(nqubit, nmode, ugate, success)

Map the quantum gate to the unitary matrix of the photonic quantum circuit based on dual-rail encoding.

class UnitaryMapper(nqubit: int, nmode: int, ugate: Any, success: float, aux: list | None = None, aux_pos: list | None = None)[source]#

Bases: object

Map the quantum gate to the unitary matrix of the photonic quantum circuit based on dual-rail encoding.

Parameters:
  • 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 | None) – Two auxiliary modes in the circuit, which could be [0,0] or [1,0]. Default: None

  • aux_pos (list | None) – The positions of the auxiliary modes. Default: None (which means the last two modes).

create_basis(aux_position)[source]#

Create the nqubit bases in dual-rail encoding.

static create_subset(num_coincidence)[source]#

Get all subset from \(\{1,2,...n\}\).

static exchange(matrix, aux1_pos)[source]#
f_complex(y)[source]#

Construct \(2^{nqubit}*2^{nqubit}\) equations for \(n*n\) matrix y, obtain complex solutions.

Parameters:

y – an array with \(2*n^2\) element

f_complex_unitary(paras)[source]#

Return quantum gate constrains and the unitary constrains.

f_real(y)[source]#

Construct equations to obtain real solutions for the real part of the target quantum gate.

Parameters:

y – Input matrix/array with \(n^2\) elements, where \(n = 2^{nqubit}\).

f_real_unitary(y)[source]#

Return the quantum gate constrains and the unitary constrains.

get_coeff_sym(input_state: Tensor, output_states: list | None = None)[source]#

Return the transfer state coefficient in a symbolic way.

get_indx_coeff(coeff_i, all_inputs=None)[source]#

Get the index of y_var for given state transfer coefficients.

get_transfer_mat(y)[source]#
indx_eqs()[source]#

Get the dictinonary of indices of y_mat for each nonlinear equations for n modes.

static is_unitary(u_temp)[source]#

Check the matrix is unitary or not.

static permanent(mat)[source]#

Use Ryser formula for permanent, only valid for square matrix.

static plot_u(unitary, vmax=1, vmin=0, fs=20, len_ticks=5, cl='RdBu')[source]#

Plot the matrix in graphic way.

Parameters:
  • 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 product_factorial(state)[source]#

Get the product of the factorial from the state, i.e., \(|s_1,s_2,...s_n> --> s_1!*s_2!*...s_n!\).

static save_dict(dictionary, file_path)[source]#
static set_copy_indx(state)[source]#

Pick up indices from the nonezero elements of state.

static single_output(single_idx, y_test)[source]#
static single_prod(single_idx_i, y_test)[source]#
solve_eqs_complex(total_trials=10, trials=1000, precision=1e-05)[source]#

Solve the non-linear eqautions for matrix satisfying ugate with complex solution.

solve_eqs_real(total_trials=10, trials=1000, precision=1e-06)[source]#

Solve the non-linear eqautions for matrix satisfying ugate with real solution.

state_basis()[source]#

Map ‘000’ to dual_rail.

static sub_matrix_sym(unitary, input_state, output_state)[source]#

Get the sub_matrix of transfer probs for given input and output state.

static unitary_constrains(u_temp: Tensor)[source]#

Return \(n^2\) equations for \(n*n\) matrix with unitary condition.

static unitary_constrains_complex(u_temp: Tensor)[source]#

Return \(2*n^2\) equations for \(n*n\) complex matrix with unitary condition.