Infleqtion / client-superstaq

https://superstaq.readthedocs.io
Apache License 2.0
89 stars 19 forks source link

QCVV sample repr fails if any component hasn't been generated yet #1071

Closed richrines1 closed 1 month ago

richrines1 commented 2 months ago

What is happening?

print(experiment.samples) fails for qcvv experiments if any sample hasn't been both run and compiled, because repr(sample) will try to access missing attributes. this is pretty annoying when working in a python shell, which tries to print the repr if i just enter e.g. experiment.samples[0]

i think the easy (and imo best?) fix would be to have the missing attributes default to None instead of making them fields with init=False.

How can we reproduce the issue?

exp = supermarq.qcvv.IRB()
exp.prepare_experiment(2, [2])
print(exp.samples)  # AttributeError: 'Sample' object has no attribute 'probabilities'

exp.run_with_simulator()
print(exp.samples)  # AttributeError: 'Sample' object has no attribute 'compiled_circuit'

What should happen?

i should be able to print the samples, even if they're not ready yet

Environment

Any additional context?

No response

cdbf1 commented 2 months ago

This is something that had been bugging me a bit too, I just hadn't gotten round to fixing so thanks for forcing me to actually sort it!