Coverage for src/quafel/pipelines/data_generation/pipeline.py: 50%

6 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-27 09:52 +0000

1""" 

2This is a boilerplate pipeline 'data_science' 

3generated using Kedro 0.18.3 

4""" 

5 

6from kedro.pipeline import node, pipeline 

7from quafel.pipelines.data_generation.nodes import ( 

8 extract_partition_data, 

9 generate_random_qasm_circuit_from_partition, 

10 calculate_measures, 

11 generate_evaluation_matrix, 

12 generate_evaluation_partitions, 

13 qasm_circuit_to_qiskit, 

14) 

15 

16 

17def create_pipeline(partitions, existing_circuits, existing_measures, **kwargs) -> dict: 

18 pl_generate_evaluation_partitions = pipeline( 

19 [ 

20 node( 

21 func=generate_evaluation_matrix, 

22 inputs={ 

23 "min_qubits": "params:data_generation.min_qubits", 

24 "max_qubits": "params:data_generation.max_qubits", 

25 "qubits_increment": "params:data_generation.qubits_increment", 

26 "qubits_type": "params:data_generation.qubits_type", 

27 "min_depth": "params:data_generation.min_depth", 

28 "max_depth": "params:data_generation.max_depth", 

29 "depth_increment": "params:data_generation.depth_increment", 

30 "depth_type": "params:data_generation.depth_type", 

31 "min_shots": "params:data_generation.min_shots", 

32 "max_shots": "params:data_generation.max_shots", 

33 "max_shots": "params:data_generation.max_shots", 

34 "shots_increment": "params:data_generation.shots_increment", 

35 "shots_type": "params:data_generation.shots_type", 

36 "frameworks": "params:data_generation.frameworks", 

37 }, 

38 outputs={ 

39 "evaluation_matrix": "evaluation_matrix", 

40 }, 

41 ), 

42 node( 

43 func=generate_evaluation_partitions, 

44 inputs={ 

45 "evaluation_matrix": "evaluation_matrix", 

46 "skip_combinations": "params:data_generation.skip_combinations", 

47 }, 

48 outputs={ 

49 "evaluation_partitions": "evaluation_partitions", 

50 }, 

51 ), 

52 ], 

53 outputs={"evaluation_partitions": "evaluation_partitions"}, 

54 ) 

55 

56 pl_generate_qasm_circuits = pipeline( 

57 [ 

58 *[ 

59 node( 

60 func=generate_random_qasm_circuit_from_partition, 

61 inputs={ 

62 "partition": f"evaluation_partition_{i}", 

63 "seed": "params:data_generation.seed", 

64 }, 

65 outputs={ 

66 "qasm_circuit": f"qasm_circuit_{i}", 

67 "n_shots": f"n_shots_{i}", 

68 "framework": f"framework_{i}", 

69 "qiskit_circuit": f"qiskit_circuit_{i}", 

70 }, 

71 tags=["dynamic"], 

72 name=f"generate_random_qasm_circuit_from_partition_{i}", 

73 ) 

74 for i in partitions 

75 if i not in existing_circuits 

76 ], 

77 *[ 

78 node( 

79 func=extract_partition_data, 

80 inputs={ 

81 "partition": f"evaluation_partition_{i}", 

82 }, 

83 outputs={ 

84 "qubits": f"qubits_{i}", 

85 "depth": f"depth_{i}", 

86 "n_shots": f"n_shots_{i}", 

87 "framework": f"framework_{i}", 

88 }, 

89 tags=["dynamic"], 

90 name=f"extract_partition_data_{i}", 

91 ) 

92 for i in partitions 

93 if i in existing_circuits 

94 ], 

95 *[ 

96 node( 

97 func=qasm_circuit_to_qiskit, 

98 inputs={ 

99 "qasm_circuit": f"qasm_circuit_{i}", 

100 }, 

101 outputs={ 

102 "qiskit_circuit": f"qiskit_circuit_{i}", 

103 }, 

104 tags=["dynamic"], 

105 name=f"extract_circuit_{i}", 

106 ) 

107 for i in partitions 

108 if i in existing_circuits 

109 ], 

110 *[ 

111 node( 

112 func=calculate_measures, 

113 inputs={ 

114 "circuit": f"qiskit_circuit_{i}", 

115 "samples_per_parameter": "params:data_generation.samples_per_parameter", # noqa 

116 "haar_samples_per_qubit": "params:data_generation.haar_samples_per_qubit", # noqa 

117 "seed": "params:data_generation.seed", 

118 }, 

119 outputs={ 

120 "measure": f"measure_{i}", 

121 }, 

122 tags=["dynamic"], 

123 name=f"calculate_measures_{i}", 

124 ) 

125 for i in partitions 

126 if i not in existing_measures 

127 ], 

128 ], 

129 inputs={ 

130 # note that this dataset is dynamically created in the hooks, 

131 # so it is not directly available in the catalog 

132 **{ 

133 f"evaluation_partition_{i}": f"evaluation_partition_{i}" 

134 for i in partitions 

135 }, 

136 }, 

137 outputs={ 

138 **{f"n_shots_{i}": f"n_shots_{i}" for i in partitions}, 

139 **{f"framework_{i}": f"framework_{i}" for i in partitions}, 

140 **{ 

141 f"qasm_circuit_{i}": f"qasm_circuit_{i}" 

142 for i in partitions 

143 if i not in existing_circuits 

144 }, 

145 **{ 

146 f"measure_{i}": f"measure_{i}" 

147 for i in partitions 

148 if i not in existing_measures 

149 }, 

150 }, 

151 ) 

152 

153 return { 

154 "pl_generate_evaluation_partitions": pl_generate_evaluation_partitions, 

155 "pl_generate_qasm_circuits": pl_generate_qasm_circuits, 

156 }