Skip to content

Several modules, e.g QBaysian, use a private attribute of QuantumCircuit #943

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

Open
woodsp-ibm opened this issue May 28, 2025 · 0 comments
Open

Comments

@woodsp-ibm
Copy link
Member

woodsp-ibm commented May 28, 2025

I noticed the following in the QBayasian code where the use of a variable with the private naming ie leading underscore was flagged. As this is using what is normally considered implementation private and can be changed at any time it would be better to be relying on a supported public interface instead. (Raising an issue perhaps on qiskit to address this need if its not met elsewhere - which I kinda assume is the case due to the use of that private.)

if hasattr(circuit.layout, "_input_qubit_count"):
self.num_virtual_qubits = circuit.layout._input_qubit_count
else:
if pass_manager is None:
self.num_virtual_qubits = circuit.num_qubits
else:
circuit = pass_manager.run(circuit)
self.num_virtual_qubits = circuit.layout._input_qubit_count

Now I had to do a double take on the code snippet above as while it seemed to be doing a conditional check on the presence and accessing it in the if part - it goes ahead anyway and just accesses it in the else at the end. It seems on further research that the transpiler adds that so running the pass manager has the side-effect of creating it so it exists despite at first glance being wrong as its inside the else part. Some comments in the code would have been helpful - though to me anyway the use of a private member is rather suspect as the private variable is really an internal implementation detail that not being public and supported could be changed at any time.


Note: Code using the same private variable is present in several other files too where the same comment about its use applies.

@woodsp-ibm woodsp-ibm changed the title QBaysian uses private circuit attribute Several classes, e.g QBaysian, use a private attribute of QuantumCircuit May 30, 2025
@woodsp-ibm woodsp-ibm changed the title Several classes, e.g QBaysian, use a private attribute of QuantumCircuit Several modules, e.g QBaysian, use a private attribute of QuantumCircuit May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant