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 supports LineQubits #5211

Merged
merged 9 commits into from
Apr 6, 2022
7 changes: 6 additions & 1 deletion cirq-web/cirq_web/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,10 @@ 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})
if isinstance(qubit, cirq.GridQubit):
location_info.append({'row': qubit.row, 'col': qubit.col})
elif isinstance(qubit, cirq.LineQubit):
location_info.append({'row': qubit.x, 'col': 0})
else:
raise ValueError('Unsupported qubit type')
return Operation3DSymbol(symbol_info.labels, location_info, symbol_info.colors, moment)
16 changes: 13 additions & 3 deletions cirq-web/cirq_web/circuits/circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import cirq
import cirq_web

import pytest


def strip_ws(string):
return "".join(string.split())
Expand All @@ -28,9 +30,9 @@ def test_circuit_init_type():
assert isinstance(circuit3d, cirq_web.Circuit3D)


def test_circuit_client_code():
qubits = [cirq.GridQubit(x, y) for x in range(2) for y in range(2)]
moment = cirq.Moment(cirq.H(qubits[0]))
@pytest.mark.parametrize('qubit', [cirq.GridQubit(0, 0), cirq.LineQubit(0)])
def test_circuit_client_code(qubit):
moment = cirq.Moment(cirq.H(qubit))
circuit = cirq_web.Circuit3D(cirq.Circuit(moment))

circuit_obj = [
Expand Down Expand Up @@ -64,6 +66,14 @@ def test_circuit_client_code():
assert strip_ws(circuit.get_client_code()) == strip_ws(expected_client_code)


def test_circuit_client_code_unsupported_qubit_type():
moment = cirq.Moment(cirq.H(cirq.NamedQubit('q0')))
circuit = cirq_web.Circuit3D(cirq.Circuit(moment))

with pytest.raises(ValueError, match='Unsupported qubit type'):
circuit.get_client_code()


def test_circuit_default_bundle_name():
qubits = [cirq.GridQubit(x, y) for x in range(2) for y in range(2)]
moment = cirq.Moment(cirq.H(qubits[0]))
Expand Down