Error accessing attribute of Python object from Julia.
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Reproduziere den Attributzugriff von qiskit_aer.AerSimulator mit den bereitgestellten Julia- und CondaPkg-Versionen. Beginne bei src/JlWrap/any.jl:249 und dem im Traceback gezeigten PythonCall-Attribut-Lookup und vergleiche anschließend den Zugriff auf num_qubits mit dem Pfad für die Tab-Vervollständigung. Erledigt ist die Aufgabe, wenn test.num_qubits den numerischen Wert des Python-Attributs ohne den Array-Feldfehler zurückgibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Affects: PythonCall
Describe the bug
Im trying to use qiskit_aer, which is a python package, from Julia.
First I add the dependencies, which results in my CondaPkg.toml to look like this:
[deps]
qiskit-aer = "0.16.1.*"
qiskit = "1.4.2.*"
Then I load it:
const qiskit_aer = PythonCall.pynew()
PythonCall.pycopy!(qiskit_aer, PythonCall.pyimport("qiskit_aer"))
Now I can create an simulator object:
test = qiskit_aer.AerSimulator(
method="statevector",
device="CPU",
enable_truncation=false,
target=[0]
)
And I can see all its attributes when pressing tab for auto compleation:
julia> test.
_AVAILABLE_DEVICES _AVAILABLE_METHODS _BASIS_GATES _CUSTOM_INSTR _DEFAULT_CONFIGURATION _SIMULATION_DEVICES _SIMULATION_METHODS
__abstractmethods__ __class__ __delattr__ __dict__ __dir__ __doc__ __eq__
__format__ __ge__ __getattribute__ __getstate__ __gt__ __hash__ __init__
__init_subclass__ __le__ __lt__ __module__ __ne__ __new__ __reduce__
__reduce_ex__ __repr__ __setattr__ __sizeof__ __slots__ __str__ __subclasshook__
__weakref__ _abc_impl _assemble_noise_model _basis_gates _cached_basis_gates _check_basis_gates _compile
_configuration _controller _convert_binds _convert_circuit_binds _coupling_map _default_options _execute_circuits
_execute_circuits_job _format_results _from_backend _get_executor _instruction_schedule_map _mapping _options
_options_configuration _options_properties _properties _provider _run_circuits _set_configuration_option _set_method_config
_set_properties_option _target acquire_channel available_devices available_methods backend_version clear_options
configuration control_channel coupling_map description drive_channel dt dtm
from_backend instruction_durations instruction_schedule_map instructions max_circuits meas_map measure_channel
name num_qubits online_date operation_names operations options properties
provider qubit_properties run set_max_qubits set_option set_options status
target
So far it works great. Now the bug occurs when I actually want to get one of these attributes:
julia> test.num_qubits
ERROR: Python: AttributeError: Julia: type Array has no field num_qubits
Python stacktrace:
[1] __getattr__
@ ~/.julia/packages/PythonCall/WMWY0/src/JlWrap/any.jl:249
[2] num_qubits
@ qiskit.providers.backend /files/home/part8/user/Bookworm/Documents/project/.CondaPkg/env/lib/python3.11/site-packages/qiskit/providers/backend.py:406
Stacktrace:
[1] pythrow()
@ PythonCall.Core ~/.julia/packages/PythonCall/WMWY0/src/Core/err.jl:92
[2] errcheck
@ ~/.julia/packages/PythonCall/WMWY0/src/Core/err.jl:10 [inlined]
[3] pygetattr(x::Py, k::String)
@ PythonCall.Core ~/.julia/packages/PythonCall/WMWY0/src/Core/builtins.jl:62
[4] getproperty(x::Py, k::Symbol)
@ PythonCall.Core ~/.julia/packages/PythonCall/WMWY0/src/Core/Py.jl:273
[5] top-level scope
@ REPL[19]:1
I would expect this to just return a number. The attribute existes, see docs.
Your system
julia> versioninfo()
Julia Version 1.11.4
Commit 8561cc3d68d (2025-03-10 11:36 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 24 × 13th Gen Intel(R) Core(TM) i7-13700
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 24 virtual cores)
Environment:
JULIA_EDITOR = code
julia> CondaPkg.status()
CondaPkg Status /files/home/part8/user/Bookworm/Documents/project/CondaPkg.toml
Environment
/files/home/part8/user/Bookworm/Documents/project/.CondaPkg/env
Packages
qiskit v1.4.2 (1.4.2.*)
qiskit-aer v0.16.1 (0.16.1.*)
- Vorherrschende Sprache
- Julia
- Sterne
- 1.1k
- Forks
- 89
- Ø Merge
- 2 T. 15 Std.
- Gemergte PRs (30 T.)
- 7
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus JuliaPy/PythonCall.jl
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
JuliaPy/PythonCall.jl#828 · 7 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
JuliaPy/PythonCall.jl#809 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
JuliaPy/PythonCall.jl#805 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
JuliaPy/PythonCall.jl#796 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
JuliaPy/PythonCall.jl#790 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in JuliaPy/PythonCall.jl
Ähnliche Issues
-
documentation
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 65/100
Maintainer antworten meist innerhalb von 6 Tagen
-
broken links in docsOffen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
JuliaPhysics/BeamletOptics.jl#127 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up stepsEvtl. vergeben @thevolatilebit hat das vor 1 Tag übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag