@@ -64,8 +64,13 @@ impl TryFrom<InstructionSetArchitecture> for Compiler {
6464 let qubits = qubits
6565 . into_iter ( )
6666 . map ( |( k, v) | ( k. to_string ( ) , v) )
67+ . filter ( |( _, q) | q. has_valid_operations ( ) )
68+ . collect ( ) ;
69+ let edges = edges
70+ . into_iter ( )
71+ . map ( |( k, v) | ( k. to_string ( ) , v) )
72+ . filter ( |( _, e) | e. has_valid_operations ( ) )
6773 . collect ( ) ;
68- let edges = edges. into_iter ( ) . map ( |( k, v) | ( k. to_string ( ) , v) ) . collect ( ) ;
6974 Ok ( Self { qubits, edges } )
7075 }
7176}
@@ -93,7 +98,7 @@ mod describe_compiler_isa {
9398 use std:: { convert:: TryFrom , fs:: read_to_string} ;
9499
95100 use float_cmp:: { approx_eq, F64Margin } ;
96- use qcs_api_client_openapi:: models:: InstructionSetArchitecture ;
101+ use qcs_api_client_openapi:: models:: { InstructionSetArchitecture , Node } ;
97102 use serde_json:: Value ;
98103
99104 use super :: Compiler ;
@@ -186,22 +191,44 @@ mod describe_compiler_isa {
186191 fn compiler_excludes_qubits_with_no_operations ( ) {
187192 let input = read_to_string ( "tests/qcs-isa-with-dead-qubits.json" )
188193 . expect ( "Could not read ISA with dead qubits" ) ;
189- let expected_json = read_to_string ( "tests/compiler-isa-with-dead-qubits.json" )
190- . expect ( "Could not read expected output with dead qubits" ) ;
191194 let qcs_isa: InstructionSetArchitecture =
192195 serde_json:: from_str ( & input) . expect ( "Could not deserialize ISA with dead qubits" ) ;
193- let expected: Value = serde_json:: from_str ( & expected_json)
194- . expect ( "Could not deserialize expected output with dead qubits" ) ;
195-
196- let compiler_isa =
197- Compiler :: try_from ( qcs_isa) . expect ( "Could not convert ISA with dead qubits to CompilerIsa" ) ;
198196
199- assert ! ( !compiler_isa. qubits. contains_key( "31" ) , "Qubit 31 should not be in the CompilerIsa" ) ;
197+ assert ! (
198+ qcs_isa. architecture. nodes. contains( & Node :: new( 31 ) ) ,
199+ "Qubit 31 is in the source ISA"
200+ ) ;
201+ assert ! (
202+ qcs_isa. architecture. edges. iter( ) . any( |e| e. node_ids. contains( & 31 ) ) ,
203+ "edge with Qubit 31 is in the source ISA"
204+ ) ;
205+
206+ let compiler_isa = Compiler :: try_from ( qcs_isa)
207+ . expect ( "Could not convert ISA with dead qubits to CompilerIsa" ) ;
208+
209+ assert ! (
210+ !compiler_isa. qubits. contains_key( "31" ) ,
211+ "Qubit 31 should not be in the CompilerIsa"
212+ ) ;
213+ assert ! (
214+ !compiler_isa. edges. contains_key( "31-32" ) ,
215+ "edge with Qubit 31 should not be in the CompilerIsa"
216+ ) ;
217+
218+ let input_without_dead = read_to_string ( "tests/qcs-isa-excluding-dead-qubits.json" )
219+ . expect ( "Could not read ISA that excludes dead qubits" ) ;
220+ let isa_without_dead: InstructionSetArchitecture =
221+ serde_json:: from_str ( & input_without_dead)
222+ . expect ( "Could not read ISA that excludes dead qubits" ) ;
223+ let compiler_isa_excluding_dead = Compiler :: try_from ( isa_without_dead)
224+ . expect ( "Could not convert ISA with manually excluded dead qubits to CompilerIsa" ) ;
200225
201- let serialized = serde_json:: to_value ( compiler_isa)
202- . expect ( "Unable to serialize CompilerIsa with dead qubits" ) ;
226+ let serialized =
227+ serde_json:: to_value ( compiler_isa) . expect ( "Unable to serialize CompilerIsa" ) ;
228+ let serialized_without_dead = serde_json:: to_value ( compiler_isa_excluding_dead)
229+ . expect ( "Unable to serialize CompilerIsa" ) ;
203230
204- let result = json_is_equivalent ( & serialized, & expected ) ;
231+ let result = json_is_equivalent ( & serialized, & serialized_without_dead ) ;
205232 result. expect ( "JSON was not equivalent" ) ;
206233 }
207234}
0 commit comments