Add string representation for PassManagerConfig#8085
Conversation
This commit adds a new string representation to the PassManagerConfig class. When str() is run on a PassManagerConfig object it will return a string listing the values for all of the attributes in the class.
Pull Request Test Coverage Report for Build 2391198920
💛 - Coveralls |
jakelishman
left a comment
There was a problem hiding this comment.
Happy to approve if you're not bothered about the comment.
| return ( | ||
| "Pass Manager Config:\n" |
There was a problem hiding this comment.
I don't feel very strongly about this at all, but is it worth formatting it as
f"""
PassManagerConfig(
initial_layout={self.initial_layout},
basis_gates={self.basis_gates},
...
)
"""so it can easily be copy-paste evaled back into an interpreter?
There was a problem hiding this comment.
I'm not sure if it's useful to do that in this case because this is not actually going to be a repr string in this case. You won't be able to eval the output because several of the fields are more complex objects that have human readable outputs (InstructionScheduleMap, InstructionDurations, CouplingMap, Target, etc)
I personally was just looking for something that I could use for quick print debugging in #7789 that gave me output I could read to show what was getting passed to the PassManagerConfig
There was a problem hiding this comment.
I'm fine with this - what I was suggesting is more like for repr anyway.
|
While trying to test it, I realised that I'm not sure if does what is intended: from qiskit import QuantumRegister
from qiskit.test.mock import FakeMelbourne
from qiskit.transpiler.passmanager_config import PassManagerConfig
qr = QuantumRegister(4, "qr")
initial_layout = [None, qr[0], qr[1], qr[2], None, qr[3]]
backend = FakeMelbourne()
config = PassManagerConfig.from_backend(
backend, basis_gates=["user_gate"], initial_layout=initial_layout
)
print(config) |
|
tagging this as |
|
@1ucian0 I'm not sure what your concern is that's the expected output, it's showing the string output for each element in the pass manager config. What are you expecting the output to look like? I'll add a test, that was an oversight. |
|
For example, |
This commit ensure that all entries under the pass manager config have a single tab indent and also adds a test to verify the output.
Summary
This commit adds a new string representation to the PassManagerConfig
class. When str() is run on a PassManagerConfig object it will return a
string listing the values for all of the attributes in the class.
Details and comments