quantumlib / OpenFermion

The electronic structure package for quantum computers.
Apache License 2.0
1.51k stars 372 forks source link

The implementation of bogoliubov for a general fermionic gaussian that doesn't mix spin up and spin down is broken #776

Open wjhuggins opened 2 years ago

wjhuggins commented 2 years ago

When bogoliubov_transform is called with a transformation_matrix that has shape N x 2N the check that determines whether or not the transformation mixes spin up and spin down and the subsequent code is broken. The current check (_is_spin_block_diagonal) and some of the subsequent code is only valid for a square transformation_matrix.

To reproduce:

Call bogoliubov_transform with the following arguments: qubits = [cirq.LineQubit(0), cirq.LineQubit(1)] trasformation_matrix = np.ndarray([[-9.57167901e-01-2.89533435e-01j, 0.00000000e+00+0.00000000e+00j, -3.33066907e-16-5.55111512e-17j, 0.00000000e+00+0.00000000e+00j], [ 0.00000000e+00+0.00000000e+00j, 1.00000000e+00+0.00000000e+00j, 0.00000000e+00+0.00000000e+00j, 0.00000000e+00+0.00000000e+00j]])

wjhuggins commented 2 years ago

It can be circumvented by adding the following code to _is_spin_block_diagonal(matrix) if matrix.shape[0] != matrix.shape[1]: return False

It should be possible to implement properly for a general fermionic gaussian transformation though.