77from typing import TYPE_CHECKING , Any
88
99if TYPE_CHECKING :
10+ from qiskit import QuantumCircuit
1011 from quimb .tensor import Tensor , TensorNetwork
1112
12- from qiskit import QuantumCircuit
13+ from mqt .core import QuantumComputation
14+
1315from qiskit .providers import Options
1416from qiskit .result .models import ExperimentResult , ExperimentResultData
1517from qiskit .transpiler import Target
1618
19+ from mqt .core .io import load
20+
1721from .header import DDSIMHeader
1822from .pyddsim import PathCircuitSimulator , PathSimulatorConfiguration , PathSimulatorMode
1923from .qasmsimulator import QasmSimulatorBackend
@@ -38,18 +42,14 @@ def read_tensor_network_file(filename: str) -> list[Tensor]:
3842 return tensors
3943
4044
41- def create_tensor_network (qc : QuantumCircuit ) -> TensorNetwork :
45+ def create_tensor_network (qc : QuantumComputation ) -> TensorNetwork :
4246 import quimb .tensor as qtn
4347 import sparse
4448
4549 from mqt .ddsim import dump_tensor_network
4650
47- if isinstance (qc , QuantumCircuit ):
48- filename = qc .name + "_" + str (qc .num_qubits ) + ".tensor"
49- nqubits = qc .num_qubits
50- else :
51- filename = "tensor.tensor"
52- nqubits = qc .header .n_qubits
51+ filename = qc .name + "_" + str (qc .num_qubits ) + ".tensor"
52+ nqubits = qc .num_qubits
5353
5454 dump_tensor_network (qc , filename )
5555 tensors = read_tensor_network_file (filename )
@@ -78,7 +78,7 @@ def create_tensor_network(qc: QuantumCircuit) -> TensorNetwork:
7878
7979
8080def get_simulation_path (
81- qc : QuantumCircuit ,
81+ qc : QuantumComputation ,
8282 max_time : int = 60 ,
8383 max_repeats : int = 1024 ,
8484 parallel_runs : int = 1 ,
@@ -101,7 +101,7 @@ def get_simulation_path(
101101 path = linear_to_ssa (info .path )
102102
103103 if dump_path :
104- filename = qc .name + "_" + str (qc .num_qubits ) + ".path" if isinstance ( qc , QuantumCircuit ) else "simulation.path"
104+ filename = qc .name + "_" + str (qc .num_qubits ) + ".path"
105105 with pathlib .Path (filename ).open ("w" ) as file :
106106 file .write (str (path ))
107107
@@ -181,7 +181,8 @@ def _run_experiment(self, qc: QuantumCircuit, **options: Any) -> ExperimentResul
181181 if seed is not None :
182182 pathsim_configuration .seed = seed
183183
184- sim = PathCircuitSimulator (qc , config = pathsim_configuration )
184+ circuit = load (qc )
185+ sim = PathCircuitSimulator (circuit , config = pathsim_configuration )
185186
186187 # determine the contraction path using cotengra in case this is requested
187188 if pathsim_configuration .mode == PathSimulatorMode .cotengra :
@@ -190,7 +191,11 @@ def _run_experiment(self, qc: QuantumCircuit, **options: Any) -> ExperimentResul
190191 dump_path = options .get ("cotengra_dump_path" , False )
191192 plot_ring = options .get ("cotengra_plot_ring" , False )
192193 path = get_simulation_path (
193- qc , max_time = max_time , max_repeats = max_repeats , dump_path = dump_path , plot_ring = plot_ring
194+ circuit ,
195+ max_time = max_time ,
196+ max_repeats = max_repeats ,
197+ dump_path = dump_path ,
198+ plot_ring = plot_ring ,
194199 )
195200 sim .set_simulation_path (path , False )
196201
0 commit comments