Skip to content

Commit

Permalink
Fix Quirk import extra gates bug
Browse files Browse the repository at this point in the history
  • Loading branch information
matpompili committed Jun 12, 2020
1 parent d3ce7cc commit c866d23
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cirq/interop/quirk/url_to_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ def msg(error):
# Collect registry of quirk cell types.
if isinstance(extra_cell_makers, Mapping):
extra_makers = [
CellMaker(identifier=identifier,
size=protocols.num_qubits(gate),
maker=lambda args: gate(*args.qubits))
CellMaker(
identifier=identifier,
size=protocols.num_qubits(gate),
maker=(lambda gate: lambda args: gate(*args.qubits))(gate))
for identifier, gate in extra_cell_makers.items()
]
else:
Expand Down
26 changes: 26 additions & 0 deletions cirq/interop/quirk/url_to_circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ def test_extra_cell_makers():
extra_cell_makers={'iswap': cirq.ISWAP}) == cirq.Circuit(
cirq.ISWAP(*cirq.LineQubit.range(2)))

assert cirq.quirk_url_to_circuit(
'http://algassert.com/quirk#circuit={"cols":[["iswap"], ["toffoli"]]}',
extra_cell_makers=[
cirq.interop.quirk.cells.CellMaker(
identifier='iswap',
size=2,
maker=lambda args: cirq.ISWAP(*args.qubits)),
cirq.interop.quirk.cells.CellMaker(
identifier='toffoli',
size=3,
maker=lambda args: cirq.TOFFOLI(*args.qubits))
]) == cirq.Circuit([
cirq.ISWAP(*cirq.LineQubit.range(2)),
cirq.TOFFOLI(*cirq.LineQubit.range(3))
])

assert cirq.quirk_url_to_circuit(
'http://algassert.com/quirk#circuit={"cols":[["iswap"], ["toffoli"]]}',
extra_cell_makers={
'iswap': cirq.ISWAP,
'toffoli': cirq.TOFFOLI
}) == cirq.Circuit([
cirq.ISWAP(*cirq.LineQubit.range(2)),
cirq.TOFFOLI(*cirq.LineQubit.range(3))
])


def test_init():
b, c, d, e, f = cirq.LineQubit.range(1, 6)
Expand Down

0 comments on commit c866d23

Please sign in to comment.