@@ -293,6 +293,42 @@ class Interpreter:
293
293
"""
294
294
...
295
295
296
+ def import_qasm (
297
+ self ,
298
+ source : str ,
299
+ output_fn : Callable [[Output ], None ],
300
+ read_file : Callable [[str ], Tuple [str , str ]],
301
+ list_directory : Callable [[str ], List [Dict [str , str ]]],
302
+ resolve_path : Callable [[str , str ], str ],
303
+ fetch_github : Callable [[str , str , str , str ], str ],
304
+ ** kwargs
305
+ ) -> Any :
306
+ """
307
+ Imports OpenQASM source code into the active Q# interpreter.
308
+
309
+ Args:
310
+ source (str): An OpenQASM program or fragment.
311
+ output_fn: The function to handle the output of the execution.
312
+ read_file: A callable that reads a file and returns its content and path.
313
+ list_directory: A callable that lists the contents of a directory.
314
+ resolve_path: A callable that resolves a file path given a base path and a relative path.
315
+ fetch_github: A callable that fetches a file from GitHub.
316
+ **kwargs: Additional keyword arguments to pass to the execution.
317
+ - name (str): The name of the program. This is used as the entry point for the program.
318
+ - search_path (Optional[str]): The optional search path for resolving file references.
319
+ - output_semantics (OutputSemantics, optional): The output semantics for the compilation.
320
+ - program_type (ProgramType, optional): The type of program compilation to perform.
321
+
322
+ Returns:
323
+ value: The value returned by the last statement in the source code.
324
+
325
+ Raises:
326
+ QasmError: If there is an error generating, parsing, or analyzing the OpenQASM source.
327
+ QSharpError: If there is an error compiling the program.
328
+ QSharpError: If there is an error evaluating the source code.
329
+ """
330
+ ...
331
+
296
332
class Result (Enum ):
297
333
"""
298
334
A Q# measurement result.
@@ -375,75 +411,81 @@ def physical_estimates(logical_resources: str, params: str) -> str:
375
411
"""
376
412
...
377
413
378
- def resource_estimate_qasm (
414
+ def circuit_qasm_program (
379
415
source : str ,
380
- job_params : str ,
381
416
read_file : Callable [[str ], Tuple [str , str ]],
382
417
list_directory : Callable [[str ], List [Dict [str , str ]]],
383
418
resolve_path : Callable [[str , str ], str ],
384
419
fetch_github : Callable [[str , str , str , str ], str ],
385
420
** kwargs
386
- ) -> str :
421
+ ) -> Circuit :
387
422
"""
388
- Estimates the resource requirements for executing QASM source code .
423
+ Synthesizes a circuit for an OpenQASM program .
389
424
390
425
Note:
391
426
This call while exported is not intended to be used directly by the user.
392
427
It is intended to be used by the Python wrapper which will handle the
393
428
callbacks and other Python specific details.
394
429
395
430
Args:
396
- source (str): The QASM source code to estimate the resource requirements for.
397
- job_params (str): The parameters for the job .
431
+ source (str): An OpenQASM program. Alternatively, a callable can be provided,
432
+ which must be an already imported global callable .
398
433
read_file (Callable[[str], Tuple[str, str]]): A callable that reads a file and returns its content and path.
399
434
list_directory (Callable[[str], List[Dict[str, str]]]): A callable that lists the contents of a directory.
400
435
resolve_path (Callable[[str, str], str]): A callable that resolves a file path given a base path and a relative path.
401
436
fetch_github (Callable[[str, str, str, str], str]): A callable that fetches a file from GitHub.
402
437
**kwargs: Additional keyword arguments to pass to the execution.
403
- - name (str): The name of the circuit . This is used as the entry point for the program. Defaults to 'program' .
404
- - search_path (str): The optional search path for resolving imports .
438
+ - name (str): The name of the program . This is used as the entry point for the program.
439
+ - search_path (Optional[ str] ): The optional search path for resolving file references .
405
440
Returns:
406
- str: The estimated resource requirements for executing the QASM source code.
441
+ Circuit: The synthesized circuit.
442
+
443
+ Raises:
444
+ QasmError: If there is an error generating, parsing, or analyzing the OpenQASM source.
445
+ QSharpError: If there is an error evaluating the program.
446
+ QSharpError: If there is an error synthesizing the circuit.
407
447
"""
408
448
...
409
449
410
- def run_qasm (
450
+ def compile_qasm_program_to_qir (
411
451
source : str ,
412
- output_fn : Callable [[Output ], None ],
413
452
read_file : Callable [[str ], Tuple [str , str ]],
414
453
list_directory : Callable [[str ], List [Dict [str , str ]]],
415
454
resolve_path : Callable [[str , str ], str ],
416
455
fetch_github : Callable [[str , str , str , str ], str ],
417
456
** kwargs
418
- ) -> Any :
457
+ ) -> str :
419
458
"""
420
- Executes QASM source code using the specified target profile.
459
+ Compiles the OpenQASM source code into a program that can be submitted to a
460
+ target as QIR (Quantum Intermediate Representation).
421
461
422
462
Note:
423
463
This call while exported is not intended to be used directly by the user.
424
464
It is intended to be used by the Python wrapper which will handle the
425
465
callbacks and other Python specific details.
426
466
427
467
Args:
428
- source (str): The QASM source code to execute.
429
- output_fn (Callable[[Output], None]): The function to handle the output of the execution.
430
- read_file (Callable[[str], Tuple[str, str]]): The function to read a file and return its contents.
431
- list_directory (Callable[[str], List[Dict[str, str]]]): The function to list the contents of a directory.
432
- resolve_path (Callable[[str, str], str]): The function to resolve a path given a base path and a relative path.
433
- fetch_github (Callable[[str, str, str, str], str]): The function to fetch a file from GitHub.
434
- **kwargs: Additional keyword arguments to pass to the execution.
435
- - target_profile (TargetProfile): The target profile to use for execution.
436
- - name (str): The name of the circuit. This is used as the entry point for the program. Defaults to 'program'.
437
- - search_path (str): The optional search path for resolving imports.
438
- - shots (int): The number of shots to run the program for. Defaults to 1.
439
- - seed (int): The seed to use for the random number generator.
468
+ source (str): The OpenQASM source code to estimate the resource requirements for.
469
+ read_file (Callable[[str], Tuple[str, str]]): A callable that reads a file and returns its content and path.
470
+ list_directory (Callable[[str], List[Dict[str, str]]]): A callable that lists the contents of a directory.
471
+ resolve_path (Callable[[str, str], str]): A callable that resolves a file path given a base path and a relative path.
472
+ fetch_github (Callable[[str, str, str, str], str]): A callable that fetches a file from GitHub.
473
+ **kwargs: Additional keyword arguments to pass to the compilation when source program is provided.
474
+ - name (str): The name of the circuit. This is used as the entry point for the program.
475
+ - target_profile (TargetProfile): The target profile to use for code generation.
476
+ - search_path (Optional[str]): The optional search path for resolving file references.
477
+ - output_semantics (OutputSemantics, optional): The output semantics for the compilation.
440
478
441
479
Returns:
442
- Any: The result of the execution.
480
+ str: The converted QIR code as a string.
481
+
482
+ Raises:
483
+ QasmError: If there is an error generating, parsing, or analyzing the OpenQASM source.
484
+ QSharpError: If there is an error compiling the program.
443
485
"""
444
486
...
445
487
446
- def compile_qasm_to_qir (
488
+ def compile_qasm_to_qsharp (
447
489
source : str ,
448
490
read_file : Callable [[str ], Tuple [str , str ]],
449
491
list_directory : Callable [[str ], List [Dict [str , str ]]],
@@ -452,57 +494,100 @@ def compile_qasm_to_qir(
452
494
** kwargs
453
495
) -> str :
454
496
"""
455
- Converts a Qiskit QuantumCircuit to QIR (Quantum Intermediate Representation) .
497
+ Converts a OpenQASM program to Q# .
456
498
457
499
Note:
458
500
This call while exported is not intended to be used directly by the user.
459
501
It is intended to be used by the Python wrapper which will handle the
460
502
callbacks and other Python specific details.
461
503
462
504
Args:
463
- source (str): The QASM source code to estimate the resource requirements for.
505
+ source (str): The OpenQASM source code to estimate the resource requirements for.
464
506
read_file (Callable[[str], Tuple[str, str]]): A callable that reads a file and returns its content and path.
465
507
list_directory (Callable[[str], List[Dict[str, str]]]): A callable that lists the contents of a directory.
466
508
resolve_path (Callable[[str, str], str]): A callable that resolves a file path given a base path and a relative path.
467
509
fetch_github (Callable[[str, str, str, str], str]): A callable that fetches a file from GitHub.
468
510
**kwargs: Additional keyword arguments to pass to the execution.
469
511
- name (str): The name of the circuit. This is used as the entry point for the program.
470
- - entry_expr (str, optional): The entry expression for the QIR conversion. Defaults to None.
471
- - target_profile (TargetProfile): The target profile to use for code generation.
472
512
- search_path (Optional[str]): The optional search path for resolving file references.
473
513
474
514
Returns:
475
- str: The converted QIR code as a string.
515
+ str: The converted Q# code as a string.
476
516
"""
477
517
...
478
518
479
- def compile_qasm_to_qsharp (
519
+ def resource_estimate_qasm_program (
480
520
source : str ,
521
+ job_params : str ,
481
522
read_file : Callable [[str ], Tuple [str , str ]],
482
523
list_directory : Callable [[str ], List [Dict [str , str ]]],
483
524
resolve_path : Callable [[str , str ], str ],
484
525
fetch_github : Callable [[str , str , str , str ], str ],
485
526
** kwargs
486
527
) -> str :
487
528
"""
488
- Converts a Qiskit QuantumCircuit to Q# .
529
+ Estimates the resource requirements for executing OpenQASM source code .
489
530
490
531
Note:
491
532
This call while exported is not intended to be used directly by the user.
492
533
It is intended to be used by the Python wrapper which will handle the
493
534
callbacks and other Python specific details.
494
535
495
536
Args:
496
- source (str): The QASM source code to estimate the resource requirements for.
537
+ source (str): The OpenQASM source code to estimate the resource requirements for.
538
+ job_params (str): The parameters for the job.
497
539
read_file (Callable[[str], Tuple[str, str]]): A callable that reads a file and returns its content and path.
498
540
list_directory (Callable[[str], List[Dict[str, str]]]): A callable that lists the contents of a directory.
499
541
resolve_path (Callable[[str, str], str]): A callable that resolves a file path given a base path and a relative path.
500
542
fetch_github (Callable[[str, str, str, str], str]): A callable that fetches a file from GitHub.
501
543
**kwargs: Additional keyword arguments to pass to the execution.
502
- - name (str): The name of the circuit. This is used as the entry point for the program.
503
- - search_path (Optional[str]): The optional search path for resolving file references.
544
+ - name (str): The name of the circuit. This is used as the entry point for the program. Defaults to 'program'.
545
+ - search_path (str): The optional search path for resolving imports.
546
+ Returns:
547
+ str: The estimated resource requirements for executing the OpenQASM source code.
548
+ """
549
+ ...
550
+
551
+ def run_qasm_program (
552
+ source : str ,
553
+ output_fn : Callable [[Output ], None ],
554
+ noise : Optional [Tuple [float , float , float ]],
555
+ read_file : Callable [[str ], Tuple [str , str ]],
556
+ list_directory : Callable [[str ], List [Dict [str , str ]]],
557
+ resolve_path : Callable [[str , str ], str ],
558
+ fetch_github : Callable [[str , str , str , str ], str ],
559
+ ** kwargs
560
+ ) -> Any :
561
+ """
562
+ Runs the given OpenQASM program for the given number of shots.
563
+ Each shot uses an independent instance of the simulator.
564
+
565
+ Note:
566
+ This call while exported is not intended to be used directly by the user.
567
+ It is intended to be used by the Python wrapper which will handle the
568
+ callbacks and other Python specific details.
569
+
570
+ Args:
571
+ source (str): The OpenQASM source code to execute.
572
+ output_fn (Callable[[Output], None]): The function to handle the output of the execution.
573
+ noise: The noise to use in simulation.
574
+ read_file (Callable[[str], Tuple[str, str]]): The function to read a file and return its contents.
575
+ list_directory (Callable[[str], List[Dict[str, str]]]): The function to list the contents of a directory.
576
+ resolve_path (Callable[[str, str], str]): The function to resolve a path given a base path and a relative path.
577
+ fetch_github (Callable[[str, str, str, str], str]): The function to fetch a file from GitHub.
578
+ **kwargs: Additional keyword arguments to pass to the execution.
579
+ - target_profile (TargetProfile): The target profile to use for execution.
580
+ - name (str): The name of the circuit. This is used as the entry point for the program. Defaults to 'program'.
581
+ - search_path (str): The optional search path for resolving imports.
582
+ - output_semantics (OutputSemantics, optional): The output semantics for the compilation.
583
+ - shots (int): The number of shots to run the program for. Defaults to 1.
584
+ - seed (int): The seed to use for the random number generator.
504
585
505
586
Returns:
506
- str: The converted Q# code as a string.
587
+ Any: The result of the execution.
588
+
589
+ Raises:
590
+ QasmError: If there is an error generating, parsing, or analyzing the OpenQASM source.
591
+ QSharpError: If there is an error interpreting the input.
507
592
"""
508
593
...
0 commit comments