def test_simulator_flush(): from hiq.projectq.backends import SimulatorMPI sim = SimulatorMPI() sim._simulator = MockSimulatorBackend() eng = MainEngine(sim) eng.flush() assert sim._simulator.run_cnt == 1
def get_hiq_quantum_engine(): from hiq.projectq.backends import SimulatorMPI backend = SimulatorMPI(gate_fusion=True) cache_depth = 10 rule_set = DecompositionRuleSet(modules=[projectq.setups.decompositions]) engines = [TagRemover(), LocalOptimizer(cache_depth), AutoReplacer(rule_set)] compiler_engine = MainEngine(backend=backend, engine_list=engines) return compiler_engine return
def test_simulator_send(): from hiq.projectq.backends import SimulatorMPI sim = SimulatorMPI() backend = DummyEngine(save_commands=True) eng = MainEngine(backend, [sim]) qubit = eng.allocate_qubit() H | qubit Measure | qubit del qubit eng.flush() assert len(backend.received_commands) == 5
p = num.index(1) a1 = a1 - 1 num[p] = 0 X | x[p] def _is_power2(num): """ Checks whether a given number is a power of two """ return num != 0 and ((num & (num - 1)) == 0) if __name__ == "__main__": # create a main compiler engine with a simulator backend: backend = SimulatorMPI(gate_fusion=True, num_local_qubits=20) # backend = CircuitDrawer() # locations = {} # for i in range(module.nqubits): # locations[i] = i # backend.set_qubit_locations(locations) cache_depth = 10 rule_set = DecompositionRuleSet(modules=[projectq.setups.decompositions]) engines = [ TagRemover(), LocalOptimizer(cache_depth), AutoReplacer(rule_set), TagRemover(), LocalOptimizer(cache_depth), #,CommandPrinter(),
from mpi4py import MPI def adiabatic_simulation(eng): """The function you need to modify. Returns: real_energy(float): The final ideally continously evolved energy. simulated_energy(float): The final energy simulated by your model. """ simulated_energy = 0 real_energy = 0 return simulated_energy, real_energy if __name__ == "__main__": # use projectq simulator #eng = MainEngine() # use hiq simulator backend = SimulatorMPI(gate_fusion=True) cache_depth = 10 rule_set = DecompositionRuleSet(modules=[projectq.setups.decompositions]) engines = [TagRemover() , LocalOptimizer(cache_depth) , AutoReplacer(rule_set) , TagRemover() , LocalOptimizer(cache_depth) , GreedyScheduler() ] # make the compiler and run the circuit on the simulator backend eng = HiQMainEngine(backend, engines) simulated_energy, real_energy = adiabatic_simulation(eng) simulated_error = simulated_energy - real_energy print(simulated_error)
def sim(request): if request.param == "hiq_simulator_mpi": from hiq.projectq.backends import SimulatorMPI sim = SimulatorMPI(gate_fusion=True) return sim
resource_counter = ResourceCounter() rule_set = DecompositionRuleSet( modules=[projectq.libs.math, projectq.setups.decompositions]) compilerengines = [ AutoReplacer(rule_set), InstructionFilter(high_level_gates), TagRemover(), LocalOptimizer(3), AutoReplacer(rule_set), TagRemover(), LocalOptimizer(3), GreedyScheduler(), resource_counter ] # make the compiler and run the circuit on the simulator backend eng = HiQMainEngine(SimulatorMPI(gate_fusion=True, num_local_qubits=20), compilerengines) N = 0 if MPI.COMM_WORLD.Get_rank() == 0: # print welcome message and ask the user for the number to factor print( "\n\t\033[37mH\033[91mI\033[37mQ\033[91m>\033[0m\n\t--------\n\tImplementation of Shor" "\'s algorithm.", end="") N = int(input('\n\tNumber to factor: ')) print("") N = MPI.COMM_WORLD.bcast(N, root=0) print("\tFactoring N = {}: \033[0m".format(N), end="\n")