Util

class slowquant.qiskit_interface.util.Clique

Clique class.

  1. 10.1109/TQE.2020.3035814, Sec. IV. A, IV. B, and VIII.

Initialize clique class.

add_paulis(paulis: list[str]) list[str]

Add list of Pauli strings to cliques and return clique heads to be simulated.

Parameters:

paulis – Paulis to be added to cliques.

Returns:

List of clique heads to be calculated.

get_distr(pauli: str) dict[int, float]

Get sample state distribution for a Pauli string.

Parameters:

pauli – Pauli string.

Returns:

Sample state distribution.

update_distr(new_heads: list[str], new_distr: list[dict[int, float]]) None

Update sample state distributions of clique heads.

Parameters:
  • new_heads – List of clique heads.

  • new_distr – List of sample state distributions.

class slowquant.qiskit_interface.util.CliqueHead(head: str, distr: dict[int, float] | None)

Initialize clique head dataclass.

Parameters:
  • head – Clique head.

  • distr – Sample state distribution.

slowquant.qiskit_interface.util.correct_distribution(dist: dict[int, float], M: ndarray) dict[int, float]

Corrects a quasi-distribution of bitstrings based on a correlation matrix in statevector notation.

Parameters:
  • dist – Quasi-distribution.

  • M – Correlation martix.

Returns:

Quasi-distribution corrected by correlation matrix.

slowquant.qiskit_interface.util.f2q(i: int, num_orbs: int) int

Convert fermionic index to qubit index.

The fermionic index is assumed to follow the convention,

\[\left|0_\alpha 0_\beta 1_\alpha 1_\beta ... N_\alpha N_\beta\right>\]

The qubit index follows,

\[\left|0_\alpha 1_\alpha ... N_\alpha 0_\beta 1_\beta ... N_\beta\right>\]

This function assumes Jordan-Wigner mapping.

Parameters:
  • i – Fermionic index.

  • num_orbs – Number of spatial orbitals.

Returns:

Qubit index.

slowquant.qiskit_interface.util.fit_in_clique(pauli: str, head: str) tuple[bool, str]

Check if a Pauli fits in a given clique.

Parameters:
  • pauli – Pauli string.

  • head – Clique head.

Returns:

If commuting and new clique head.

slowquant.qiskit_interface.util.get_bitstring_sign(op: str, binary: int) int

Convert Pauli string and bit-string measurement to expectation value.

Takes Pauli String and a state in binary form and returns the sign based on the expectation value of the Pauli string with each single qubit state.

This is achieved by using the following evaluations:

\[\begin{split}\begin{align} \left<0\left|I\right|0\right> &= 1\\ \left<1\left|I\right|1\right> &= 1\\ \left<0\left|Z\right|0\right> &= 1\\ \left<1\left|Z\right|1\right> &= -1\\ \left<0\left|HXH\right|0\right> &= 1\\ \left<1\left|HXH\right|1\right> &= -1\\ \left<0\left|HSYS^{\dagger}H\right|0\right> &= 1\\ \left<1\left|HSYS^{\dagger}H\right|1\right> &= -1 \end{align}\end{split}\]

The total expectation value is then evaulated as:

\[E = \prod_i^N\left<b_i\left|P_{i,T}\right|b_i\right>\]

With \(b_i\) being the \(i\) th bit and \(P_{i,T}\) being the \(i\) th properly transformed Pauli operator.

Parameters:
  • op – Pauli string operator.

  • binary – Measured bit-string.

Returns:

Expectation value of Pauli string.

slowquant.qiskit_interface.util.postselection(dist: dict[int, float], mapper: FermionicMapper, num_elec: tuple[int, int], num_qubits: int) dict[int, float]

Perform post-selection on distribution in computational basis.

For the Jordan-Wigner mapper the post-selection ensure that,

\[\text{sum}\left(\left|\alpha\right>\right) = N_\alpha\]

and,

\[\text{sum}\left(\left|\beta\right>\right) = N_\beta\]

For the Parity mapper it is counted how many times bitstring changes between 0 and 1. For the bitstring \(\left|01\right>\) the counting is done by padding the string before counting. I.e.

\[\left|01\right> \rightarrow 0\left|01\right>p\]

Where \(p\) is zero for even number of electrons and one for odd number of electrons. This counting is done independtly for the \(\alpha\) part and \(\beta\) part.

Parameters:
  • dist – Measured quasi-distribution.

  • mapper – Fermionic to qubit mapper.

  • num_elec – Number of electrons (alpha, beta).

  • num_qubits – Number of qubits.

Returns:

Post-selected distribution.

slowquant.qiskit_interface.util.to_CBS_measurement(op: str, transpiled: None | list[QuantumCircuit] = None) QuantumCircuit

Convert a Pauli string to Pauli measurement circuit.

This is achived by the following transformation:

\[\begin{split}\begin{align} I &\rightarrow I\\ Z &\rightarrow Z\\ X &\rightarrow XH\\ Y &\rightarrow YS^{\dagger}H \end{align}\end{split}\]
Parameters:
  • op – Pauli string.

  • transpiled – List of transpiled X and Y gate.

Returns:

Pauli measurement quantum circuit.