Testing QHack problem template using PowerShell

My code is spitting out value error thought the typecasting has been done and still I am getting the error.
I debugged it and it’s pointing out to “import pennylane as qml”
I am pretty sure that my code is correct.

Hi @yusharth,

Would you be able to provide a minimal working version of the code that is producing this error? (please don’t show explicit solutions to the QHack challenge problems though). Also, if you could show the full error message, that would be useful for debugging.

These are the errors.

(base) PS C:\Users\Yusharth Singh\Desktop\QC Notebooks\Qhack-main\QML_Challenges\simple_circuits_20_template> python simple_circuits_20_template.py < 1.in
At line:1 char:39
+ python simple_circuits_20_template.py < 1.in
+                                       ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupported

(base) PS C:\Users\Yusharth Singh\Desktop\QC Notebooks\Qhack-main\QML_Challenges\simple_circuits_20_template> python simple_circuits_20_template.py
Traceback (most recent call last):
  File "simple_circuits_20_template.py", line 40, in <module>
    angle = float(angle_str)
ValueError: could not convert string to float: ''

I didn’t change anything out of the #QHack# segment. For assurance, I downloaded the code from GitHub again and pasted mine.

You should run python simple_circuits_20_template.py < 1.in in your console
You have to pipe an input, like from the files 1.in or 2.in, into the function
And the output should then be similar to 1.ans or 2.ans

Hi @yusharth,

I edited out your code because it looked like it contained you solution to one of the QHack challenge questions, which I asked that you not share.

Anyway, the issue doesn’t seem to be with your code, but, as @BillyLjm mentioned, your method of feeding in the sample data.

I’m not a windows coder, but it looks like you are using PowerShell? It seems powershell does not support this < method for passing input data. Could you try running the same command in a vanilla cmd terminal instead?
Alternatively, you could check here for the equivalent Powershell method

Anaconda Prompt:

(base) PS C:\Users\Yusharth Singh\Desktop\QC Notebooks\Qhack-main\QML_Challenges\simple_circuits_20_template> python simple_circuits_20_template.py < 1.in.txt
At line:1 char:39
+ python simple_circuits_20_template.py < 1.in.txt
+                                       ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupported

(base) PS C:\Users\Yusharth Singh\Desktop\QC Notebooks\Qhack-main\QML_Challenges\simple_circuits_20_template>

(base) PS C:\Users\Yusharth Singh\Desktop\QC Notebooks\Qhack-main\QML_Challenges\simple_circuits_20_template> Get-Content '1.in.txt' | ./program simple_circuits_20_template.py
./program : The term './program' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:26
+ Get-Content '1.in.txt' | ./program simple_circuits_20_template.py
+                          ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./program:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

It does seem to be sorted out. Can u send me link of vanilla cmd terminal please.

Hi @yusharth!

The link @nathan provided has some more details on how to redirect file input in Windows. In particular, this command looks like it should work in the anaconda shell:

Get-Content 1.in | python simple_circuits_20_template.py

Thanks, it’s working now

1 Like