Skip to content

Commit

Permalink
Cirq web supports LineQubits (#5211)
Browse files Browse the repository at this point in the history
This would be to fix #5173
  • Loading branch information
tonybruguier authored Apr 6, 2022
1 parent e616710 commit 5ca0b47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit 5ca0b47

Please sign in to comment.