def test_three_mode(self, tol): """Test that a three mode interferometer using either mesh gives the correct gates""" N = 3 wires = range(N) dev = qml.device('default.gaussian', wires=N) theta = [0.321, 0.4523, 0.21321] phi = [0.234, 0.324, 0.234] varphi = [0.42342, 0.234, 0.1121] with qml.utils.OperationRecorder() as rec_rect: Interferometer(theta, phi, varphi, wires=wires) with qml.utils.OperationRecorder() as rec_tria: Interferometer(theta, phi, varphi, wires=wires) for rec in [rec_rect, rec_tria]: # test both meshes (both give identical results for the 3 mode case). assert len(rec.queue) == 6 expected_bs_wires = [[0, 1], [1, 2], [0, 1]] for idx, op in enumerate(rec_rect.queue[:3]): assert isinstance(op, qml.Beamsplitter) assert op.parameters == [theta[idx], phi[idx]] assert op.wires == expected_bs_wires[idx] for idx, op in enumerate(rec.queue[3:]): assert isinstance(op, qml.Rotation) assert op.parameters == [varphi[idx]] assert op.wires == [idx]
def test_clements_beamsplitter_convention(self, tol): """test the beamsplitter convention""" N = 2 wires = range(N) dev = qml.device('default.gaussian', wires=N) theta = [0.321] phi = [0.234] varphi = [0.42342, 0.1121] with qml.utils.OperationRecorder() as rec_rect: Interferometer(theta, phi, varphi, mesh='rectangular', beamsplitter='clements', wires=wires) with qml.utils.OperationRecorder() as rec_tria: Interferometer(theta, phi, varphi, mesh='triangular', beamsplitter='clements', wires=wires) for rec in [rec_rect, rec_tria]: assert len(rec.queue) == 4 assert isinstance(rec.queue[0], qml.Rotation) assert rec.queue[0].parameters == phi assert isinstance(rec.queue[1], qml.Beamsplitter) assert rec.queue[1].parameters == [theta[0], 0] assert isinstance(rec.queue[2], qml.Rotation) assert rec.queue[2].parameters == [varphi[0]] assert isinstance(rec.queue[3], qml.Rotation) assert rec.queue[3].parameters == [varphi[1]]
def circuit(varphi, mesh): Interferometer(theta=None, phi=None, varphi=varphi, mesh=mesh, wires=0) return qml.expval.MeanPhoton(0)
def circuit(varphi, mesh): Interferometer(theta=None, phi=None, varphi=varphi, mesh=mesh, wires=0) return qml.expval(qml.NumberOperator(0))
def circuit(varphi, bs=None): Interferometer(theta=[], phi=[], varphi=varphi, beamsplitter=bs, wires=0) return qml.expval(qml.NumberOperator(0))
def test_four_mode_triangular(self, tol): """Test that a 4 mode interferometer using triangular mesh gives the correct gates""" N = 4 wires = range(N) dev = qml.device('default.gaussian', wires=N) theta = [0.321, 0.4523, 0.21321, 0.123, 0.5234, 1.23] phi = [0.234, 0.324, 0.234, 1.453, 1.42341, -0.534] varphi = [0.42342, 0.234, 0.4523, 0.1121] with qml.utils.OperationRecorder() as rec: Interferometer(theta, phi, varphi, mesh='triangular', wires=wires) assert len(rec.queue) == 10 expected_bs_wires = [[2, 3], [1, 2], [0, 1], [2, 3], [1, 2], [2, 3]] for idx, op in enumerate(rec.queue[:6]): assert isinstance(op, qml.Beamsplitter) assert op.parameters == [theta[idx], phi[idx]] assert op.wires == expected_bs_wires[idx] for idx, op in enumerate(rec.queue[6:]): assert isinstance(op, qml.Rotation) assert op.parameters == [varphi[idx]] assert op.wires == [idx]
def circuit(varphi, bs): Interferometer(theta=None, phi=None, varphi=varphi, beamsplitter=bs, wires=0) return qml.expval.MeanPhoton(0)
def circuit_tria(varphi): Interferometer(theta, phi, varphi, mesh='triangular', beamsplitter='clements', wires=wires) return [qml.expval.MeanPhoton(w) for w in wires]
def circuit_tria(varphi): Interferometer(theta, phi, varphi, mesh='triangular', beamsplitter='clements', wires=wires) return [qml.expval(qml.NumberOperator(w)) for w in wires]
def test_one_mode(self, tol): """Test that a one mode interferometer correctly gives a rotation gate""" dev = qml.device('default.gaussian', wires=1) varphi = [0.42342] with qml.utils.OperationRecorder() as rec: Interferometer(theta=[], phi=[], varphi=varphi, wires=0) assert len(rec.queue) == 1 assert isinstance(rec.queue[0], qml.Rotation) assert np.allclose(rec.queue[0].parameters, varphi, atol=tol)
def test_two_mode_rect(self, tol): """Test that a two mode interferometer using the rectangular mesh correctly gives a beamsplitter+rotation gate""" N = 2 wires = range(N) dev = qml.device('default.gaussian', wires=N) theta = [0.321] phi = [0.234] varphi = [0.42342, 0.1121] with qml.utils.OperationRecorder() as rec: Interferometer(theta, phi, varphi, wires=wires) isinstance(rec.queue[0], qml.Beamsplitter) assert rec.queue[0].parameters == theta + phi assert isinstance(rec.queue[1], qml.Rotation) assert rec.queue[1].parameters == [varphi[0]] assert isinstance(rec.queue[2], qml.Rotation) assert rec.queue[2].parameters == [varphi[1]]
def circuit(theta, phi, varphi): for w in wires: qml.Squeezing(sq[w][0], sq[w][1], wires=w) Interferometer(theta, phi, varphi, wires=wires) return [qml.expval(qml.NumberOperator(w)) for w in wires]
def circuit(varphi): Interferometer(theta, phi, varphi, mesh='triangular', wires=wires) return [qml.expval(qml.NumberOperator(w)) for w in wires]
def circuit(theta, phi, varphi): for w in wires: qml.Squeezing(sq[w][0], sq[w][1], wires=w) Interferometer(theta, phi, varphi, wires=wires) return [qml.expval.MeanPhoton(w) for w in wires]
def circuit_rect(varphi): Interferometer(theta, phi, varphi, wires=wires) return [qml.expval.MeanPhoton(w) for w in wires]
def circuit(varphi): Interferometer(theta, phi, varphi, mesh='triangular', wires=wires) return [qml.expval.MeanPhoton(w) for w in wires]
def circuit_rect(varphi): Interferometer(theta, phi, varphi, wires=wires) return [qml.expval(qml.NumberOperator(w)) for w in wires]