Conversation
There was a problem hiding this comment.
@1ucian0 Need clarification on some colors.
Gate Previous New
cx Blue DarkBlue
ccx Purple DarkBlue
mcx Purple ?
swap Blue DarkBlue
cswap Purple DarkBlue
ccswap Purple ?
dcx Blue ?
iswap Blue ?
What about u and p?
I assume all controlled versions of t, s, sdg, and tdg will be DarkRed?
I also assume all other gates - custom to_gates, isometry, diagonal, gms, etc., etc. will be DarkRed?
Thanks.
qiskit/visualization/matplotlib.py
Outdated
| # ccx gates | ||
| elif isinstance(op.op, ControlledGate) and op.name == 'ccx': | ||
| num_ctrl_qubits = op.op.num_ctrl_qubits | ||
| self._set_ctrl_bits(op.op.ctrl_state, num_ctrl_qubits, | ||
| q_xy, ec=ec, tc=tc, text=ctrl_text, qargs=op.qargs) | ||
| self._x_tgt_qubit(q_xy[num_ctrl_qubits+1], ec=ec, | ||
| ac=self._style.dispcol['target']) | ||
| self._line(qreg_b, qreg_t, lc=lc) | ||
|
|
There was a problem hiding this comment.
I don't believe this elif is necessary. The ccx is covered by the base_name == 'x' elif above it.
There was a problem hiding this comment.
If I don't specifically add the elif here, the color would be in dark red instead of dark blue (please check the reference in #5032). The present version doesn't handle this scenario either, i.e. >=2 controlled qubit, the color is different from colors defined for swap and cx
There was a problem hiding this comment.
I see you added ccx to dispcol in qcstyle. This should take care of the color. I haven't run your code yet, but when I add it in to qcstyle with a different color using the master version, the color changes in the display output.
qiskit/visualization/matplotlib.py
Outdated
| elif op.name != 'swap' and base_name == 'swap': | ||
| elif op.name == 'cswap': |
There was a problem hiding this comment.
This will not cover swap gates with more than one control, like ccswap, so should go back to original.
There was a problem hiding this comment.
Yeah. I also figured this problem. The current version also doesn't cover for cases with more than 1 controlling qubit. Since the original problem asked for colors change only, I modified the code to match it up with IQX reference. Should we create a different issue for it?
There was a problem hiding this comment.
I understand why you did it, but we have to be careful we don't lose functionality. Adding a separate elif would be better. I left a comment on the original issue. I feel like we're working with an incomplete spec.
There was a problem hiding this comment.
The specifications are complete, see the comment below: #5063 (comment)
I have no opinion here. @nonhermitian ? |
|
@enavarro51 @1ucian0 here's an overview of the colors: https://quantum-computing.ibm.com/docs/iqx/operations-glossary. Classical gates are dark blue, this includes also MCX and DCX, since they are also a classical operation. So here's the overview again, including the gates @enavarro51 mentioned above: Classical: Dark blue Phase gates: Cyan Hadamard: Red Non-unitary: Grey Other: Dark red In principle, controlled versions of the phase gates should also be cyan as controlling a diagonal gates is still diagonal. But this might be a little more complicated to do and we can stick to just making the single qubit ones cyan for now and the controlled versions have the default red. |
I don't think this makes a lot of sense, it'll just duplicate the work and we'll be only able to merge one 🤔 |
qiskit/visualization/qcstyle.py
Outdated
| basis_color = '#FA74A6' # Red | ||
| clifford_color = '#6FA4FF' # Blue | ||
| iden_color = '#05BAB6' # Green | ||
|
|
||
| hadamard_color = '#DC143C' # Red | ||
| classical_gate_color = '#000080' # Dark Blue | ||
| phase_gate_color = '#1E90FF' # Light Blue | ||
| non_unitary_gate_color = '#808080' # Grey | ||
| other_color = '#99004C' # Dark Red |
There was a problem hiding this comment.
These are the official color codes, could you update these?
classical: #002D9C
phase: #33B1FF
hadamard: #FA4D56
quantum: #9F1853
non-unitary: #A8A8A8
qiskit/visualization/matplotlib.py
Outdated
| gt = self._style.lc | ||
| else: | ||
| gt = self._style.gt | ||
| if op.name not in {'h', 't', 's', 'z', 'sdg', 'tdg', 'u1', 'reset', 'meas', 'measure'}: | ||
| gt = self._style.not_gate_lc | ||
| self._style.sc = self._style.not_gate_lc | ||
| else: | ||
| gt = self._style.gt | ||
| self._style.sc = self._style.lc |
There was a problem hiding this comment.
The text colors should not be hardcoded in matplotlib.py but should be a dictionary in the Style class like the gate color. Otherwise we won't be able to use different style sheets that use different combinations of gate and text color.
There was a problem hiding this comment.
Understood. I'll fix it
|
@Cryoris Thanks for the great info. This clarifies a lot. |
|
I have a proposal that will get us well on the way to a true user-defined colormap/style sheet and can be done as an extension of this PR. There already exists a rudimentary style sheet idea in the mpl drawer, but it is incomplete and buggy. In fact, I'm relatively sure there is nobody using the style capability for 'displaycolor' since it would only work if they knew the source and knew one specific way to set it up. It would be fairly easy to make the 'displaycolor' option available to users. In addition there is a user-configurable selection in the settings.conf file for 'circuit_mpl_style', but the only option that works in the mpl code is 'default', which is what you would get anyway. So I think we should add 'original' - for current colors, 'iqx' - for the new iqx color map, and 'bw' for black & white. Then we just need 3 style classes in qcstyle to do it all. Also there is an issue with font color, since there are a lot of border cases where black or white could both work, so I'd like to make the dispcol value a (color, font_color) tuple which would make the qcstyle code much easier to maintain. Unlike the old version of mpl, which had 35 references to dispcol, the new version has 3 (pat myself on the back :)), so updating this in mpl would be easy as well, and can be made backward compatible, in case anyone was using the 'displaycolor' option. This would be phase 1 on the path to full user colormap definition. It would,
Phase 2 would create a location for colormaps, maybe .qiskit, and let users build whatever they wanted and import somehow into mpl, either as an import or a file read. I'm happy to work with @galeinston on this. It really should be fairly straightforward. |
|
I like the idea of 3 color styles and how @enavarro51 planned out to make it work. It's be my pleasure to work on the proposed extension. |
FWIW, we do try to document the style sheet
I agree with this, instead of changing the default this PR should be adding a 3rd
I think this last point might be out of scope for this PR. I'm assuming by this you're talking about doing something like: and instead of the current behavior where only hadamard gates would have a color set, it changes the default color in the configured style sheet to use the fuschia for hadmard and everything remains the same. We should do this piece separately because there are backwards compat implications for changing this behavior. We can quickly add a new stylesheet to the drawer for the iqx theme (and fix the font color thing as you described) without this piece.
My thinking on this was to either do it one of 2 ways:
[mpl_stylesheets]
custom1 = ~/custom_mpl_style.json
custom2 = ~/special_mpl_style.jsonI'm leaning more towards the later, because it also gives us this flexibility for more easily distinguishing style sheets between the mpl circuit drawer, the pulse drawer (and possibly the mpl state visualizations too). The pulse visualizer has the same kind of style sheets as the circuit drawer and whatever we expose for the circuit drawer we're also going to want to work for the pulse visualizer too. |
Using 'default' is fine.
There actually is not a backwards compat problem here. Someone can currently do what you show above, but if they put an 'x' gate in the circuit, the drawer would crash. The 'displaycolor' dict currently has to have an entry for every gate that's used. Not sure anybody really knows that. What I'm proposing is doing the same thing, but not crashing. As you say, this would then change the 'h' color and leave all the rest the same. Don't think we need to worry about backwards compat if the previous behavior was a crash. And making the (color, font_color) tuple can be backwards compat as well by checking if the value for 'h' is a string or tuple in the code. If a string, use the color and make the font_color either the default or what the user has defined in the style dict. All of this will require some doc changes, of course. As to the phase 2, what you suggest looks fine and making it compatible with the pulse drawer would be great. Once this PR is done, we can create a new issue for phase 2. |
|
@galeinston Are you on qiskit Slack? |
|
Yup. I'm on Slack |
|
Following @1ucian0 suggestion in #4544,I made this binder to test the MPL. I believe this link is still valid even after @enavarro51 and I update the code based on #5063 (comment) and #5063 (comment) |
@Cryoris Just one more check. What about sx and sxdg. Are these phase gates? Thanks. |
|
@galeinston Make sure to update the refs in /test/ipynb/mpl/references to match your gate colors. Or else you will have failing binder tests. |
abhobe
left a comment
There was a problem hiding this comment.
Here are some small changes.
qiskit/visualization/matplotlib.py
Outdated
| gt = self._style.lc | ||
| else: | ||
| gt = self._style.gt | ||
| if op.name not in {'h', 't', 's', 'z', 'sdg', 'tdg', 'u1', 'r', 'reset', 'meas', 'measure'}: |
There was a problem hiding this comment.
| if op.name not in {'h', 't', 's', 'z', 'sdg', 'tdg', 'u1', 'r', 'reset', 'meas', 'measure'}: | |
| if op.name not in {'h', 't', 's', 'z', 'sdg', 'tdg', 'u1', 'reset', 'meas', 'measure'}: |
I think r should be removed because it seems like its a quantum gate which needs a white font.
@enavarro51 SX and SXdg should be red, their matrix representation is not diagonal. I updated the list above 👍 |
@Cryoris Some (hopefully) last questions on colors.
|
|
@Cryoris I also have a question regarding the R-gate (as shown in the picture). I can't find it neither in Circuit Library document nor in IQX page, can you clarify if this gate has been deprecated/deleted? |
|
We've made the following changes in this PR.
Phase 2 for the future,
|


Summary
Fixes #5032
Details and comments
Modified background colors of operational gates and their font text colors to match with IQX colors as suggested by @1ucian0 in the original issue.