qiskit-community / qiskit-hackathon-korea-21

A repository for Qiskit Hackathon Korea (February 16-19, 2021)
33 stars 11 forks source link

EntangledMeasurementGrouper (Qiskit-Terra/OperatorFlow) #20

Open ikkoham opened 3 years ago

ikkoham commented 3 years ago

Abstract

Reduction of the number of measurements is one of the most important topic for variational quantum algorithms. In Qiskit, Abelian grouper was implemented for the evaluations of expectation values by joint measurement of tensor product basis (TPB). This project enhances the grouper by using entangled measurements.

Description

This project aims to implement a part of our research for Qiskit and improve the research. The number of measurements can be reduced by entangled measurements. For example, Bell measurement is a joint measurement of XX, YY, and ZZ.

image

We use the entangled joint measurements to improve the grouper. Very recently, I have added the parameter grouping_type for this purpose.https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/opflow/primitive_ops/pauli_sum_op.py#L39

Milestone

References

Members

Deliverable

GitHub repo

KIMJAEHEE0821 commented 3 years ago

Hello, I want to participate in this project. Can I join the team?

physicman96 commented 3 years ago

I'm interested in this project. Could I join this team?

YubeenKim commented 3 years ago

I am also interested in this project!!

sky-born commented 3 years ago

It seems very interesting. I want to reduce measurement too. Can I join this project?

ghost commented 3 years ago

it is very groundbreaking idea! Can i participate?

ikkoham commented 3 years ago

Dev Environment

  1. Fork Qiskit-Terra

  2. Make your branch to work

For CLI

git clone https://github.com/Qiskit/qiskit-terra.git
git remote add sky-born https://github.com/sky-born/qiskit-terra
git fetch sky-born
git switch -c qiskit_korea_hackerthon sky-born/qiskit_korea_hackerthon

Launch Jupyter Notebook with dev env

ikkoham commented 3 years ago

It may be better to prepare the molecule for benchmark.

YubeenKim commented 3 years ago

I saw LiH, BeH2, H2O, NH3, HCl is in the paper. Should we use that??

ikkoham commented 3 years ago

You can choose it. You can use same molecules with the paper, or it may be interesting to study and compare other molecules. Note that the paper uses Ancillary files in https://arxiv.org/abs/1701.08213. if you want to use Ancillary files, you need to parse the data and make PauliSumOp from them.

sky-born commented 3 years ago

How can I extract Pauli string from PaulisumOp operator?

sky-born commented 3 years ago

and SummedOp too, It's not easy to extract Pauli string operators from PaulisumOp and SummedOp class

ikkoham commented 3 years ago

This is a hint for creating Pauli graph. https://github.com/Qiskit/qiskit-terra/pull/5299/files

Hint for _anti_commutation_graph(ops: PauliSumOp) -> List[Tuple[int, int]]: For TPB (qubit-wise anti-commutation graph),

# convert a Pauli operator into int vector where {I: 0, X: 2, Y: 3, Z: 1}
mat1 = np.array(
    [op.primitive.table.Z[0] + 2 * op.primitive.table.X[0] for op in observable],
    dtype=np.int8,
)
mat2 = mat1[:, None]
# mat3[i, j] is True if i and j are commutable with TPB
mat3 = (mat1 * mat2) * (mat1 - mat2)
mat4 = (mat3 == 0).all(axis=2)
# return [(i, j) if mat3[i, j] is False and i < j]
return list(zip(*np.where(np.triu(np.logical_not(mat4), k=1))))

For ALL, (general anti-commutation graph),

# convert a Pauli operator into int vector where {I: 0, X: 2, Y: 3, Z: 1}
mat1 = np.array(
    [op.primitive.table.Z[0] + 2 * op.primitive.table.X[0] for op in observable],
    dtype=np.int8,
)
mat2 = mat1[:, None]
# mat3[i, j] is True if i and j are commutable with TPB
mat3 = (mat1 * mat2) * (mat1 - mat2)
mat4 = mat3.copy()
mat4[mat3 == 0] = 1
mat4[mat3 != 0] = -1
mat5 = np.multiply.reduce(mat4, axis=2) == 1
return list(zip(*np.where(np.triu(np.logical_not(mat5), k=1))))

This algorithm is too difficult because I use numpy technique for performance.