def cbs(filename, configuration): revkit.read_aiger(filename=filename) num_outputs = revkit.ps(aig=True, silent=True)["outputs"] synthesis = revkit.cbs(**configuration).dict() # update costs for Qubits and T-count for Bennett trick circuit = revkit.ps(circuit=True, silent=True).dict() circuit["qubits"] += num_outputs circuit["tcount"] *= 2 revkit.store(clear=True, aig=True, circuit=True) return synthesis, circuit
def lhrs(filename, configuration): revkit.read_aiger(filename=filename) synthesis = revkit.lhrs(**configuration).dict() circuit = revkit.ps(circuit=True, silent=True).dict() revkit.store(clear=True, aig=True, circuit=True) return synthesis, circuit
def dxs(filename, configuration): revkit.read_aiger(filename=filename) revkit.xmglut(lut_size=4) synthesis = revkit.dxs(**configuration).dict() circuit = revkit.ps(circuit=True, silent=True).dict() revkit.store(clear=True, aig=True, circuit=True, xmg=True) return synthesis, circuit
def hdbs(filename, configuration): revkit.read_aiger(filename=filename) num_outputs = revkit.ps(aig=True, silent=True)["outputs"] # also incorporate conversion to BDD to the runtime start = timer() revkit.convert(aig_to_bdd=True) synthesis = revkit.hdbs(**configuration).dict() end = timer() synthesis["runtime"] = end - start # update costs for Qubits and T-count for Bennett trick circuit = revkit.ps(circuit=True, silent=True).dict() circuit["qubits"] += num_outputs circuit["tcount"] *= 2 revkit.store(clear=True, aig=True, circuit=True, bdd=True) return synthesis, circuit
def __or__(self, qubits): """ Apply control function to qubits (and synthesizes circuit). Args: qubits (tuple<Qureg>): Qubits to which the control function is being applied. The first `n` qubits are for the controls, the last qubit is for the target qubit. """ try: import revkit # pylint: disable=import-outside-toplevel except ImportError as err: # pragma: no cover raise RuntimeError( "The RevKit Python library needs to be installed and in the " "PYTHONPATH in order to call this function") from err # pylint: disable=invalid-name # convert qubits to tuple qs = [] for item in BasicGate.make_tuple_of_qureg(qubits): qs += item if isinstance(item, list) else [item] # function truth table cannot be larger than number of control qubits # allow if 2**(2**(len(qs) - 1)) <= self.function: raise AttributeError( "Function truth table exceeds number of control qubits") # create truth table from function integer hex_length = max(2**(len(qs) - 1) // 4, 1) revkit.tt(table="{0:#0{1}x}".format(self.function, hex_length)) # create reversible circuit from truth table self.kwargs.get("synth", revkit.esopbs)() # check whether circuit has correct signature if revkit.ps(mct=True, silent=True)['qubits'] != len(qs): raise RuntimeError( "Generated circuit lines does not match provided qubits") # convert reversible circuit to ProjectQ code and execute it _exec(revkit.to_projectq(mct=True), qs)