Skip to content
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

[cirq_web 3D circuit] X**0.5 and Y**0.5 look the same as X and Y #4761

Closed
balopat opened this issue Dec 18, 2021 · 1 comment · Fixed by #4777
Closed

[cirq_web 3D circuit] X**0.5 and Y**0.5 look the same as X and Y #4761

balopat opened this issue Dec 18, 2021 · 1 comment · Fixed by #4777
Labels
kind/bug-report Something doesn't seem to work.

Comments

@balopat
Copy link
Contributor

balopat commented Dec 18, 2021

Description of the issue

The default look for X**0.5 and Y**0.5 look the same as X and Y in the 3D circuit.

How to reproduce the issue

import cirq_web
a, b, c, d = cirq.GridQubit.rect(2, 2)
cirq_web.Circuit3D(cirq.Circuit(cirq.X(a)**0.5, cirq.Y(b)**0.5, cirq.X(c), cirq.Y(d))).generate_html_file(
    file_name="hello.html")

image

Cirq version
You can get the cirq version by printing cirq.__version__. From the command line:

0.13.1

@balopat balopat added the kind/bug-report Something doesn't seem to work. label Dec 18, 2021
@yjt98765
Copy link
Contributor

The problem is that the symbols on the boxes are generated entirely based on wire_symbols:

def _build_3D_symbol(self, operation, moment) -> Operation3DSymbol:
symbol_info = resolve_operation(operation, self._resolvers)
location_info = []
for qubit in operation.qubits:
location_info.append({'row': qubit.row, 'col': qubit.col})
return Operation3DSymbol(symbol_info.labels, location_info, symbol_info.colors, moment)

As a comparison, the text representation of a circuit also consider the exponent:

# Print gate qubit labels.
symbols = info._wire_symbols_including_formatted_exponent(
args,
preferred_exponent_index=max(range(len(labels)), key=lambda i: label_map[labels[i]]),
)
for s, q in zip(symbols, labels):
out_diagram.write(x, label_map[q], s)

May I be assigned with this issue? I guess cirq-web can generally follow the same pattern.

CirqBot pushed a commit that referenced this issue Jan 4, 2022
This pull request fixes the bug reported in #4761. The exponents of gates are not reflected in the labels of 3D circuits. This PR adds it using `CircuitDiagramInfo._wire_symbols_including_formatted_exponent`, which has been used in the generation of the text circuit diagrams.

Another problem raises after the exponents are added. The color of the `X` gate is chosen as black, and the label's color is also black. As a result, the label cannot be recognized. To solve this problem, I set the label's color according to the brightness of the gate color. If it is dark (e.g., in the case of black), white is picked for the label. The color parameter for `MeshBasicMaterial` has also to be changed to avoid shadowing the label.

After the modification, the test case used in the #4761
```
import cirq_web
a, b, c, d = cirq.GridQubit.rect(2, 2)
cirq_web.Circuit3D(cirq.Circuit(cirq.X(a)**0.5, cirq.Y(b)**0.5, cirq.X(c), cirq.Y(d))).generate_html_file(
    file_name="hello.html")
```
generates this circuit:

![image](https://user-images.githubusercontent.com/14125945/147078537-f668e05f-0fc0-419b-ab67-794ebe3b9527.png)

close #4761
MichaelBroughton pushed a commit to MichaelBroughton/Cirq that referenced this issue Jan 22, 2022
This pull request fixes the bug reported in quantumlib#4761. The exponents of gates are not reflected in the labels of 3D circuits. This PR adds it using `CircuitDiagramInfo._wire_symbols_including_formatted_exponent`, which has been used in the generation of the text circuit diagrams.

Another problem raises after the exponents are added. The color of the `X` gate is chosen as black, and the label's color is also black. As a result, the label cannot be recognized. To solve this problem, I set the label's color according to the brightness of the gate color. If it is dark (e.g., in the case of black), white is picked for the label. The color parameter for `MeshBasicMaterial` has also to be changed to avoid shadowing the label.

After the modification, the test case used in the quantumlib#4761
```
import cirq_web
a, b, c, d = cirq.GridQubit.rect(2, 2)
cirq_web.Circuit3D(cirq.Circuit(cirq.X(a)**0.5, cirq.Y(b)**0.5, cirq.X(c), cirq.Y(d))).generate_html_file(
    file_name="hello.html")
```
generates this circuit:

![image](https://user-images.githubusercontent.com/14125945/147078537-f668e05f-0fc0-419b-ab67-794ebe3b9527.png)

close quantumlib#4761
rht pushed a commit to rht/Cirq that referenced this issue May 1, 2023
This pull request fixes the bug reported in quantumlib#4761. The exponents of gates are not reflected in the labels of 3D circuits. This PR adds it using `CircuitDiagramInfo._wire_symbols_including_formatted_exponent`, which has been used in the generation of the text circuit diagrams.

Another problem raises after the exponents are added. The color of the `X` gate is chosen as black, and the label's color is also black. As a result, the label cannot be recognized. To solve this problem, I set the label's color according to the brightness of the gate color. If it is dark (e.g., in the case of black), white is picked for the label. The color parameter for `MeshBasicMaterial` has also to be changed to avoid shadowing the label.

After the modification, the test case used in the quantumlib#4761
```
import cirq_web
a, b, c, d = cirq.GridQubit.rect(2, 2)
cirq_web.Circuit3D(cirq.Circuit(cirq.X(a)**0.5, cirq.Y(b)**0.5, cirq.X(c), cirq.Y(d))).generate_html_file(
    file_name="hello.html")
```
generates this circuit:

![image](https://user-images.githubusercontent.com/14125945/147078537-f668e05f-0fc0-419b-ab67-794ebe3b9527.png)

close quantumlib#4761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug-report Something doesn't seem to work.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants