def test_qasm_from_file(self, tmpdir, recorder): """Tests that a QuantumCircuit object is deserialized from a qasm file.""" qft_qasm = tmpdir.join("qft.qasm") with open(qft_qasm, "w") as f: f.write(TestConverterQasm.qft_qasm) quantum_circuit = load_qasm_from_file(qft_qasm) with pytest.warns(UserWarning) as record: with recorder: quantum_circuit() assert len(recorder.queue) == 6 assert recorder.queue[0].name == 'PauliX' assert recorder.queue[0].params == [] assert recorder.queue[0].wires == [0] assert recorder.queue[1].name == 'PauliX' assert recorder.queue[1].params == [] assert recorder.queue[1].wires == [2] assert recorder.queue[2].name == 'Hadamard' assert recorder.queue[2].params == [] assert recorder.queue[2].wires == [0] assert recorder.queue[3].name == 'Hadamard' assert recorder.queue[3].params == [] assert recorder.queue[3].wires == [1] assert recorder.queue[4].name == 'Hadamard' assert recorder.queue[4].params == [] assert recorder.queue[4].wires == [2] assert recorder.queue[5].name == 'Hadamard' assert recorder.queue[5].params == [] assert recorder.queue[5].wires == [3] assert len(record) == 11 # check that the message matches assert record[0].message.args[0] == "pennylane_qiskit.converter: The {} instruction is not supported by" \ " PennyLane, and has not been added to the template."\ .format('Barrier') assert record[1].message.args[0] == "pennylane_qiskit.converter: The {} instruction is not supported by" \ " PennyLane, and has not been added to the template."\ .format('CU1Gate') assert record[7].message.args[0] == "pennylane_qiskit.converter: The {} instruction is not supported by" \ " PennyLane, and has not been added to the template."\ .format('Measure')
def test_qasm_from_file(self, tmpdir, recorder): """Tests that a QuantumCircuit object is deserialized from a qasm file.""" qft_qasm = tmpdir.join("qft.qasm") with open(qft_qasm, "w") as f: f.write(TestConverterQasm.qft_qasm) quantum_circuit = load_qasm_from_file(qft_qasm) with pytest.warns(UserWarning) as record: with recorder: quantum_circuit() assert len(recorder.queue) == 6 assert recorder.queue[0].name == "PauliX" assert recorder.queue[0].parameters == [] assert recorder.queue[0].wires == Wires([0]) assert recorder.queue[1].name == "PauliX" assert recorder.queue[1].parameters == [] assert recorder.queue[1].wires == Wires([2]) assert recorder.queue[2].name == "Hadamard" assert recorder.queue[2].parameters == [] assert recorder.queue[2].wires == Wires([0]) assert recorder.queue[3].name == "Hadamard" assert recorder.queue[3].parameters == [] assert recorder.queue[3].wires == Wires([1]) assert recorder.queue[4].name == "Hadamard" assert recorder.queue[4].parameters == [] assert recorder.queue[4].wires == Wires([2]) assert recorder.queue[5].name == "Hadamard" assert recorder.queue[5].parameters == [] assert recorder.queue[5].wires == Wires([3])
def test_qasm_file_not_found_error(self): """Tests that an error is propagated, when a non-existing file is specified for parsing.""" qft_qasm = "some_qasm_file.qasm" with pytest.raises(FileNotFoundError): load_qasm_from_file(qft_qasm)