Closed hadizadeh-ali closed 1 year ago
import numpy as np from qiskit.opflow import I, MatrixOp def positional(n: int, i: int, ketbra: str): KETBRA = np.eye(2) if ketbra[0] == '0': KETBRA = KETBRA @ np.array([[1, 0]]).T else: KETBRA = KETBRA @ np.array([[0, 1]]).T if ketbra[1] == '0': KETBRA = KETBRA @ np.array([[1, 0]]) else: KETBRA = KETBRA @ np.array([[0, 1]]) return (I ^ i) ^ MatrixOp(KETBRA) ^ (I ^ (n-i-1)) (3 * positional(2, 0, '11') @ positional(2, 1, '11')).to_matrix()
Output:
array([[0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 9.+0.j]])
Correct output:
array([[0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 3.+0.j]])
Output:
Correct output: