def test_parameterized_op(self, mocker): """Tests job attribute several parameterized operations.""" def mock_submit_job(*args): pass mocker.patch("pennylane_ionq.device.IonQDevice._submit_job", mock_submit_job) dev = IonQDevice(wires=(0, )) with qml.tape.QuantumTape() as tape: qml.RX(1.2345, wires=0) qml.RY(qml.numpy.array(2.3456), wires=0) dev.apply(tape.operations) assert dev.job["lang"] == "json" assert dev.job["body"]["qubits"] == 1 assert len(dev.job["body"]["circuit"]) == 2 assert dev.job["body"]["circuit"][0] == { "gate": "rx", "target": 0, "rotation": 1.2345 } assert dev.job["body"]["circuit"][1] == { "gate": "ry", "target": 0, "rotation": 2.3456 }
def test_emptycircuit_warning(self, mocker): """Test warning raised on submission of an empty circuit.""" def mock_submit_job(*args): pass mocker.patch("pennylane_ionq.device.IonQDevice._submit_job", mock_submit_job) dev = IonQDevice(wires=(0, )) with pytest.warns(UserWarning, match=r"Circuit is empty."): dev.apply([])
def test_failedcircuit(self, monkeypatch): monkeypatch.setattr( requests, "post", lambda url, timeout, data, headers: (url, data, headers)) monkeypatch.setattr(ResourceManager, "handle_response", lambda self, response: None) monkeypatch.setattr(Job, "is_complete", False) monkeypatch.setattr(Job, "is_failed", True) dev = IonQDevice(wires=(0, )) with pytest.raises(JobExecutionError): dev._submit_job()
def test_nonparametrized_tape(self, mocker): """Tests job attribute after single paulix tape.""" def mock_submit_job(*args): pass mocker.patch("pennylane_ionq.device.IonQDevice._submit_job", mock_submit_job) dev = IonQDevice(wires=(0, )) with qml.tape.QuantumTape() as tape: qml.PauliX(0) dev.apply(tape.operations) assert dev.job["lang"] == "json" assert dev.job["body"]["qubits"] == 1 assert len(dev.job["body"]["circuit"]) == 1 assert dev.job["body"]["circuit"][0] == {"gate": "x", "target": 0}
def test_parameterized_native_op(self, mocker): """Tests job attribute several parameterized native operations.""" def mock_submit_job(*args): pass mocker.patch("pennylane_ionq.device.IonQDevice._submit_job", mock_submit_job) dev = IonQDevice(wires=(0, 1, 2), gateset="native") with qml.tape.QuantumTape() as tape: GPI(0.1, wires=[0]) GPI2(0.2, wires=[1]) MS(0.2, 0.3, wires=[1, 2]) assert dev.job["lang"] == "json" assert dev.job["body"]["gateset"] == "native" assert dev.job["body"]["qubits"] == 3 dev.apply(tape.operations) assert len(dev.job["body"]["circuit"]) == 3 assert dev.job["body"]["circuit"][0] == { "gate": "gpi", "target": 0, "phase": 0.1, } assert dev.job["body"]["circuit"][1] == { "gate": "gpi2", "target": 1, "phase": 0.2, } assert dev.job["body"]["circuit"][2] == { "gate": "ms", "targets": [1, 2], "phases": [0.2, 0.3], }