Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamicsBackend sets Target.num_qubits which is not settable in Qiskit 1.3 #366

Open
wshanks opened this issue Nov 15, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@wshanks
Copy link
Contributor

wshanks commented Nov 15, 2024

Informations

  • Qiskit Dynamics version: 0.5.1
  • Python version: 3.12
  • Operating system: Fedora Linux 41

What is the current behavior?

AttributeError when trying to create a DynamicsBackend:


File ~/envs/qiskit/lib/python3.12/site-packages/qiskit_dynamics/backend/dynamics_backend.py:219, in DynamicsBackend.__init__(self, solver, target, **options)
    216     target.add_instruction(Measure(), measure_properties)
    218 target.dt = solver._dt
--> 219 target.num_qubits = len(self.options.subsystem_dims)
    221 self._target = target

AttributeError: attribute 'num_qubits' of 'qiskit._accelerate.target.BaseTarget' objects is not writable

Steps to reproduce the problem

Run the following code with Qiskit 1.3:

from qiskit.quantum_info import Operator
from qiskit_dynamics import DynamicsBackend, Solver
import numpy as np

nu_z = 10.
nu_x = 1.
nu_d = 9.98 # Almost on resonance with the Hamiltonian's energy levels difference, nu_z

X = Operator.from_label('X')
Y = Operator.from_label('Y')
Z = Operator.from_label('Z')
s_p = 0.5 * (X + 1j * Y)

solver = Solver(
    static_hamiltonian=.5 * 2 * np.pi * nu_z * Z,
    hamiltonian_operators=[2 * np.pi * nu_x * X],
    hamiltonian_channels=["d0"],
    channel_carrier_freqs={"d0": nu_x},
    dt=0.01,
)

dynamics_backend = DynamicsBackend(solver=solver, subsystem_dims=[2])

What is the expected behavior?

Successful DynamicsBackend creation

Suggested solutions

num_qubits can be passed to Target instead. I am not sure about the case when a target is passed in to DynamicsBackend. I think it should just leave the target alone and base the number of qubits on the subsystem dimensions. Perhaps it could make a new target and only copy the instructions related to the qubits in the subsystem. Thinking about it more, I think it would be most consistent to build a new qubit with just the instructions for the qubits in the subsystem to be simulated. Otherwise, number of qubits will be inconsistent in different parts of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant