/// <summary> /// Execute this inital mapping algorithm. /// </summary> /// <param name="architecture"> The architecture to find a mapping for. </param> /// <param name="circuit"> The circuit containing the qubits to map. </param> /// <returns> /// The best <see cref="Mapping"/> which has been found by the initial mapping algorithm. /// </returns> public abstract (Mapping, double) Execute(Architecture architecture, LogicalCircuit circuit);
public static double GetMappingCost(Mapping mapping, Architecture architecture, LogicalCircuit circuit) { // Parameters to calculate the weight of each gate double p1 = circuit.NbCnotGates / Math.Min(circuit.NbGates, MAX_NB_GATES_IN_COST); double p2 = 0.1; double cost = 0; int NbOfGatesLookedAt = 0; for (int i = 0; i < circuit.NbCnotGates; i++) { double weight = 1 / (++NbOfGatesLookedAt / p1 + p2); if (circuit.Gates[i] is CNOT) { cost += architecture.GetCost(mapping.Map[((CNOT)circuit.Gates[i]).GetControlQubit()], mapping.Map[((CNOT)circuit.Gates[i]).GetTargetQubit()]); } if (NbOfGatesLookedAt > MAX_NB_GATES_IN_COST) { return(cost); } } return(cost); }
/// <summary> /// Initialise a new dependency graph with given gates and dependencies. /// </summary> /// <param name="executeBefore"> The dependencies of gates to execute before. </param> /// <param name="executeAfter"> The dependencies of gates to execute after. </param> /// <param name="circuit"> The logical circuit this dependency graph should refer to. </param> public DependencyGraph(List <List <int> > executeBefore, List <List <int> > executeAfter, LogicalCircuit circuit) { ExecuteBefore = executeBefore; ExecuteAfter = executeAfter; Circuit = circuit; }