@@ -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}
@@ -186,22 +191,33 @@ 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" ) ;
198-
199- assert ! ( !compiler_isa. qubits. contains_key( "31" ) , "Qubit 31 should not be in the CompilerIsa" ) ;
196+ let compiler_isa = Compiler :: try_from ( qcs_isa)
197+ . expect ( "Could not convert ISA with dead qubits to CompilerIsa" ) ;
198+
199+ assert ! (
200+ !compiler_isa. qubits. contains_key( "31" ) ,
201+ "Qubit 31 should not be in the CompilerIsa"
202+ ) ;
203+ assert ! (
204+ !compiler_isa. edges. contains_key( "31-32" ) ,
205+ "edge with Qubit 31 should not be in the CompilerIsa"
206+ ) ;
207+
208+ let input_without_dead = read_to_string ( "tests/qcs-isa-excluding-dead-qubits.json" )
209+ . expect ( "Could not read ISA that excludes dead qubits" ) ;
210+ let isa_without_dead: InstructionSetArchitecture = serde_json:: from_str ( & input_without_dead)
211+ . expect ( "Could not read ISA that excludes dead qubits" ) ;
212+ let compiler_isa_excluding_dead = Compiler :: try_from ( isa_without_dead)
213+ . expect ( "Could not convert ISA with manually excluded dead qubits to CompilerIsa" ) ;
200214
201215 let serialized = serde_json:: to_value ( compiler_isa)
202- . expect ( "Unable to serialize CompilerIsa with dead qubits" ) ;
216+ . expect ( "Unable to serialize CompilerIsa" ) ;
217+ let serialized_without_dead = serde_json:: to_value ( compiler_isa_excluding_dead)
218+ . expect ( "Unable to serialize CompilerIsa" ) ;
203219
204- let result = json_is_equivalent ( & serialized, & expected ) ;
220+ let result = json_is_equivalent ( & serialized, & serialized_without_dead ) ;
205221 result. expect ( "JSON was not equivalent" ) ;
206222 }
207223}
0 commit comments