-
Notifications
You must be signed in to change notification settings - Fork 131
Remove units from experiment options #516
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
Conversation
nkanazawa1989
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @yaelbh for taking a look at the unit issue. I think there are several other experiments that take frequency val with arbitrary unit. Probably we need an internal rule to define how we pass values to fitter, either dt or SI. If fitter assumes values in SI the xval conversion logic should exist on experiment side.
| "experiment_type": self.experiment_type, | ||
| "qubits": self.physical_qubits, | ||
| "xval": prefactor * flat_top_width * dt_factor, # in units of sec | ||
| "xval": flat_top_width |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this conversion is necessary because fitter assumes xval in sec, i.e. it need to compute Hamiltonian coefficients in Hz (or you can covert dt in sec in the fitter since it still has access to backend)
|
To do:
|
| options.normalization = True | ||
| options.xlabel = "Frequency" | ||
| options.ylabel = "Signal (arb. units)" | ||
| options.xval_unit = "Hz" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this xval_unit is necessary because this represents an axis label of output figure.
|
I'd like not to update the cloud tutorial. It's not updated to the latest main in the first place, it involves cuts of screenshots from the web, and is about to be refactored anyway. |
nkanazawa1989
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @yaelbh this is really good. Just one request for update of handling of delay to be more precise. You can also remove this code
https://github.com/Qiskit/qiskit-experiments/blob/482a83cede9a22fd96bfa176446014d48e57ea61/qiskit_experiments/library/characterization/t1.py#L108-L118
and
https://github.com/Qiskit/qiskit-experiments/blob/482a83cede9a22fd96bfa176446014d48e57ea61/qiskit_experiments/library/characterization/t1.py#L64
because this exist because of init guess unit conversion that is removed with this PR. Then you can revert the patch code introduced in #529
|
|
||
| circuits = [] | ||
| for delay in prefactor * np.asarray(self.experiment_options.delays, dtype=float): | ||
| for delay in np.asarray(self.experiment_options.delays, dtype=float): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we explicitly convert delay into dt here? Because delay in SI is converted into dt in the transpiler and rounded to integer. So actual delay value can differ from x value in analysis by this rounded value. This effect becomes visible when T1 value is very short (really edge case though).
The code is something like
delay_dt = int(np.round(delay / dt_factor))
...
circ.delay(delay_dt, 0, "dt")
...
"xval": delay_dt * dt_factor,same for T2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. On the one hand, I understand your reason. On the other hand:
- I was hoping to completely get rid of anything that has units and factors in it.
- Users may not understand why the delays they entered have shifted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree mismatch due to rounding error is negligible and probably this is overkill. In our device, the error of actual delay and fit xval is less than 0.22 ns which is way smaller than T1 decay of fit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the values should be shifted, but I also agree that for current IBM devices this concern is negligible for T1. However, there are some experiments where timing is important and I think we should try to handle time values consistently across experiments. So I think it would be best to store time values as the real values when we are scanning time and rounding is involved. Maybe a helper function for translating the time values could help promote handling time values consistently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but in way that's a bit different from the one suggested here, please check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks okay to me, but @nkanazawa1989 should check it. I don't know what one can rely on when doing a transpilation. Could a delay gate ever be split into multiple delays or could another delay gate ever get inserted in the beginning of a circuit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is too hacky and has several edge cases. For example, you only assumes single delay in the program but this is not true because measure align pass will add extra delay before measurement to align acquire instruction. In addition, T2Ramsey needs delay to insert artificial rotation and the rotation angle should be computed with correct delay amount. Of course calling transpile for computing xval is too much extra computation overhead. Why just cannot
delays_dt = np.round(options.delays / self.backend.configuration().dt).astype(int)
for delay_dt in delays_dt:
delay_sec_rounded = delay_dt * self.backend.configuration().dt # used for T2Ramsey and xval
qc.delay(delay_dt, 0, "dt")Indeed this is what is done during transpilation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are still skeptical, you can call this function from terra. This is what exactly called when you transpile delays with value in sec (but warnings are super annoying).
https://github.com/Qiskit/qiskit-terra/blob/f6ab3a98ca2c8c33842e1adbf5da6fbde78dc268/qiskit/circuit/duration.py#L23-L42
Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
|
Reporting that I was able to successfully run on a device and save to the database. |
|
|
||
| circuits = [] | ||
| for delay in self.experiment_options.delays: | ||
| rotation_angle = 2 * np.pi * self.experiment_options.osc_freq * delay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to update delay here (will be delay_dt * dt_factor)
| delay = np.round(delay, decimals=10) | ||
| for delay in self.experiment_options.delays: | ||
| if dt_unit: | ||
| real_delay_in_sec = delay_dt * dt_factor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like delay_dt is used before assignment. how is this test passed? seems like we are testing only on the backend without dt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is how we test, but I always run on a device and look at the results, so I can't explain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I can explain: I've had other, unrelated problems with T2Ramsey-on-device lately, in the main branch, I think I opened issues. So I didn't run.
| ram_x = self._pre_circuit() | ||
| ram_x.sx(0) | ||
| ram_x.delay(p_delay, 0, self.experiment_options.unit) | ||
| ram_x.delay(p_delay, 0, "s") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please also update this in the same way with t2ramsey?
nkanazawa1989
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @yaelbh I'll approve with update of RamseyXY.
|
This is API change and should be merged in 0.2. Any update? @yaelbh ? I found that we should set delay in units "dt" rather than "s" for T1, T2Ramsey, RamseyXY to avoid annoying user warning. Could you please update the logic? |
|
@nkanazawa1989 I haven't tested on device yet (I'm going to do it now) but essentially it's ready. In ramsey xy I had to work with two parameters because |
nkanazawa1989
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Yael. Code looks good to me. Probably we need to implement some logic to allow typecast of Parameter in future (I had same problem when I write CR ham tomo).
* dt units in cr_hamiltonian * updated characterization experiments * t1 tests * t2ramsey test * cr hamiltonian tests * Ramsey XY tests * black * lint * fixed ramsey xy test * Hz * black * lint * updated t1 tutorial * lint * fixed tests * t1 tutorial again (nicer execution count) * updated t2 ramsey tutorial * more update to t2ramsey tutorial * fixed analysis option in qubit spectro * release notes * Update qiskit_experiments/library/calibration/rough_frequency.py Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com> * Update releasenotes/notes/remove-units-78db311686213a58.yaml Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com> * update xval to the true value following transpilation and conversion to dt * round dts * fixed rotation angle in t2ramsey * bug fix in t2ramsey * resolved conflict * ramsey_xy * transpile options for ramsey xy Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

Users will not be able to determine the units of their input parameters. When it comes to time units, pulse widths will be in dt, and delays as in T1 and T2 will be in seconds.