14#ifndef _NETWORK_INTERFACE_H_
15#define _NETWORK_INTERFACE_H_
17#include <boost/container_hash/hash.hpp>
19#include <unordered_set>
55template <
typename Time = Types::time_type>
56class INetwork :
public std::enable_shared_from_this<INetwork<Time>> {
60 std::pair<Simulators::SimulatorType, Simulators::SimulationType>;
62 std::unordered_set<SimulatorPair, boost::hash<SimulatorPair>>;
128 virtual std::vector<double>
130 const std::vector<std::string> &paulis) = 0;
149 const std::vector<std::string> &paulis) = 0;
167 size_t shots = 1000) = 0;
207 size_t hostId,
size_t shots = 1000) = 0;
229 executeCircuit.
shots);
274 size_t nrQubits = 0) = 0;
284 virtual std::shared_ptr<Simulators::ISimulator>
GetSimulator()
const = 0;
295 virtual void Configure(
const char *key,
const char *value) = 0;
319 virtual std::shared_ptr<Schedulers::IScheduler<Time>>
331 virtual const std::shared_ptr<IHost<Time>>
GetHost(
size_t hostId)
const = 0;
450 size_t bitId2)
const = 0;
463 size_t bitId)
const = 0;
532 virtual std::vector<size_t>
556 virtual std::vector<size_t>
625 const std::vector<uint8_t> &packet) = 0;
691 size_t qubitId2)
const = 0;
733 std::shared_ptr<INetwork<Time>>
getptr() {
734 return std::enable_shared_from_this<INetwork<Time>>::shared_from_this();
752 virtual std::shared_ptr<INetwork<Time>>
Clone()
const = 0;
763 virtual std::shared_ptr<Circuits::Circuit<Time>>
928 virtual std::shared_ptr<Simulators::ISimulator>
930 size_t &counts,
size_t nrQubits,
size_t nrCbits,
933 std::vector<bool> &executed,
bool multithreading =
false,
934 bool dontRunCircuitStart =
false)
const = 0;
Circuit class for holding the sequence of operations.
std::unordered_map< std::vector< bool >, size_t > ExecuteResults
The results of the execution of the circuit.
The state class that stores the classical state of a quantum circuit execution.
virtual std::shared_ptr< Simulators::ISimulator > ChooseBestSimulator(const std::shared_ptr< Circuits::Circuit< Time > > &dcirc, size_t &counts, size_t nrQubits, size_t nrCbits, size_t nrResultCbits, Simulators::SimulatorType &simType, Simulators::SimulationType &method, std::vector< bool > &executed, bool multithreading=false, bool dontRunCircuitStart=false) const =0
Choose the best simulator for the given circuit.
virtual Simulators::SimulationType GetLastSimulationType() const =0
Get the last used simulation type.
virtual size_t GetNumClassicalBitsForHost(size_t hostId) const =0
Get the number of classical bits in the network for the specified host.
virtual void Execute(const std::shared_ptr< Circuits::Circuit< Time > > &circuit)=0
Execute the circuit on the network.
virtual bool IsNetworkEntangledQubit(size_t qubitId) const =0
Check if the specified qubit id is for a qubit used for entanglement between hosts.
virtual void ClearEntanglements()=0
Clear all entanglements between hosts in the network.
virtual void RemoveOptimizationSimulator(Simulators::SimulatorType type, Simulators::SimulationType kind)=0
Removes a simulator from the simulators optimization set.
virtual ExecuteResults RepeatedExecute(const std::shared_ptr< Circuits::Circuit< Time > > &circuit, size_t shots=1000)=0
Execute the circuit on the network, repeatedly.
virtual bool IsDistributedOperation(const std::shared_ptr< Circuits::IOperation< Time > > &op) const =0
Check if the circuit operation is distributed.
virtual bool ExpectsClassicalBitFromOtherHost(const std::shared_ptr< Circuits::IOperation< Time > > &op) const =0
Checks if a gate expects a classical bit from another host.
virtual bool IsLocalOperation(const std::shared_ptr< Circuits::IOperation< Time > > &op) const =0
Check if the circuit operation is local.
ExecuteResults RepeatedExecuteCircuitOnHost(const Schedulers::ExecuteCircuit< Time > &executeCircuit, size_t hostId)
Execute the circuit on the specified host, repeatedly.
virtual void SetMaxSimulators(size_t maxSimulators)=0
Set the maximum number of simulators that can be used in the network.
virtual size_t GetNumNetworkEntangledQubitsForHost(size_t hostId) const =0
Get the number of qubits used for entanglement between hosts for the specified host.
virtual size_t GetHostIdForAnyQubit(size_t qubitId) const =0
Get the host id for the specified qubit.
virtual std::vector< size_t > GetClassicalBitsIds(size_t hostId) const =0
Get the classical bit ids for the specified host.
virtual std::vector< double > ExecuteExpectations(const std::shared_ptr< Circuits::Circuit< Time > > &circuit, const std::vector< std::string > &paulis)=0
Execute the circuit on the network and return the expectation values for the specified Pauli strings.
virtual Circuits::OperationState & GetState()=0
Get the classical state of the network.
virtual std::vector< size_t > GetQubitsIds(size_t hostId) const =0
Get the qubit ids for the specified host.
ExecuteResults RepeatedExecuteCircuit(const Schedulers::ExecuteCircuit< Time > &executeCircuit)
Execute the circuit on the network, repeatedly.
virtual size_t GetNumberOfGatesDistributedOrCut(const std::shared_ptr< Circuits::Circuit< Time > > &circuit) const =0
Get the number of gates that span more than one host.
virtual ExecuteResults RepeatedExecuteOnHost(const std::shared_ptr< Circuits::Circuit< Time > > &circuit, size_t hostId, size_t shots=1000)=0
Execute the circuit on the specified host, repeatedly.
virtual bool SendPacket(size_t fromHostId, size_t toHostId, const std::vector< uint8_t > &packet)=0
Sends a packet between two hosts.
virtual size_t GetMaxSimulators() const =0
Get the maximum number of simulators that can be used in the network.
virtual bool AreQubitsOnSameHost(size_t qubitId1, size_t qubitId2) const =0
Check if the specified qubits are on the same host.
virtual ~INetwork()=default
Destroy the INetwork object.
virtual std::vector< ExecuteResults > ExecuteScheduled(const std::vector< Schedulers::ExecuteCircuit< Time > > &circuits)=0
Schedule and execute circuits on the network.
virtual size_t GetNumHosts() const =0
Get the number of hosts in the network.
virtual std::shared_ptr< Schedulers::IScheduler< Time > > GetScheduler() const =0
Get the scheduler for the network.
virtual std::vector< double > ExecuteOnHostExpectations(const std::shared_ptr< Circuits::Circuit< Time > > &circuit, size_t hostId, const std::vector< std::string > &paulis)=0
Execute the circuit on the specified host and return the expectation values for the specified Pauli s...
virtual std::shared_ptr< Simulators::ISimulator > GetSimulator() const =0
Get the simulator for the network.
virtual bool AreEntanglementQubitsBusy(size_t qubitId1, size_t qubitId2) const =0
Check if any of the two specified qubits used for entanglement between hosts are busy.
virtual bool OptimizationSimulatorExists(Simulators::SimulatorType type, Simulators::SimulationType kind) const =0
Checks if a simulator exists in the optimization set.
virtual void AddOptimizationSimulator(Simulators::SimulatorType type, Simulators::SimulationType kind)=0
Adds a simulator to the simulators optimization set.
std::shared_ptr< INetwork< Time > > getptr()
Get a shared pointer to this object.
virtual bool IsEntanglingGate(const std::shared_ptr< Circuits::IOperation< Time > > &op) const =0
Checks if a gate is an entangling gate.
virtual void Configure(const char *key, const char *value)=0
Configures the network.
virtual const std::shared_ptr< IHost< Time > > GetHost(size_t hostId) const =0
Get the host with the specified id.
virtual bool OperatesWithNetworkEntangledQubit(const std::shared_ptr< Circuits::IOperation< Time > > &op) const =0
Check if the circuit operation operates on the entanglement qubits between hosts.
virtual void CreateSimulator(Simulators::SimulatorType simType=Simulators::SimulatorType::kQCSim, Simulators::SimulationType simExecType=Simulators::SimulationType::kMatrixProductState, size_t nrQubits=0)=0
Create the simulator for the network.
virtual size_t GetNumQubits() const =0
Get the number of qubits in the network.
virtual size_t GetNumQubitsForHost(size_t hostId) const =0
Get the number of qubits in the network for the specified host.
std::unordered_set< SimulatorPair, boost::hash< SimulatorPair > > SimulatorsSet
virtual std::shared_ptr< INetwork< Time > > Clone() const =0
Clone the network.
virtual std::shared_ptr< Circuits::Circuit< Time > > GetDistributedCircuit() const =0
Get the distributed circuit.
virtual size_t GetHostIdForClassicalControl(const std::shared_ptr< Circuits::IOperation< Time > > &op) const =0
Get the host id where the classical control bit resides for a conditioned gate.
virtual bool AreQubitAndClassicalBitOnSameHost(size_t qubitId, size_t bitId) const =0
Check if the specified qubit and classical bit are on the same host.
virtual bool IsEntanglementQubitBusy(size_t qubitId) const =0
Check if the specified qubit used for entanglement between hosts is busy.
virtual const SimulatorsSet & GetSimulatorsSet() const =0
Get the optimizations simulators set.
virtual void MarkEntangledQubitFree(size_t qubitId)=0
Mark the specified qubit used for entanglement between hosts as free.
typename Circuits::Circuit< Time >::ExecuteResults ExecuteResults
virtual void CreateScheduler(SchedulerType schType=SchedulerType::kNoEntanglementQubitsParallel)=0
Create the scheduler for the network.
virtual size_t GetNumClassicalBits() const =0
Get the number of classical bits in the network.
virtual size_t GetNumNetworkEntangledQubits() const =0
Get the number of qubits used for entanglement between hosts.
virtual Simulators::SimulatorType GetLastSimulatorType() const =0
Get the last used simulator type.
virtual size_t GetHostIdForEntangledQubit(size_t qubitId) const =0
Get the host id for the specified qubit used for entanglement between hosts.
virtual size_t GetHostIdForQubit(size_t qubitId) const =0
Get the host id for the specified qubit.
virtual bool GetOptimizeSimulator() const =0
Returns the 'optimize' flag.
virtual void ExecuteOnHost(const std::shared_ptr< Circuits::Circuit< Time > > &circuit, size_t hostId)=0
Execute the circuit on the specified host.
virtual void MarkEntangledQubitsBusy(size_t qubitId1, size_t qubitId2)=0
Mark the pair of the specified qubits used for entanglement between hosts as busy.
virtual std::vector< std::vector< std::string > > GetSubroutinesTextCode() const
Get the text code that is executed on the hosts.
virtual bool AreClassicalBitsOnSameHost(size_t bitId1, size_t bitId2) const =0
Check if the specified classical bits are on the same host.
virtual void SetOptimizeSimulator(bool optimize=true)=0
Allows using an optimized simulator.
std::pair< Simulators::SimulatorType, Simulators::SimulationType > SimulatorPair
virtual std::vector< size_t > GetEntangledQubitMeasurementBitIds(size_t hostId) const =0
Get the classical bit ids used for measurement of entanglement qubits between the hosts for the speci...
virtual void RemoveAllOptimizationSimulatorsAndAdd(Simulators::SimulatorType type, Simulators::SimulationType kind)=0
Removes all simulators from the simulators optimization set and adds the one specified.
virtual std::vector< size_t > GetNetworkEntangledQubitsIds(size_t hostId) const =0
Get the qubit ids used for entanglement between hosts for the specified host.
virtual NetworkType GetType() const =0
Get the type of the network.
virtual const std::shared_ptr< IController< Time > > GetController() const =0
Get the controller for the network.
virtual size_t GetHostIdForClassicalBit(size_t classicalBitId) const =0
Get the host id for the specified classical bit.
NetworkType
The type of the network.
@ kSimpleDisconnectedNetwork
Simple network, no communication among hosts, sequential simulation.
@ kSimpleNetwork
Simple fully connected network, sequential simulation.
@ kNetqasmNetwork
Fully connected network, hosts executing netqasm code with cooperative multitasking.
@ kNetqasmDESNetwork
Fully connected network, hosts executing netqasm code with discrete events simulation.
@ kSimpleDESNetwork
Simple fully connected network, discrete events simulation.
SchedulerType
The type of the network scheduler for scheduling execution of multiple circuits.
@ kNoEntanglementQubitsParallel
SimulationType
The type of simulation.
@ kMatrixProductState
matrix product state simulation type
SimulatorType
The type of simulator.
@ kQCSim
qcsim simulator type
A way to pack together a circuit and the number of shots for its execution.
std::shared_ptr< Circuits::Circuit< Time > > circuit