def get_output(self): """Returns the generated circuit.""" if not self._is_circuit_valid(): raise BackendError( "Invalid circuit! Please check the syntax of your circuit." "Has the Qasm parsing been called?. e.g: unroller.execute().") return self.circuit
def start_gate(self, name, args, qubits, nested_scope=None, extra_fields=None): if self.listen and name not in self.basis \ and self.gates[name]["opaque"]: raise BackendError("opaque gate %s not in basis" % name) if self.listen and name in self.basis: self.in_gate = name self.listen = False qubit_indices = [ self._qubit_order_internal.get(qubit) for qubit in qubits ] gate_instruction = { 'name': name, # TODO: keep these real for now, until a later time 'params': list(map(lambda x: float(x.real(nested_scope)), args)), 'texparams': list( map(lambda x: x.latex(prec=8, nested_scope=nested_scope), args)), 'qubits': qubit_indices, } if extra_fields is not None: gate_instruction.update(extra_fields) self.circuit['instructions'].append(gate_instruction) self._add_condition()
def start_gate(self, op, qargs, extra_fields=None): """ Begin a custom gate. Args: op (Instruction): operation to apply to the dag. qargs (list[QuantumRegister, int]): qubit arguments extra_fields (dict): extra_fields used by non-standard instructions for now (e.g. snapshot) Raises: BackendError: if using a non-basis opaque gate """ if not self.listen: return if op.name not in self.basis and self.gates[op.name]["opaque"]: raise BackendError("opaque gate %s not in basis" % op.name) if op.name in self.basis: self.in_gate = op self.listen = False qubit_indices = [ self._qubit_order_internal.get((qubit[0].name, qubit[1])) for qubit in qargs ] clbit_indices = [ self._cbit_order_internal.get((cbit[0].name, cbit[1])) for cbit in op.cargs ] gate_instruction = { 'name': op.name, 'params': list(map(lambda x: x.evalf(), op.param)), 'texparams': list(map(sympy.latex, op.param)), 'qubits': qubit_indices, 'clbits': clbit_indices, 'memory': clbit_indices.copy() } if extra_fields is not None: gate_instruction.update(extra_fields) self.circuit['instructions'].append(gate_instruction) self._add_condition()