06-Nature Tutorial- Mapping to the Qubit Space

[ ]:
#This code is at
#https://qiskit-community.github.io/qiskit-nature/tutorials/06_qubit_mappers.html
[1]:
from qiskit_nature.second_q.drivers import PySCFDriver

driver = PySCFDriver()
problem = driver.run()
fermionic_op = problem.hamiltonian.second_q_op()
[2]:
from qiskit_nature.second_q.mappers import JordanWignerMapper

mapper = JordanWignerMapper()
[3]:
qubit_jw_op = mapper.map(fermionic_op)
print(qubit_jw_op)

SparsePauliOp(['IIII', 'IIIZ', 'IIZI', 'IIZZ', 'IZII', 'IZIZ', 'ZIII', 'ZIIZ', 'YYYY', 'XXYY', 'YYXX', 'XXXX', 'IZZI', 'ZIZI', 'ZZII'],
              coeffs=[-0.81054798+0.j,  0.17218393+0.j, -0.22575349+0.j,  0.12091263+0.j,
  0.17218393+0.j,  0.16892754+0.j, -0.22575349+0.j,  0.16614543+0.j,
  0.0452328 +0.j,  0.0452328 +0.j,  0.0452328 +0.j,  0.0452328 +0.j,
  0.16614543+0.j,  0.17464343+0.j,  0.12091263+0.j])
[4]:
from qiskit_nature.second_q.mappers import ParityMapper

mapper = ParityMapper()
[5]:
qubit_p_op = mapper.map(fermionic_op)
print(qubit_p_op)
SparsePauliOp(['IIII', 'IIIZ', 'IIZZ', 'IIZI', 'IZZI', 'IZZZ', 'ZZII', 'ZZIZ', 'ZXIX', 'IXZX', 'ZXZX', 'IXIX', 'IZIZ', 'ZZZZ', 'ZIZI'],
              coeffs=[-0.81054798+0.j,  0.17218393+0.j, -0.22575349+0.j,  0.12091263+0.j,
  0.17218393+0.j,  0.16892754+0.j, -0.22575349+0.j,  0.16614543+0.j,
  0.0452328 +0.j, -0.0452328 +0.j, -0.0452328 +0.j,  0.0452328 +0.j,
  0.16614543+0.j,  0.17464343+0.j,  0.12091263+0.j])
[6]:
mapper = ParityMapper(num_particles=problem.num_particles)
[7]:
qubit_op = mapper.map(fermionic_op)
print(qubit_op)
SparsePauliOp(['II', 'IZ', 'ZI', 'ZZ', 'XX'],
              coeffs=[-1.05237325+0.j,  0.39793742+0.j, -0.39793742+0.j, -0.0112801 +0.j,
  0.1809312 +0.j])
[8]:
tapered_mapper = problem.get_tapered_mapper(mapper)
print(type(tapered_mapper))
<class 'qiskit_nature.second_q.mappers.tapered_qubit_mapper.TaperedQubitMapper'>
[9]:
qubit_op = tapered_mapper.map(fermionic_op)
print(qubit_op)

SparsePauliOp(['I', 'Z', 'X'],
              coeffs=[-1.04109314+0.j, -0.79587485+0.j, -0.1809312 +0.j])
[10]:
from qiskit_nature.second_q.circuit.library import HartreeFock
[11]:
hf_state = HartreeFock(2, (1, 1), JordanWignerMapper())
hf_state.draw()
[11]:
     ┌───┐
q_0: ┤ X ├
     └───┘
q_1: ─────
     ┌───┐
q_2: ┤ X ├
     └───┘
q_3: ─────
          
[12]:
from qiskit_nature.second_q.mappers import InterleavedQubitMapper

[13]:
interleaved_mapper = InterleavedQubitMapper(JordanWignerMapper())


[14]:
hf_state = HartreeFock(2, (1, 1), interleaved_mapper)
hf_state.draw()
[14]:
     ┌───┐
q_0: ┤ X ├
     ├───┤
q_1: ┤ X ├
     └───┘
q_2: ─────

q_3: ─────
          
[ ]: